@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
@@ -13,7 +13,7 @@ sidebar_position: 2
13
13
 
14
14
  字符串的形式可以让你直接使用内置的预设。
15
15
 
16
- ```js modern.config.ts
16
+ ```js title="modern.config.ts"
17
17
  import { defineConfig } from '@modern-js/module-tools';
18
18
 
19
19
  export default defineConfig({
@@ -34,7 +34,7 @@ export default defineConfig({
34
34
 
35
35
  :::
36
36
 
37
- ```json package.json
37
+ ```json title="package.json"
38
38
  {
39
39
  "main": "./dist/lib/index.js",
40
40
  "module": "./dist/es/index.js",
@@ -72,7 +72,7 @@ export const buildConfig = [
72
72
 
73
73
  在类 [NPM](https://www.npmjs.com/) 包管理器下使用,并且 Library 支持类似 [unpkg](https://unpkg.com/) 的模式。在预设 `'npm-library'` 的基础上,额外提供 `umd` 产物。
74
74
 
75
- ```json package.json
75
+ ```json title="package.json"
76
76
  {
77
77
  "main": "./dist/lib/index.js",
78
78
  "module": "./dist/es/index.js",
@@ -120,7 +120,7 @@ export const buildConfig = [
120
120
 
121
121
  对于源码中包含的样式文件,产物中提供样式的编译产物和样式的源文件。
122
122
 
123
- ```json package.json
123
+ ```json title="package.json"
124
124
  {
125
125
  "main": "./dist/lib/index.js", // bundleless type
126
126
  "module": "./dist/es/index.js", // bundleless type
@@ -158,7 +158,7 @@ export const buildConfig = [
158
158
 
159
159
  在类 [NPM](https://www.npmjs.com/) 包管理器下使用的组件(库),同时支持类 [unpkg](https://unpkg.com/) 的模式。 在预设 `'npm-component'` 的基础上,额外提供 `umd` 产物。
160
160
 
161
- ```json package.json
161
+ ```json title="package.json"
162
162
  {
163
163
  "main": "./dist/lib/index.js", // bundleless type
164
164
  "module": "./dist/es/index.js", // bundleless type
@@ -204,7 +204,7 @@ export const buildConfig = [
204
204
 
205
205
  例如希望 `'npm-library'` 预设支持 `'es2017'`,则可以按照如下方式配置:
206
206
 
207
- ```js modern.config.ts
207
+ ```js title="modern.config.ts"
208
208
  import { defineConfig } from '@modern-js/module-tools';
209
209
 
210
210
  export default defineConfig({
@@ -217,7 +217,7 @@ export default defineConfig({
217
217
  函数的配置方式,可以通过 `preset` 参数获取到预设值,然后对里面的构建配置进行修改来自定义你的构建配置。
218
218
  以下是一个函数的配置方式的例子,它配置了压缩构建产物的功能:
219
219
 
220
- ```js modern.config.ts
220
+ ```js title="modern.config.ts"
221
221
  import { defineConfig } from '@modern-js/module-tools';
222
222
 
223
223
  export default defineConfig({
@@ -248,10 +248,9 @@ export default defineConfig({
248
248
 
249
249
  包含了所有可用的构建预设对应的构建配置。可以通过 `buildPreset` 所支持的字符串来使用构建配置,也可以使用这些字符串的下划线命令的方式。下面是两种方式的使用示例:
250
250
 
251
+ - 使用 `buildPreset` 所支持的字符串。
251
252
 
252
- <CH.Spotlight>
253
-
254
- ```ts modern.config.ts
253
+ ```ts title="modern.config.ts"
255
254
  import { defineConfig } from '@modern-js/module-tools';
256
255
 
257
256
  export default defineConfig({
@@ -260,25 +259,10 @@ export default defineConfig({
260
259
  },
261
260
  });
262
261
  ```
263
- ---
264
262
 
265
- 使用 `buildPreset` 所支持的字符串。
263
+ - 使用 `buildPreset` 所支持的字符串的下划线命名方式。
266
264
 
267
- ```ts modern.config.ts
268
- import { defineConfig } from '@modern-js/module-tools';
269
-
270
- export default defineConfig({
271
- buildPreset({ preset }) {
272
- return preset['npm-library'];
273
- },
274
- });
275
- ```
276
-
277
- ---
278
-
279
- 使用 `buildPreset` 所支持的字符串的下划线命名方式。
280
-
281
- ```ts modern.config.ts
265
+ ```ts title="modern.config.ts"
282
266
  import { defineConfig } from '@modern-js/module-tools';
283
267
 
284
268
  export default defineConfig({
@@ -288,8 +272,6 @@ export default defineConfig({
288
272
  });
289
273
  ```
290
274
 
291
- </CH.Spotlight>
292
-
293
275
  #### `extendPreset`
294
276
 
295
277
  类型:`Function`
@@ -300,7 +282,7 @@ export default defineConfig({
300
282
 
301
283
  例如在 `'npm-library'` 构建预设的基础上增加 `define` 配置:
302
284
 
303
- ```ts modern.config.ts
285
+ ```ts title="modern.config.ts"
304
286
  import { defineConfig } from '@modern-js/module-tools';
305
287
 
306
288
  export default defineConfig({
@@ -969,7 +969,7 @@ const designSystem = {
969
969
 
970
970
  要覆盖默认配置中的选项,请在 `designSystem` 中添加要覆盖的属性:
971
971
 
972
- ```js modern.config.ts
972
+ ```js title="modern.config.ts"
973
973
  import { defineConfig } from '@modern-js/module-tools';
974
974
 
975
975
  const designSystem = {
@@ -999,7 +999,7 @@ export default defineConfig({
999
999
 
1000
1000
  例如,如果您想添加一个额外的断点但保留现有的断点,则可以扩展 `screens` 属性:
1001
1001
 
1002
- ```js modern.config.ts
1002
+ ```js title="modern.config.ts"
1003
1003
  import { defineConfig } from '@modern-js/module-tools';
1004
1004
 
1005
1005
  const designSystem = {
@@ -1018,7 +1018,7 @@ export default defineConfig({
1018
1018
 
1019
1019
  您当然可以覆盖默认主题的某些部分,并在同一配置中扩展默认主题的其他部分:
1020
1020
 
1021
- ```js modern.config.ts
1021
+ ```js title="modern.config.ts"
1022
1022
  import { defineConfig } from '@modern-js/module-tools';
1023
1023
 
1024
1024
  const designSystem = {
@@ -1048,7 +1048,7 @@ export default defineConfig({
1048
1048
 
1049
1049
  例如,您可以在 `fill` 配置上通过引用 `theme('colors')` 为调色板中的每种颜色生成 `fill` utilities。
1050
1050
 
1051
- ```js modern.config.ts
1051
+ ```js title="modern.config.ts"
1052
1052
  import { defineConfig } from '@modern-js/module-tools';
1053
1053
 
1054
1054
  const designSystem = {
@@ -1069,7 +1069,7 @@ export default defineConfig({
1069
1069
 
1070
1070
  如果出于任何原因想要引用默认配置中的值,则可以从 `tailwindcss/defaultTheme` 导入它。一个有用的示例是,如果要将添加默认配置提供的字体中某一个字体:
1071
1071
 
1072
- ```js modern.config.ts
1072
+ ```js title="modern.config.ts"
1073
1073
  import { defineConfig } from '@modern-js/module-tools';
1074
1074
 
1075
1075
  const defaultTheme = require('tailwindcss/defaultTheme');
@@ -1134,7 +1134,7 @@ const designSystem = {
1134
1134
 
1135
1135
  另一个示例是在自定义插件中添加新的属性以进行引用。例如,如果您为项目编写了渐变插件,则可以向该插件引用的主题对象添加渐变属性:
1136
1136
 
1137
- ```js modern.config.ts
1137
+ ```js title="modern.config.ts"
1138
1138
  import { defineConfig } from '@modern-js/module-tools';
1139
1139
 
1140
1140
  const designSystem = {
@@ -25,7 +25,7 @@ sidebar_position: 4
25
25
 
26
26
  使用 npm 上的插件,需要通过包管理器安装插件,并通过 import 引入。
27
27
 
28
- ```js modern.config.ts
28
+ ```js title="modern.config.ts"
29
29
  import { myPlugin } from 'my-plugin';
30
30
 
31
31
  export default defineConfig({
@@ -37,7 +37,7 @@ export default defineConfig({
37
37
 
38
38
  使用本地代码仓库中的插件,直接通过相对路径 import 引入即可。
39
39
 
40
- ```js modern.config.ts
40
+ ```js title="modern.config.ts"
41
41
  import { myPlugin } from './plugins/myPlugin';
42
42
 
43
43
  export default defineConfig({
@@ -49,7 +49,7 @@ export default defineConfig({
49
49
 
50
50
  如果插件提供了一些自定义的配置项,你可以通过插件函数的参数传入配置。
51
51
 
52
- ```js modern.config.ts
52
+ ```js title="modern.config.ts"
53
53
  import { myPlugin } from 'my-plugin';
54
54
 
55
55
  export default defineConfig({
@@ -17,7 +17,7 @@ sidebar_position: 5
17
17
 
18
18
  对应 [Jest](https://jestjs.io/docs/configuration) 的配置,当为 `object` 类型时,可以配置 Jest 所支持的所有底层配置 。
19
19
 
20
- ```js modern.config.ts
20
+ ```js title="modern.config.ts"
21
21
  import { defineConfig } from '@modern-js/module-tools';
22
22
 
23
23
  export default defineConfig({
@@ -31,7 +31,7 @@ export default defineConfig({
31
31
 
32
32
  值为 `Function` 类型时,默认配置作为第一个参数传入,需要返回新的 Jest 配置对象。
33
33
 
34
- ```js modern.config.ts
34
+ ```js title="modern.config.ts"
35
35
  import { defineConfig } from '@modern-js/module-tools';
36
36
 
37
37
  export default defineConfig({
@@ -1,11 +1,11 @@
1
- ```js modern.config.ts
1
+ ```js title="modern.config.ts"
2
2
  import { myEsbuildPlugin } from './myEsbuildPlugin';
3
3
 
4
4
  export default defineConfig({
5
5
  buildConfig: {
6
6
  esbuildOptions: options => {
7
7
  options.plugins = [myEsbuildPlugin, ...options.plugins];
8
- return option;
8
+ return options;
9
9
  },
10
10
  },
11
11
  });
@@ -19,44 +19,30 @@ sidebar_position: 7
19
19
  - 设置静态资源路径为 `./assets`。
20
20
  - 对于不超过 **10kb** 的文件会内联到代码中。
21
21
 
22
+ ### 示例
23
+
22
24
  让我们看下面的例子:
23
25
 
24
- <CH.Spotlight>
26
+ - 项目源代码:
25
27
 
26
- ```ts ./src/asset.ts
28
+ ```ts title="./src/asset.ts"
27
29
  import img from './bg.png';
28
30
  console.log(img);
29
31
  ```
30
32
 
31
- ---
32
-
33
- 项目源代码。
34
-
35
- ---
36
-
37
- 如果 `bg.png` 的大小小于 10 kb,则此时产物目录结构和产物内容为。
38
-
39
- <CH.Code>
33
+ - 如果 `bg.png` 的大小小于 10 kb,则此时产物目录结构和产物内容为:
40
34
 
41
35
  ```bash
42
36
  ./dist
43
37
  └── asset.js
44
38
  ```
45
39
 
46
- ---
47
-
48
- ```js ./dist/asset.js
40
+ ```js title="./dist/asset.js"
49
41
  var img_default = 'data:image/png;base64,';
50
42
  console.info(img_default);
51
43
  ```
52
44
 
53
- </CH.Code>
54
-
55
- ---
56
-
57
- 如果 `bg.png` 的大小大于 10 kb,则此时产物目录结构和产物内容为。
58
-
59
- <CH.Code>
45
+ - 如果 `bg.png` 的大小大于 10 kb,则此时产物目录结构和产物内容为:
60
46
 
61
47
  ```bash
62
48
  ./dist
@@ -65,19 +51,12 @@ console.info(img_default);
65
51
  └── bg.13e2aba2.png
66
52
  ```
67
53
 
68
- ---
69
-
70
- ```js ./dist/asset.js
54
+ ```js title="./dist/asset.js"
71
55
  import img from './assets/bg.13e2aba2.png';
72
56
  console.info(img);
73
57
  ```
74
58
 
75
- </CH.Code>
76
-
77
- </CH.Spotlight>
78
-
79
- 当想要修改默认行为的时候,可以使用以下 API:
59
+ 当你想要修改默认行为的时候,可以使用以下 API:
80
60
 
81
61
  - `asset.path`:修改静态资源文件输出路径。
82
62
  - `asset.limit`:修改内联静态资源文件的阈值。
83
-
@@ -25,35 +25,21 @@ export default defineConfig({
25
25
  在 [「如何处理第三方依赖」](/guide/advance/external-dependency) 章节中,我们知道可以通过 [`autoExternals`](/api/config/build-config#autoexternal) 和 [`externals`](/api/config/build-config#externals) API 来控制项目是否对第三方依赖打包。
26
26
  因此在构建 umd 产物的过程中,我们也可以这样使用:
27
27
 
28
- <CH.Spotlight>
28
+ ### 示例
29
29
 
30
- ```json package.json
31
- {
32
- "dependencies": {
33
- "react": "^17"
34
- //...other dependencies
35
- }
36
- }
37
- ```
30
+ - 如果项目依赖了 `react`:
38
31
 
39
- ---
40
-
41
- 如果项目依赖了 `react`。
42
-
43
- ```json package.json
32
+ ```json title="package.json"
44
33
  {
45
34
  "dependencies": {
46
35
  "react": "^17"
47
- //...other dependencies
48
36
  }
49
37
  }
50
38
  ```
51
39
 
52
- ---
53
-
54
- `modern.config.ts` 配置。
40
+ - `modern.config.ts` 配置:
55
41
 
56
- ```ts
42
+ ```ts title="modern.config.ts"
57
43
  export default defineConfig({
58
44
  buildConfig: {
59
45
  format: 'umd',
@@ -63,20 +49,16 @@ export default defineConfig({
63
49
  });
64
50
  ```
65
51
 
66
- ---
67
-
68
- 当源码中使用了 `react` 依赖。
52
+ - 当源码中使用了 `react` 依赖:
69
53
 
70
- ```tsx src/index.ts
54
+ ```tsx title="src/index.ts"
71
55
  import React from 'react';
72
56
  console.info(React);
73
57
  ```
74
58
 
75
- ---
76
-
77
- 此时产物中不会将 `react` 代码打包到产物中。
59
+ - 此时产物中不会将 `react` 代码打包到产物中:
78
60
 
79
- ```js dist/index.js focus=1:7
61
+ ```js title="dist/index.js"
80
62
  (function (global, factory) {
81
63
  if (typeof module === 'object' && typeof module.exports === 'object')
82
64
  factory(exports, require('react'));
@@ -103,42 +85,18 @@ console.info(React);
103
85
  });
104
86
  ```
105
87
 
106
- </CH.Spotlight>
107
-
108
88
  通过上面的例子我们知道,当使用 `autoExternal` 和 `externals` API 后:
109
89
 
110
90
  - 在 Node.js 环境下,可以通过 `require('react')` 获取 react 依赖。
111
91
  - 在 浏览器环境下,可以通过 `global.react` 获取 react 依赖。
112
92
 
93
+ ### 三方依赖的全局变量名称
94
+
113
95
  然而在浏览器环境下,获取第三方依赖的时候,**全局变量名称不一定与依赖名称完全相同**,此时就要使用 [`buildConfig.umdGlobals`](/api/config/build-config#umdglobals) API。
114
96
 
115
97
  还是使用之前的例子,当 `react` 依赖以 `windows.React` 或者 `global.React` 全局变量的形式存在于浏览器环境下,那么此时:
116
98
 
117
- <CH.Spotlight>
118
-
119
- ```json package.json
120
- {
121
- "devDependencies": {
122
- "react": "^17"
123
- }
124
- }
125
- ```
126
-
127
- ---
128
-
129
- 如果项目依赖了 `react`。
130
-
131
- ```json package.json
132
- {
133
- "devDependencies": {
134
- "react": "^17"
135
- }
136
- }
137
- ```
138
-
139
- ---
140
-
141
- `modern.config.ts` 配置。
99
+ - `modern.config.ts` 配置:
142
100
 
143
101
  ```ts
144
102
  export default defineConfig({
@@ -151,20 +109,16 @@ export default defineConfig({
151
109
  });
152
110
  ```
153
111
 
154
- ---
155
-
156
- 当源码中使用了 `react` 依赖。
112
+ - 当源码中使用了 `react` 依赖:
157
113
 
158
- ```tsx src/index.ts
114
+ ```tsx title="src/index.ts"
159
115
  import React from 'react';
160
116
  console.info(React);
161
117
  ```
162
118
 
163
- ---
119
+ - 此时我们会看到这样的产物代码:
164
120
 
165
- 此时我们会看到这样的产物代码。
166
-
167
- ```js dist/index.js focus=12:18
121
+ ```js title="dist/index.js"
168
122
  (function (global, factory) {
169
123
  if (typeof module === 'object' && typeof module.exports === 'object')
170
124
  factory();
@@ -187,15 +141,13 @@ console.info(React);
187
141
  });
188
142
  ```
189
143
 
190
- </CH.Spotlight>
191
-
192
144
  此时项目就可以运行在浏览器中,并使用存在于全局对象上的 `React` 变量了。
193
145
 
194
146
  ## 更改项目的全局变量名称
195
147
 
196
148
  当我们将下面的代码打包成 umd 产物并运行在浏览器的时候,我们可以通过 `window.index` 来使用该模块。
197
149
 
198
- ```ts ./src/index.ts
150
+ ```ts title="./src/index.ts"
199
151
  export default () => {
200
152
  console.info('hello world');
201
153
  };
@@ -203,7 +155,7 @@ export default () => {
203
155
 
204
156
  **默认情况下,以源码文件名称作为该模块在浏览器里全局变量的名称**。对于上面的例子,其产物内容如下:
205
157
 
206
- ```js ./dist/index.js focus=9:9
158
+ ```js title="./dist/index.js"
207
159
  (function (global, factory) {
208
160
  if (typeof module === 'object' && typeof module.exports === 'object')
209
161
  factory(exports);
@@ -233,7 +185,7 @@ export default defineConfig({
233
185
 
234
186
  此时构建产物的内容为:
235
187
 
236
- ```js ./dist/index.js focus=9:9
188
+ ```js title="./dist/index.js"
237
189
  (function (global, factory) {
238
190
  if (typeof module === 'object' && typeof module.exports === 'object')
239
191
  factory(exports);
@@ -6,7 +6,7 @@ sidebar_position: 4
6
6
 
7
7
  一般来说,项目所需要的第三方依赖可以通过包管理器的 `install` 命令安装,在安装第三方依赖成功后,这些第三方依赖一般会出现在项目 `package.json` 的 `dependencies` 和 `devDependencies` 下。
8
8
 
9
- ```json pacakge.json
9
+ ```json title="pacakge.json"
10
10
  {
11
11
  "dependencies": {},
12
12
  "devDependencies": {}
@@ -25,25 +25,11 @@ sidebar_position: 4
25
25
 
26
26
  如果需要打包某些依赖,建议将它们从 `"dependencies"` 挪到 `"devDependencies"` ,这相当于对依赖进行 **prebundle** ,可以减小依赖安装的体积。
27
27
 
28
- <CH.Spotlight>
28
+ ### 示例
29
29
 
30
- ```json ./v1/package.json
31
- {
32
- "dependencies": {
33
- "react": "^17"
34
- },
35
- // or
36
- "peerDependencies": {
37
- "react": "^17"
38
- }
39
- }
40
- ```
41
-
42
- ---
30
+ 如果项目依赖了 `react`:
43
31
 
44
- 如果项目依赖了 `react`。
45
-
46
- ```json ./v1/package.json
32
+ ```json title="package.json"
47
33
  {
48
34
  "dependencies": {
49
35
  "react": "^17"
@@ -55,26 +41,20 @@ sidebar_position: 4
55
41
  }
56
42
  ```
57
43
 
58
- ---
44
+ 当源码中使用了 `react` 依赖:
59
45
 
60
- 当源码中使用了 `react` 依赖。
61
-
62
- ```tsx src/index.ts
46
+ ```tsx title="src/index.ts"
63
47
  import React from 'react';
64
48
  console.info(React);
65
49
  ```
66
50
 
67
- ---
68
-
69
- 此时产物中不会将 `react` 代码打包到产物中。
51
+ 此时产物中不会包含 `react` 的代码:
70
52
 
71
- ```js dist/index.js
53
+ ```js title="dist/index.js"
72
54
  import React from 'react';
73
55
  console.info(React);
74
56
  ```
75
57
 
76
- </CH.Spotlight>
77
-
78
58
  如果想要修改默认的处理方式,可以通过下面的 API 进行修改:
79
59
 
80
60
  - [`buildConfig.autoExternal`](/api/config/build-config#autoexternal)
@@ -50,7 +50,7 @@ Bundleless 是单文件编译模式,因此对于类型的引用和导出你需
50
50
 
51
51
  在 Bundle 构建过程中,除了将 `input` 设置为一个数组,也可以将它设置为一个对象。**通过使用对象的形式,我们可以修改构建产物输出的文件名称**。那么对于下面的例子,`./src/index.ts` 对应的构建产物文件路径为 `./dist/main.js`。
52
52
 
53
- ```js modern.config.ts
53
+ ```js title="modern.config.ts"
54
54
  import { defineConfig } from '@modern-js/module-tools';
55
55
 
56
56
  export default defineConfig({
@@ -85,7 +85,7 @@ export default defineConfig({
85
85
 
86
86
  默认情况下类型生成功能是开启的,如果需要关闭的话,可以按照如下配置:
87
87
 
88
- ```js modern.config.ts
88
+ ```js title="modern.config.ts"
89
89
  import { defineConfig } from '@modern-js/module-tools';
90
90
 
91
91
  export default defineConfig({
@@ -112,7 +112,7 @@ export default defineConfig({
112
112
 
113
113
  在 Bundleless 构建过程中,如果源代码中出现了别名,例如:
114
114
 
115
- ```js ./src/index.ts
115
+ ```js title="./src/index.ts"
116
116
  import utils from '@common/utils';
117
117
  ```
118
118
 
@@ -231,7 +231,7 @@ console.log('1.0.0');
231
231
 
232
232
  > 如果不存在 `d.ts` 文件,则可以手动创建。
233
233
 
234
- ```ts env.d.ts
234
+ ```ts title="env.d.ts"
235
235
  declare const YOUR_ADD_GLOBAL_VAR;
236
236
  ```
237
237
 
@@ -24,7 +24,7 @@ sidebar_position: 2
24
24
 
25
25
  一般来说,实现一个什么都不做的调试工具,其实现代码以及相关配置如下:
26
26
 
27
- ``` ts do-nothing.ts
27
+ ```ts do-nothing.ts
28
28
  export const myPlugin = (): CliPlugin<ModuleTools> => ({
29
29
  name: 'do-nothing',
30
30
  setup() {
@@ -53,7 +53,7 @@ export const myPlugin = (): CliPlugin<ModuleTools> => ({
53
53
 
54
54
  如果需要使用该调试工具插件,则需要在配置文件中增加它:
55
55
 
56
- ``` ts
56
+ ```ts
57
57
  import doNothingPlugin from './plugins/do-nothing';
58
58
 
59
59
  export default defineConfig({
@@ -31,7 +31,7 @@ sidebar_position: 6
31
31
 
32
32
  例如在下面的配置中扩展了原有的颜色配置:
33
33
 
34
- ```ts ./modern.config.ts
34
+ ```ts title="modern.config.ts"
35
35
  export default {
36
36
  designSystem: {
37
37
  extend: {
@@ -47,7 +47,7 @@ export default {
47
47
 
48
48
  #### HTML 类名
49
49
 
50
- ```tsx ./src/index.tsx
50
+ ```tsx title="./src/index.tsx"
51
51
  import 'tailwindcss/utilities.css';
52
52
 
53
53
  export default () => {
@@ -59,9 +59,7 @@ export default () => {
59
59
 
60
60
  关于 [`@apply`](https://tailwindcss.com/docs/functions-and-directives#apply)。
61
61
 
62
- <CH.Code>
63
-
64
- ```tsx ./src/index.tsx
62
+ ```tsx title="./src/index.tsx"
65
63
  import './index.css';
66
64
 
67
65
  export default () => {
@@ -69,10 +67,8 @@ export default () => {
69
67
  };
70
68
  ```
71
69
 
72
- ```css ./src/index.css
70
+ ```css title="./src/index.css"
73
71
  .btn-primary {
74
72
  @apply bg-primary;
75
73
  }
76
74
  ```
77
-
78
- </CH.Code>
@@ -41,7 +41,7 @@ $ npx modern change
41
41
 
42
42
  当执行成功后,生成的包含变更记录的 Markdown 文件会保存在项目的 `.changeset` 目录下面。其内容类似下面这样:
43
43
 
44
- ```markdown .changeset/brave-dryers-agree.md
44
+ ```markdown title=".changeset/brave-dryers-agree.md"
45
45
  ---
46
46
  'module-example': patch
47
47
  ---
@@ -57,7 +57,7 @@ publish test
57
57
 
58
58
  执行 `modern bump` 将会基于 `.changeset/` 目录下记录了变更的 Markdown 文件内容来修改 `package.json` 中的版本号,同时生成 `CHANGELOG.md` 文件。**而当版本更新完成后,这些记录变更的 Markdown 文件也会被删除,也可说这些 Markdown 文件被“消耗”掉了**。
59
59
 
60
- ```markdown CHANGELOG.md
60
+ ```markdown title="CHANGELOG.md"
61
61
  # module
62
62
 
63
63
  ## 0.1.1