@modern-js/module-tools-docs 2.30.0 → 2.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/docs/en/api/config/build-config.mdx +49 -49
  3. package/docs/en/api/config/build-preset.mdx +15 -33
  4. package/docs/en/api/config/design-system.md +42 -34
  5. package/docs/en/api/config/plugins.md +3 -3
  6. package/docs/en/api/config/testing.md +2 -2
  7. package/docs/en/api/plugin-api/plugin-hooks.md +24 -24
  8. package/docs/en/components/register-esbuild-plugin.mdx +2 -2
  9. package/docs/en/guide/advance/asset.mdx +8 -27
  10. package/docs/en/guide/advance/build-umd.mdx +18 -66
  11. package/docs/en/guide/advance/external-dependency.mdx +7 -27
  12. package/docs/en/guide/advance/in-depth-about-build.md +4 -4
  13. package/docs/en/guide/advance/in-depth-about-dev-command.md +2 -2
  14. package/docs/en/guide/advance/theme-config.mdx +4 -8
  15. package/docs/en/guide/basic/before-getting-started.md +1 -1
  16. package/docs/en/guide/basic/publish-your-project.md +8 -7
  17. package/docs/en/guide/basic/test-your-project.mdx +10 -47
  18. package/docs/en/guide/basic/use-micro-generator.md +4 -4
  19. package/docs/en/guide/basic/using-storybook.mdx +12 -44
  20. package/docs/en/guide/best-practices/components.mdx +44 -402
  21. package/docs/en/guide/faq/build.mdx +16 -0
  22. package/docs/en/guide/intro/getting-started.md +2 -2
  23. package/docs/en/plugins/guide/getting-started.mdx +8 -24
  24. package/docs/en/plugins/guide/plugin-object.mdx +2 -8
  25. package/docs/en/plugins/official-list/plugin-import.mdx +9 -52
  26. package/docs/en/plugins/official-list/plugin-node-polyfill.md +2 -2
  27. package/docs/zh/api/config/build-config.mdx +52 -52
  28. package/docs/zh/api/config/build-preset.mdx +12 -30
  29. package/docs/zh/api/config/design-system.md +6 -6
  30. package/docs/zh/api/config/plugins.md +3 -3
  31. package/docs/zh/api/config/testing.md +2 -2
  32. package/docs/zh/components/register-esbuild-plugin.mdx +2 -2
  33. package/docs/zh/guide/advance/asset.mdx +9 -30
  34. package/docs/zh/guide/advance/build-umd.mdx +19 -67
  35. package/docs/zh/guide/advance/external-dependency.mdx +8 -28
  36. package/docs/zh/guide/advance/in-depth-about-build.md +4 -4
  37. package/docs/zh/guide/advance/in-depth-about-dev-command.md +2 -2
  38. package/docs/zh/guide/advance/theme-config.mdx +4 -8
  39. package/docs/zh/guide/basic/publish-your-project.md +2 -2
  40. package/docs/zh/guide/basic/test-your-project.mdx +11 -49
  41. package/docs/zh/guide/basic/use-micro-generator.md +4 -4
  42. package/docs/zh/guide/basic/using-storybook.mdx +13 -45
  43. package/docs/zh/guide/best-practices/components.mdx +50 -410
  44. package/docs/zh/guide/faq/build.mdx +16 -0
  45. package/docs/zh/guide/intro/getting-started.md +1 -1
  46. package/docs/zh/plugins/guide/getting-started.mdx +8 -24
  47. package/docs/zh/plugins/guide/plugin-object.mdx +2 -8
  48. package/docs/zh/plugins/official-list/plugin-import.mdx +10 -55
  49. package/docs/zh/plugins/official-list/plugin-node-polyfill.md +2 -2
  50. package/modern.config.ts +1 -12
  51. package/package.json +3 -5
  52. package/theme/index.ts +0 -2
  53. package/theme/index.css +0 -9
@@ -8,9 +8,9 @@ Module engineering solution not only provides a rich set of features, but also s
8
8
 
9
9
  We can quickly see how to write a Module Tools plugin by using the following example.
10
10
 
11
- <CH.Spotlight>
11
+ 1. First we create `. /plugins/example.ts` file under the initialized project.
12
12
 
13
- ```md . /project
13
+ ```md title=". /project"
14
14
  . /project .
15
15
  ├── plugins
16
16
  │ └── example.ts
@@ -18,17 +18,7 @@ We can quickly see how to write a Module Tools plugin by using the following exa
18
18
  └── modern.config.ts
19
19
  ```
20
20
 
21
- ---
22
-
23
- First we create `. /plugins/example.ts` file under the initialized project.
24
-
25
- ```md . /project
26
-
27
- ```
28
-
29
- ---
30
-
31
- Next add the code for the plugin to the `example.ts` file.
21
+ 2. Next add the code for the plugin to the `example.ts` file.
32
22
 
33
23
  ```ts
34
24
  import type { CliPlugin, ModuleTools } from '@modern-js/module-tools';
@@ -42,36 +32,30 @@ export const ExamplePlugin = (): CliPlugin<ModuleTools> => {
42
32
  // use hooks
43
33
  afterBuild() {
44
34
  console.info('build over');
45
- }
35
+ },
46
36
  };
47
37
  },
48
38
  };
49
39
  };
50
40
  ```
51
41
 
52
- ---
53
-
54
- Then we register the plugin we just wrote via the [`plugins`](/en/api/config/plugins) API.
42
+ 3. Then we register the plugin we just wrote via the [`plugins`](/en/api/config/plugins) API.
55
43
 
56
- ```ts . /modern.config.ts
44
+ ```ts title=". /modern.config.ts"
57
45
  import { examplePlugin } from '. /plugins/example';
58
46
  export default defineConfig({
59
47
  plugins: [examplePlugin()],
60
48
  });
61
49
  ```
62
50
 
63
- ---
64
-
65
- Finally, run `modern build` and you will see.
51
+ 4. Finally, run `modern build` and you will see:
66
52
 
67
- ```bash terminal
53
+ ```bash title="terminal"
68
54
  This is example plugin
69
55
  Build succeed: 510.684ms
70
56
  build over
71
57
  ```
72
58
 
73
- </CH.Spotlight>
74
-
75
59
  With the above example, we learned the following things.
76
60
 
77
61
  - The recommended plugin directory structure
@@ -11,9 +11,7 @@ The Module Tools plugin is an object, and the object contains the following prop
11
11
 
12
12
  For example, in the following plugin code example, the `beforeBuild` function is triggered before the project starts the build task and the `build start` log is printed.
13
13
 
14
- <CH.Code>
15
-
16
- ```ts . /plugins/demo.tsx
14
+ ```ts title=". /plugins/demo.tsx"
17
15
  import type { CliPlugin, ModuleTools } from '@modern-js/module-tools';
18
16
 
19
17
  const myPlugin: CliPlugin<ModuleTools> = {
@@ -30,17 +28,13 @@ const myPlugin: CliPlugin<ModuleTools> = {
30
28
  };
31
29
  ```
32
30
 
33
- ---
34
-
35
- ```ts . /modern.config.ts
31
+ ```ts title="modern.config.ts"
36
32
  import { myPlugin } from '. /plugins/demo';
37
33
  export default {
38
34
  plugins: [myPlugin()],
39
35
  };
40
36
  ```
41
37
 
42
- </CH.Code>
43
-
44
38
  ## Plugin type definitions
45
39
 
46
40
  When using TypeScript, you can introduce the built-in `CliPlugin` and `ModuleTools` types to provide the correct type derivation for plugins: ``
@@ -92,79 +92,36 @@ Some configurations can accept functions, such as `customName`, `customStyleName
92
92
 
93
93
  Simple function logic can be replaced by template language. Therefore, for configurations such as `customName`, `customStyleName`, etc., instead of passing functions, you can also pass a string as a template to replace the function, improving performance.
94
94
 
95
- <CH.Spotlight>
95
+ We will use the following code as example:
96
96
 
97
97
  ```ts
98
98
  import { MyButton as Btn } from 'foo';
99
99
  ```
100
100
 
101
- ---
102
-
103
- We will use this piece of code for illustration.
104
-
105
- ```ts
106
- import { MyButton as Btn } from 'foo';
107
- ```
108
-
109
- ---
110
-
111
101
  Add the following configuration on the right-hand side:
112
102
 
113
103
  ```ts
114
- import { modulePluginImport } from '@modern-js/plugin-module-import';
115
- import { moduleTools, defineConfig } from '@modern-js/module-tools';
116
-
117
- export default defineConfig({
118
- plugins: [
119
- moduleTools(),
120
- modulePluginImport({
121
- pluginImport: [
122
- {
123
- libraryName: 'foo',
124
- customName: 'foo/es/{{ member }}',
125
- },
126
- ],
127
- }),
104
+ modulePluginImport({
105
+ pluginImport: [
106
+ {
107
+ libraryName: 'foo',
108
+ customName: 'foo/es/{{ member }}',
109
+ },
128
110
  ],
129
111
  });
130
112
  ```
131
113
 
132
- ---
133
-
134
- The `{{ member }}` in it will be replaced with the corresponding import member.
135
-
136
- ```ts focus=8:8
137
- import { modulePluginImport } from '@modern-js/plugin-module-import';
138
-
139
- export default defineConfig({
140
- plugins: [
141
- modulePluginImport({
142
- pluginImport: [
143
- {
144
- libraryName: 'foo',
145
- customName: 'foo/es/{{ member }}',
146
- },
147
- ],
148
- }),
149
- ],
150
- });
151
- ```
152
-
153
- ---
154
-
155
- After transformation:
114
+ The `{{ member }}` in it will be replaced with the corresponding import member. After transformation:
156
115
 
157
116
  ```ts
158
117
  import Btn from 'foo/es/MyButton';
159
118
  ```
160
119
 
161
- </CH.Spotlight>
162
-
163
120
  Template `customName: 'foo/es/{{ member }}'` is the same as `` customName: (member) => `foo/es/${member}` ``, but template value has no performance overhead of Node-API.
164
121
 
165
122
  The template used here is [handlebars](https://handlebarsjs.com). There are some useful builtin tools, Take the above import statement as an example:
166
123
 
167
- ```ts focus=8:8
124
+ ```ts
168
125
  import { modulePluginImport } from '@modern-js/plugin-module-import';
169
126
  import { moduleTools, defineConfig } from '@modern-js/module-tools';
170
127
 
@@ -52,7 +52,7 @@ type NodePolyfillOptions = {
52
52
 
53
53
  Exclude the Node Polyfill to be injected.
54
54
 
55
- ``` ts focus=7:9
55
+ ```ts
56
56
  import { moduleTools, defineConfig } from '@modern-js/module-tools';
57
57
  import { modulePluginNodePolyfill } from '@modern-js/plugin-module-node-polyfill';
58
58
 
@@ -70,7 +70,7 @@ export default defineConfig({
70
70
 
71
71
  Override the built-in Node Polyfill.
72
72
 
73
- ``` ts focus=7:9
73
+ ```ts
74
74
  import { moduleTools, defineConfig } from '@modern-js/module-tools';
75
75
  import { modulePluginNodePolyfill } from '@modern-js/plugin-module-node-polyfill';
76
76
 
@@ -26,7 +26,7 @@ sidebar_position: 1
26
26
  对于 TypeScript 项目,只需要在 `tsconfig.json` 中配置 [compilerOptions.paths](https://www.typescriptlang.org/tsconfig#paths), Module Tools 会自动识别 `tsconfig.json` 里的别名,因此不需要额外配置 `alias` 字段。
27
27
  :::
28
28
 
29
- ```js modern.config.ts
29
+ ```js title="modern.config.ts"
30
30
  export default defineConfig({
31
31
  buildConfig: {
32
32
  alias: {
@@ -40,7 +40,7 @@ export default defineConfig({
40
40
 
41
41
  `alias` 的值定义为函数时,可以接受预设的 alias 对象,并对其进行修改。
42
42
 
43
- ```js modern.config.ts
43
+ ```js title="modern.config.ts"
44
44
  export default defineConfig({
45
45
  buildConfig: {
46
46
  alias: alias => {
@@ -52,7 +52,7 @@ export default defineConfig({
52
52
 
53
53
  也可以在函数中返回一个新对象作为最终结果,新对象会覆盖预设的 alias 对象。
54
54
 
55
- ```js modern.config.ts
55
+ ```js title="modern.config.ts"
56
56
  export default defineConfig({
57
57
  buildConfig: {
58
58
  alias: alias => {
@@ -88,7 +88,7 @@ Module Tools 在进行打包时,默认会内联体积小于 10KB 的图片、
88
88
 
89
89
  例如,将 `limit` 设置为 `0` 来避免资源内联:
90
90
 
91
- ```js modern.config.ts
91
+ ```js title="modern.config.ts"
92
92
  export default defineConfig({
93
93
  buildConfig: {
94
94
  asset: {
@@ -105,7 +105,7 @@ export default defineConfig({
105
105
  - 类型: `string`
106
106
  - 默认值: `undefined`
107
107
 
108
- ```js modern.config.ts
108
+ ```js title="modern.config.ts"
109
109
  export default defineConfig({
110
110
  buildConfig: {
111
111
  asset: {
@@ -126,7 +126,7 @@ export default defineConfig({
126
126
 
127
127
  开启 svgr 功能后,可以使用默认导出的方式将 SVG 当做组件使用。
128
128
 
129
- ```js index.ts
129
+ ```js title="index.ts"
130
130
  // true
131
131
  import Logo from './logo.svg';
132
132
 
@@ -137,7 +137,7 @@ export default () => <Logo />;
137
137
 
138
138
  目前不支持下面的用法:
139
139
 
140
- ```js index.ts
140
+ ```js title="index.ts"
141
141
  import { ReactComponent } from './logo.svg';
142
142
  ```
143
143
 
@@ -145,7 +145,7 @@ import { ReactComponent } from './logo.svg';
145
145
 
146
146
  当开启功能后,可以通过在 `modern-app-env.d.ts` 文件中增加类型定义,修改使用 SVG 的类型:
147
147
 
148
- ```ts modern-app-env.d.ts focus=1:3
148
+ ```ts title="modern-app-env.d.ts"
149
149
  declare module '*.svg' {
150
150
  const src: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
151
151
  export default src;
@@ -177,7 +177,7 @@ declare module '*.svg' {
177
177
 
178
178
  当我们希望关闭对于第三方依赖的默认处理行为时候,可以通过以下方式来实现:
179
179
 
180
- ```ts modern.config.ts
180
+ ```ts title="modern.config.ts"
181
181
  export default defineConfig({
182
182
  buildConfig: {
183
183
  autoExternal: false,
@@ -188,7 +188,7 @@ export default defineConfig({
188
188
  这样对于 `"dependencies"` 和 `"peerDependencies"` 下面的依赖都会进行打包处理。如果只想要关闭其中某个下面的依赖处理,则可以使用
189
189
  `buildConfig.autoExternal` 的对象形式:
190
190
 
191
- ```ts modern.config.ts
191
+ ```ts title="modern.config.ts"
192
192
  export default defineConfig({
193
193
  buildConfig: {
194
194
  autoExternal: {
@@ -226,7 +226,7 @@ export default defineConfig({
226
226
 
227
227
  - 类型: `object`
228
228
 
229
- ```js modern.config.ts
229
+ ```js title="modern.config.ts"
230
230
  export default defineConfig({
231
231
  buildConfig: {
232
232
  copy: {
@@ -275,7 +275,7 @@ type Options = {
275
275
 
276
276
  由于 `define` 功能是由全局文本替换实现的,所以需要保证全局变量值为字符串,更为安全的做法是将每个全局变量的值转化为字符串,使用 `JSON.stringify` 进行转换,如下所示:
277
277
 
278
- ```js modern.config.ts
278
+ ```js title="modern.config.ts"
279
279
  export default defineConfig({
280
280
  buildConfig: {
281
281
  define: {
@@ -327,7 +327,7 @@ export default defineConfig({
327
327
 
328
328
  **默认情况下,在出现类型错误的时候会导致构建失败**。将 `abortOnError` 设置为 `false` 后,即使代码中出现了类型问题,构建依然会成功:
329
329
 
330
- ```js modern.config.ts
330
+ ```js title="modern.config.ts"
331
331
  export default defineConfig({
332
332
  buildConfig: {
333
333
  dts: {
@@ -350,7 +350,7 @@ export default defineConfig({
350
350
 
351
351
  比如输出到 `outDir` 下面的 `types` 目录:
352
352
 
353
- ```js modern.config.ts
353
+ ```js title="modern.config.ts"
354
354
  export default defineConfig({
355
355
  buildConfig: {
356
356
  dts: {
@@ -367,7 +367,7 @@ export default defineConfig({
367
367
  - 类型: `boolean`
368
368
  - 默认值: `false`
369
369
 
370
- ```js modern.config.ts
370
+ ```js title="modern.config.ts"
371
371
  export default defineConfig({
372
372
  buildConfig: {
373
373
  dts: {
@@ -386,7 +386,7 @@ export default defineConfig({
386
386
  - 类型: `boolean`
387
387
  - 默认值: `true`
388
388
 
389
- ```js modern.config.ts
389
+ ```js title="modern.config.ts"
390
390
  export default defineConfig({
391
391
  buildConfig: {
392
392
  dts: {
@@ -403,7 +403,7 @@ TypeScript 配置文件的路径。
403
403
  - 类型: `string`
404
404
  - 默认值: `./tsconfig.json`
405
405
 
406
- ```js modern.config.ts
406
+ ```js title="modern.config.ts"
407
407
  export default defineConfig({
408
408
  buildConfig: {
409
409
  dts: {
@@ -422,12 +422,12 @@ export default defineConfig({
422
422
 
423
423
  例如,我们需要修改生成文件的后缀:
424
424
 
425
- ```js modern.config.ts
425
+ ```js title="modern.config.ts"
426
426
  export default defineConfig({
427
427
  buildConfig: {
428
428
  esbuildOptions: options => {
429
429
  options.outExtension = { '.js': '.mjs' };
430
- return option;
430
+ return options;
431
431
  },
432
432
  },
433
433
  });
@@ -460,7 +460,7 @@ import RegisterEsbuildPlugin from '@site-docs/components/register-esbuild-plugin
460
460
 
461
461
  开启前:
462
462
 
463
- ```js ./dist/index.js
463
+ ```js title="./dist/index.js"
464
464
  // 辅助函数
465
465
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
466
466
  // ...
@@ -481,7 +481,7 @@ export var yourCode = function () {
481
481
 
482
482
  开启后:
483
483
 
484
- ```js ./dist/index.js
484
+ ```js title="./dist/index.js"
485
485
  // 从 @swc/helpers 导入的辅助函数
486
486
  import { _ as _async_to_generator } from '@swc/helpers/_/_async_to_generator';
487
487
 
@@ -505,7 +505,7 @@ type Externals = (string | RegExp)[];
505
505
  - 构建类型:`仅支持 buildType: 'bundle'`
506
506
  - 示例:
507
507
 
508
- ```js modern.config.ts
508
+ ```js title="modern.config.ts"
509
509
  export default defineConfig({
510
510
  buildConfig: {
511
511
  // 避免打包 React
@@ -527,7 +527,7 @@ esm 代表 "ECMAScript 模块",它需要运行环境支持 import 和 export
527
527
 
528
528
  - 示例:
529
529
 
530
- ```js modern.config.ts
530
+ ```js title="modern.config.ts"
531
531
  export default defineConfig({
532
532
  buildConfig: {
533
533
  format: 'esm',
@@ -541,7 +541,7 @@ cjs 代表 "CommonJS",它需要运行环境支持 exports、require 和 module
541
541
 
542
542
  - 示例:
543
543
 
544
- ```js modern.config.ts
544
+ ```js title="modern.config.ts"
545
545
  export default defineConfig({
546
546
  buildConfig: {
547
547
  format: 'cjs',
@@ -555,7 +555,7 @@ iife 代表 "立即调用函数表达式",它将代码包裹在函数表达式
555
555
 
556
556
  - 示例:
557
557
 
558
- ```js modern.config.ts
558
+ ```js title="modern.config.ts"
559
559
  export default defineConfig({
560
560
  buildConfig: {
561
561
  format: 'iife',
@@ -569,7 +569,7 @@ umd 代表 "Universal Module Definition",用于在不同环境(浏览器、N
569
569
 
570
570
  - 示例:
571
571
 
572
- ```js modern.config.ts
572
+ ```js title="modern.config.ts"
573
573
  export default defineConfig({
574
574
  buildConfig: {
575
575
  format: 'umd',
@@ -595,7 +595,7 @@ type Input =
595
595
 
596
596
  **数组用法:**
597
597
 
598
- ```js modern.config.ts
598
+ ```js title="modern.config.ts"
599
599
  export default defineConfig({
600
600
  buildConfig: {
601
601
  input: ['src/index.ts', 'src/index2.ts'],
@@ -609,7 +609,7 @@ export default defineConfig({
609
609
 
610
610
  **对象的 Key 是产物的文件名称,Value 是源码的文件路径。**
611
611
 
612
- ```js modern.config.ts
612
+ ```js title="modern.config.ts"
613
613
  export default defineConfig({
614
614
  buildConfig: {
615
615
  format: 'esm',
@@ -629,7 +629,7 @@ export default defineConfig({
629
629
 
630
630
  如果你需要支持 React 16,则可以设置 `jsx` 为 `transform`:
631
631
 
632
- ```js modern.config.ts
632
+ ```js title="modern.config.ts"
633
633
  export default defineConfig({
634
634
  buildConfig: {
635
635
  jsx: 'transform',
@@ -655,7 +655,7 @@ export default defineConfig({
655
655
 
656
656
  开启 `metafile` 生成:
657
657
 
658
- ```js modern.config.ts
658
+ ```js title="modern.config.ts"
659
659
  export default defineConfig({
660
660
  buildConfig: {
661
661
  buildType: 'bundle',
@@ -673,7 +673,7 @@ export default defineConfig({
673
673
  - 类型: `'terser' | 'esbuild' | false | object`
674
674
  - 默认值: `false`
675
675
 
676
- ```js modern.config.ts
676
+ ```js title="modern.config.ts"
677
677
  export default defineConfig({
678
678
  buildConfig: {
679
679
  minify: {
@@ -692,7 +692,7 @@ export default defineConfig({
692
692
  - 类型: `string`
693
693
  - 默认值: `./dist`
694
694
 
695
- ```js modern.config.ts
695
+ ```js title="modern.config.ts"
696
696
  export default defineConfig({
697
697
  buildConfig: {
698
698
  outDir: './dist/esm',
@@ -707,7 +707,7 @@ export default defineConfig({
707
707
  - 类型: `'browser' | 'node'`
708
708
  - 默认值: `'node'`
709
709
 
710
- ```js modern.config.ts
710
+ ```js title="modern.config.ts"
711
711
  export default defineConfig({
712
712
  buildConfig: {
713
713
  platform: 'browser',
@@ -724,7 +724,7 @@ export default defineConfig({
724
724
 
725
725
  在某些场景下,你可能不需要这些功能,那么可以通过此配置关闭它,关闭后,其引用路径将不会发生改变。
726
726
 
727
- ```js modern.config.ts
727
+ ```js title="modern.config.ts"
728
728
  export default {
729
729
  buildConfig: {
730
730
  redirect: {
@@ -752,7 +752,7 @@ import 'other-package/dist/index.css';
752
752
 
753
753
  但是这个三方包的 package.json 里并没有将样式文件配置到 `"sideEffects"` 里。
754
754
 
755
- ```json other-package/package.json
755
+ ```json title="other-package/package.json"
756
756
  {
757
757
  "sideEffects": ["dist/index.js"]
758
758
  }
@@ -766,7 +766,7 @@ import 'other-package/dist/index.css';
766
766
 
767
767
  这时候就可以使用这个配置项,手动配置模块的`"sideEffects"`,配置支持正则和函数形式。
768
768
 
769
- ```js modern.config.ts
769
+ ```js title="modern.config.ts"
770
770
  export default defineConfig({
771
771
  buildConfig: {
772
772
  sideEffects: [/\.css$/],
@@ -830,7 +830,7 @@ less 相关配置。
830
830
  - 类型: `string`
831
831
  - 默认值: `undefined`
832
832
 
833
- ```js modern.config.ts
833
+ ```js title="modern.config.ts"
834
834
  export default defineConfig({
835
835
  buildConfig: {
836
836
  style: {
@@ -851,7 +851,7 @@ export default defineConfig({
851
851
 
852
852
  设置 `object` 类型时,可以指定 `Less` 的实现库。
853
853
 
854
- ```js modern.config.ts
854
+ ```js title="modern.config.ts"
855
855
  export default defineConfig({
856
856
  buildConfig: {
857
857
  style: {
@@ -865,7 +865,7 @@ export default defineConfig({
865
865
 
866
866
  `string` 类型时,指定 `Less` 的实现库的路径
867
867
 
868
- ```js modern.config.ts
868
+ ```js title="modern.config.ts"
869
869
  export default defineConfig({
870
870
  buildConfig: {
871
871
  style: {
@@ -895,7 +895,7 @@ Sass 相关配置。
895
895
  - 类型: `string | Function`
896
896
  - 默认值: `undefined`
897
897
 
898
- ```js modern.config.ts
898
+ ```js title="modern.config.ts"
899
899
  export default defineConfig({
900
900
  buildConfig: {
901
901
  style: {
@@ -917,7 +917,7 @@ export default defineConfig({
917
917
 
918
918
  设置为 `object` 类型时,可以指定 `Sass` 的实现库。
919
919
 
920
- ```js modern.config.ts
920
+ ```js title="modern.config.ts"
921
921
  export default defineConfig({
922
922
  buildConfig: {
923
923
  style: {
@@ -931,7 +931,7 @@ export default defineConfig({
931
931
 
932
932
  `string` 类型时,指定 `Sass` 的实现库的路径
933
933
 
934
- ```js modern.config.ts
934
+ ```js title="modern.config.ts"
935
935
  export default defineConfig({
936
936
  buildConfig: {
937
937
  style: {
@@ -978,7 +978,7 @@ const defaultConfig = {
978
978
 
979
979
  - 示例:
980
980
 
981
- ```js modern.config.ts
981
+ ```js title="modern.config.ts"
982
982
  export default defineConfig({
983
983
  buildConfig: {
984
984
  style: {
@@ -999,7 +999,7 @@ export default defineConfig({
999
999
 
1000
1000
  将 `inject` 设置为 `true` 来开启此功能:
1001
1001
 
1002
- ```js modern.config.ts
1002
+ ```js title="modern.config.ts"
1003
1003
  export default defineConfig({
1004
1004
  buildConfig: {
1005
1005
  inject: true,
@@ -1011,7 +1011,7 @@ export default defineConfig({
1011
1011
 
1012
1012
  例如,你在源码里写了 `import './index.scss'`,那么在产物中你会看到以下代码:
1013
1013
 
1014
- ```js dist/index.js
1014
+ ```js title="dist/index.js"
1015
1015
  // node_modules/style-inject/dist/style-inject.es.js
1016
1016
  function styleInject(css, ref) {
1017
1017
  // ...
@@ -1060,7 +1060,7 @@ CSS Modules 配置。
1060
1060
 
1061
1061
  一个常用的配置是 `localsConvention`,它可以改变 CSS Modules 的类名生成规则。
1062
1062
 
1063
- ```js modern.config.ts
1063
+ ```js title="modern.config.ts"
1064
1064
  export default defineConfig({
1065
1065
  buildConfig: {
1066
1066
  style: {
@@ -1094,7 +1094,7 @@ Tailwind CSS 相关配置。
1094
1094
  <details>
1095
1095
  <summary>Tailwind CSS 配置详情</summary>
1096
1096
 
1097
- ```js modern.config.ts
1097
+ ```js title="modern.config.ts"
1098
1098
  const tailwind = {
1099
1099
  content: [
1100
1100
  './config/html/**/*.html',
@@ -1144,7 +1144,7 @@ type Target =
1144
1144
 
1145
1145
  例如,将代码编译到 `es5` 语法:
1146
1146
 
1147
- ```js modern.config.ts
1147
+ ```js title="modern.config.ts"
1148
1148
  export default defineConfig({
1149
1149
  buildConfig: {
1150
1150
  target: 'es5',
@@ -1163,7 +1163,7 @@ export default defineConfig({
1163
1163
 
1164
1164
  使用示例:
1165
1165
 
1166
- ```js modern.config.ts
1166
+ ```js title="modern.config.ts"
1167
1167
  export default defineConfig({
1168
1168
  buildConfig: {
1169
1169
  transformImport: [
@@ -1188,7 +1188,7 @@ export default defineConfig({
1188
1188
  - 类型: `Record<string, string>`
1189
1189
  - 默认值: `{}`
1190
1190
 
1191
- ```ts modern.config.ts
1191
+ ```ts title="modern.config.ts"
1192
1192
  export default defineConfig({
1193
1193
  buildConfig: {
1194
1194
  umdGlobals: {
@@ -1208,7 +1208,7 @@ export default defineConfig({
1208
1208
  - 类型: `string | Function`
1209
1209
  - 默认值: `name => name`
1210
1210
 
1211
- ```js modern.config.ts
1211
+ ```js title="modern.config.ts"
1212
1212
  export default defineConfig({
1213
1213
  buildConfig: {
1214
1214
  format: 'umd',
@@ -1228,7 +1228,7 @@ export default defineConfig({
1228
1228
 
1229
1229
  同时函数形式可以接收一个参数,为当前打包文件的输出路径
1230
1230
 
1231
- ```js modern.config.ts
1231
+ ```js title="modern.config.ts"
1232
1232
  export default defineConfig({
1233
1233
  buildConfig: {
1234
1234
  format: 'umd',