@modern-js/module-tools-docs 2.25.0 → 2.25.1

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 (29) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/docs/en/api/config/build-config.md +153 -38
  3. package/docs/en/api/config/build-preset.mdx +3 -3
  4. package/docs/en/api/config/design-system.md +3 -3
  5. package/docs/en/api/config/dev.md +22 -25
  6. package/docs/en/api/config/plugins.md +50 -5
  7. package/docs/en/api/config/testing.md +3 -3
  8. package/docs/en/guide/advance/build-umd.mdx +1 -1
  9. package/docs/en/guide/basic/command-preview.md +2 -2
  10. package/docs/en/guide/basic/modify-output-product.md +16 -4
  11. package/docs/en/guide/best-practices/components.mdx +3 -3
  12. package/docs/en/plugins/guide/setup-function.mdx +1 -1
  13. package/docs/en/plugins/official-list/plugin-banner.md +1 -1
  14. package/docs/en/plugins/official-list/plugin-import.mdx +34 -25
  15. package/docs/zh/api/config/build-config.md +158 -41
  16. package/docs/zh/api/config/build-preset.mdx +1 -1
  17. package/docs/zh/api/config/design-system.md +3 -3
  18. package/docs/zh/api/config/dev.md +23 -26
  19. package/docs/zh/api/config/plugins.md +50 -5
  20. package/docs/zh/api/config/testing.md +3 -3
  21. package/docs/zh/guide/advance/build-umd.mdx +1 -1
  22. package/docs/zh/guide/basic/before-getting-started.md +1 -1
  23. package/docs/zh/guide/basic/command-preview.md +3 -3
  24. package/docs/zh/guide/basic/modify-output-product.md +18 -7
  25. package/docs/zh/guide/best-practices/components.mdx +3 -3
  26. package/docs/zh/plugins/guide/setup-function.mdx +1 -1
  27. package/docs/zh/plugins/official-list/plugin-banner.md +1 -1
  28. package/docs/zh/plugins/official-list/plugin-import.mdx +30 -21
  29. package/package.json +3 -3
@@ -2,17 +2,62 @@
2
2
  sidebar_position: 4
3
3
  ---
4
4
 
5
- # Plugins
5
+ # plugins
6
6
 
7
7
  本章介绍注册 Module Tools 插件的配置。
8
8
 
9
- - 类型:`Array<ModuleToolsPlugin>`
9
+ - 类型:`ModuleToolsPlugin[]`
10
+ - 默认值:`undefined`
11
+
12
+ ## 插件执行顺序
13
+
14
+ 默认情况下,自定义插件会按照 `plugins` 数组的顺序依次执行,Module Tools 内置插件的执行时机早于自定义插件。
15
+
16
+ 当插件内部使用了控制顺序的相关字段,比如 `pre`、`post` 时,会基于声明的字段对执行顺序进行调整,详见 [插件之间的关系](https://modernjs.dev/guides/topic-detail/framework-plugin/relationship)。
17
+
18
+ ## 开发插件
19
+
20
+ 关于如何编写插件,可以查看[「插件编写指南」](/plugins/guide/getting-started)。
21
+
22
+ ## 示例
23
+
24
+ ### 使用 npm 上的插件
25
+
26
+ 使用 npm 上的插件,需要通过包管理器安装插件,并通过 import 引入。
27
+
28
+ ```js modern.config.ts
29
+ import { myPlugin } from 'my-plugin';
30
+
31
+ export default defineConfig({
32
+ plugins: [myPlugin()],
33
+ });
34
+ ```
35
+
36
+ #### 使用本地插件
37
+
38
+ 使用本地代码仓库中的插件,直接通过相对路径 import 引入即可。
10
39
 
11
40
  ```js modern.config.ts
12
- import { examplePlugin } from './plugins/example';
41
+ import { myPlugin } from './plugins/myPlugin';
42
+
13
43
  export default defineConfig({
14
- plugins: [examplePlugin()],
44
+ plugins: [myPlugin()],
15
45
  });
16
46
  ```
17
47
 
18
- 关于如何编写插件,可以查看[【插件编写指南】](/plugins/guide/getting-started)。
48
+ ### 插件配置项
49
+
50
+ 如果插件提供了一些自定义的配置项,你可以通过插件函数的参数传入配置。
51
+
52
+ ```js modern.config.ts
53
+ import { myPlugin } from 'my-plugin';
54
+
55
+ export default defineConfig({
56
+ plugins: [
57
+ myPlugin({
58
+ foo: 1,
59
+ bar: 2,
60
+ }),
61
+ ],
62
+ });
63
+ ```
@@ -2,7 +2,7 @@
2
2
  sidebar_position: 5
3
3
  ---
4
4
 
5
- # Testing
5
+ # testing
6
6
 
7
7
  本章描述了测试相关的配置。
8
8
 
@@ -12,10 +12,10 @@ sidebar_position: 5
12
12
 
13
13
  ## jest
14
14
 
15
- - 类型: `Object | Function`
15
+ - 类型: `object | Function`
16
16
  - 默认值:`{}`
17
17
 
18
- 对应 [Jest](https://jestjs.io/docs/configuration) 的配置,当为 `Object` 类型时,可以配置 Jest 所支持的所有底层配置 。
18
+ 对应 [Jest](https://jestjs.io/docs/configuration) 的配置,当为 `object` 类型时,可以配置 Jest 所支持的所有底层配置 。
19
19
 
20
20
  ```js modern.config.ts
21
21
  import { defineConfig } from '@modern-js/module-tools';
@@ -22,7 +22,7 @@ export default defineConfig({
22
22
 
23
23
  ## umd 产物的第三方依赖处理
24
24
 
25
- 在 [【如何处理第三方依赖】](/guide/advance/external-dependency) 章节中,我们知道可以通过 [`autoExternals`](/api/config/build-config#autoexternal) 和 [`externals`](/api/config/build-config#externals) API 来控制项目是否对第三方依赖打包。
25
+ 在 [「如何处理第三方依赖」](/guide/advance/external-dependency) 章节中,我们知道可以通过 [`autoExternals`](/api/config/build-config#autoexternal) 和 [`externals`](/api/config/build-config#externals) API 来控制项目是否对第三方依赖打包。
26
26
  因此在构建 umd 产物的过程中,我们也可以这样使用:
27
27
 
28
28
  <CH.Spotlight>
@@ -14,7 +14,7 @@ sidebar_position: 1
14
14
 
15
15
  npm 是 NodeJS 的标准软件包管理器。它一开始的用途是用于下载和管理 NodeJS 包的依赖关系,但后来它逐渐变成为一个用于前端 JavaScript 的工具。
16
16
 
17
- **如果你已经对 npm 和 npm 包的使用方式有所了解,那么可以直接跳到[npm 包管理器】](/guide/basic/before-getting-started#npm-包管理器)部分。**
17
+ **如果你已经对 npm 和 npm 包的使用方式有所了解,那么可以直接跳到[npm 包管理器」](/guide/basic/before-getting-started#npm-包管理器)部分。**
18
18
 
19
19
  ## npm 包类型项目
20
20
 
@@ -2,9 +2,9 @@
2
2
  sidebar_position: 2
3
3
  ---
4
4
 
5
- # 命令预览
5
+ # CLI 命令
6
6
 
7
- 模块工程项目可以使用的命令:
7
+ Module Tools 项目可以使用的 CLI 命令如下:
8
8
 
9
9
  ## `modern build`
10
10
 
@@ -60,7 +60,7 @@ Options:
60
60
  - Tailwind CSS 支持
61
61
  - Modern.js Runtime API
62
62
 
63
- 关于这些功能,可以通过[【使用微生成器】](/guide/basic/use-micro-generator) 章节了解更多。
63
+ 关于这些功能,可以通过[「使用微生成器」](/guide/basic/use-micro-generator) 章节了解更多。
64
64
 
65
65
  ## `modern dev`
66
66
 
@@ -6,20 +6,24 @@ sidebar_position: 3
6
6
 
7
7
  ## 默认输出产物
8
8
 
9
- 当在初始化的项目里使用 `modern build` 命令的时候,会根据 Module Tools 默认支持的配置生成相应的产物。默认支持的配置具体如下:
9
+ 当你在初始化的项目里使用 `modern build` 命令的时候,Module Tools 会根据当前配置内容,生成相应的构建产物。
10
+
11
+ 默认的配置内容如下:
10
12
 
11
13
  ```ts title="modern.config.ts"
12
14
  import { moduleTools, defineConfig } from '@modern-js/module-tools';
13
15
 
14
16
  export default defineConfig({
17
+ // 注册 Module Tools 的 CLI 工具
15
18
  plugins: [moduleTools()],
19
+ // 指定构建预设配置
16
20
  buildPreset: 'npm-library',
17
21
  });
18
22
  ```
19
23
 
20
24
  **默认生成产物具有以下特点**:
21
25
 
22
- - 会生成[CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules)和[ESM](https://nodejs.org/api/esm.html#modules-ecmascript-modules)两份产物。
26
+ - 会生成 [CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules) [ESM](https://nodejs.org/api/esm.html#modules-ecmascript-modules) 两份产物。
23
27
  - 代码语法支持到 `ES6` ,更高级的语法将会被转换。
24
28
  - 所有的代码经过打包变成了一个文件,即进行了 **bundle** 处理。
25
29
  - 产物输出根目录为项目下的 `dist` 目录,类型文件输出的目录为 `dist/types`。
@@ -29,7 +33,7 @@ export default defineConfig({
29
33
  1. `buildPreset` 是什么?
30
34
  2. 产物的这些特点是由什么决定的?
31
35
 
32
- 那么接下来首先解释一下 `buildPreset`。
36
+ 接下来,我们首先来了解一下 `buildPreset`。
33
37
 
34
38
  ## 构建预设
35
39
 
@@ -70,10 +74,17 @@ export default defineConfig({
70
74
  });
71
75
  ```
72
76
 
73
- 在上面的代码实现中,`preset.NPM_LIBRARY` 与预设字符串 `"npm-library"` 是相对应的,它代表着 `"npm-library"` 等价的多组构建相关的配置。我们通过 `map` 方法遍历了 `NPM_LIBRARY` 这个数组,在这个数组中包含了多个 `buildConfig` 对象。我们将原本的 `buildConfig` 对象进行了浅拷贝,并修改了浅拷贝后 `target` 的值,将它指定为 `es5`。
77
+ 在上面的代码实现中,`preset.NPM_LIBRARY` 与预设字符串 `"npm-library"` 是相对应的,它代表与 `"npm-library"` 等价的多个构建相关的配置。
78
+
79
+ 我们通过 `map` 方法遍历了 `NPM_LIBRARY` 这个数组,在这个数组中包含了多个 `buildConfig` 对象。我们将原本的 `buildConfig` 对象进行了浅拷贝,并修改了浅拷贝后 `target` 的值,将它指定为 `es5`。
80
+
81
+ 如果你想了解 `preset.NPM_LIBRARY` 具体包含的内容,可以通过 [BuildPreset API](/api/config/build-preset) 查看。
82
+
83
+ 此外,在 `preset` 对象下,不仅包含了 `NPM_LIBRARY`,也包含了其他类似的常量。
74
84
 
75
- > 关于 `preset.NPM_LIBRARY` 具体对应的值,可以通过 [BuildPreset API](/api/config/build-preset) 查看。在 `preset` 对象下不仅包含了 `NPM_LIBRARY`,还包含了其他类似的常量。
76
- > 我们不仅可以使用 `preset.NPM_LIBRARY` 来获取 `"npm-library"` 对应的构建配置,也可以使用 `preset['npm-library']` 这样的方式。
85
+ :::tip
86
+ 我们不仅可以使用 `preset.NPM_LIBRARY` 来获取 `"npm-library"` 对应的构建配置,也可以使用 `preset['npm-library']` 这样的方式。
87
+ :::
77
88
 
78
89
  那么这里的 `buildConfig` 对象是什么呢?之前提到的构建产物特点又是根据什么呢?
79
90
 
@@ -81,7 +92,7 @@ export default defineConfig({
81
92
 
82
93
  ## 构建配置(对象)
83
94
 
84
- **`buildConfig` 是一个用来描述如何编译、生成构建产物的配置对象**。在最开始提到的关于“_构建产物的特点_”,其实都是 `buildConfig` 所支持的属性。目前所支持的属性覆盖了大部分模块类型项目在构建产物时的需求,`buildConfig` 不仅包含一些产物所具备的属性,也包含了构建产物所需要的一些特性功能。接下来从分类的角度简单罗列一下:
95
+ **`buildConfig` 是一个用来描述如何编译、生成构建产物的配置项**。在最开始提到的关于“_构建产物的特点_”,其实都是 `buildConfig` 所支持的属性。目前所支持的属性覆盖了大部分模块类型项目在构建产物时的需求,`buildConfig` 不仅包含一些产物所具备的属性,也包含了构建产物所需要的一些特性功能。接下来从分类的角度简单罗列一下:
85
96
 
86
97
  **构建产物的基本属性包括:**
87
98
 
@@ -609,7 +609,7 @@ Tailwind CSS 提供了 [`@apply`](https://v2.tailwindcss.com/docs/functions-and-
609
609
 
610
610
  对于以下代码,在 bundle 和 bundleless 两种模式下,构建产物会有很大区别。
611
611
 
612
- > 所谓 bundle 和 bundleless 可以查看 [Bundle 和 Bundleless](/guide/advance/in-depth-about-build#bundle-和-bundleless)
612
+ > 所谓 bundle 和 bundleless 可以查看 [Bundle 和 Bundleless](/guide/advance/in-depth-about-build#bundle-和-bundleless)
613
613
 
614
614
  ```tsx ./src/index.tsx
615
615
  import 'tailwindcss/utilities.css';
@@ -786,8 +786,8 @@ export default defineConfig({
786
786
 
787
787
  ## 测试组件
788
788
 
789
- 关于如何对组件进行测试,可以参考 [【测试项目】](/guide/basic/test-your-project)。
789
+ 关于如何对组件进行测试,可以参考 [「测试项目」](/guide/basic/test-your-project)。
790
790
 
791
791
  ## 发布组件
792
792
 
793
- 推荐使用模块工程提供版本发布功能,可以参考 [【版本管理与发布】](/guide/basic/publish-your-project)。
793
+ 推荐使用模块工程提供版本发布功能,可以参考 [「版本管理与发布」](/guide/basic/publish-your-project)。
@@ -4,7 +4,7 @@ sidebar_position: 3
4
4
 
5
5
  # Setup 函数
6
6
 
7
- 在[【插件对象】](/plugins/guide/plugin-object) 部分我们知道插件对象包含了一个 `setup` 函数,该函数不仅包含了一个 `api` 对象参数,同时还可以返回一个 Hooks 对象。
7
+ 在[「插件对象」](/plugins/guide/plugin-object) 部分我们知道插件对象包含了一个 `setup` 函数,该函数不仅包含了一个 `api` 对象参数,同时还可以返回一个 Hooks 对象。
8
8
 
9
9
  ## 插件 API 对象
10
10
 
@@ -39,7 +39,7 @@ export default defineConfig({
39
39
  ```
40
40
 
41
41
  :::tip
42
- 注意:CSS 的注释不支持 `//comment` 这样的写法。详见[CSS 注释】](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Comments)
42
+ 注意:CSS 的注释不支持 `//comment` 这样的写法。详见[CSS 注释」](https://developer.mozilla.org/zh-CN/docs/Web/CSS/Comments)
43
43
  :::
44
44
 
45
45
  ## 示例
@@ -3,7 +3,7 @@
3
3
  提供与 [babel-plugin-import](https://github.com/umijs/babel-plugin-import) 等价的能力和配置,基于 [SWC](https://swc.rs/) 实现。
4
4
 
5
5
  :::tip
6
- @modern-js/module-tools 2.16.0 版本开始,该插件功能内置在 module-tools 中,由 [`transformImport`](api/config/build-config.html#transformimport)
6
+ `@modern-js/module-tools` v2.16.0 版本开始,该插件功能内置在 Module Tools 中,由 [`transformImport`](api/config/build-config.html#transformimport)
7
7
  配置提供。
8
8
  :::
9
9
 
@@ -34,10 +34,12 @@ export default defineConfig({
34
34
  plugins: [
35
35
  moduleTools(),
36
36
  modulePluginImport({
37
- pluginImport: [{
38
- libraryName: 'antd',
39
- style: true,
40
- }],
37
+ pluginImport: [
38
+ {
39
+ libraryName: 'antd',
40
+ style: true,
41
+ },
42
+ ],
41
43
  }),
42
44
  ],
43
45
  });
@@ -47,17 +49,17 @@ export default defineConfig({
47
49
 
48
50
  ## 配置
49
51
 
50
- * **类型:**
52
+ - **类型:**
51
53
 
52
54
  ```ts
53
55
  type Options = {
54
56
  pluginImport?: ImportItem[];
55
- }
57
+ };
56
58
  ```
57
59
 
58
60
  ### pluginImport
59
61
 
60
- * 类型:`Array`
62
+ - 类型:`object[]`
61
63
 
62
64
  其中数组元素为一个 babel-plugin-import 的配置对象。配置对象可以参考 [options](https://github.com/umijs/babel-plugin-import#options)。
63
65
 
@@ -76,7 +78,7 @@ export default defineConfig({
76
78
  {
77
79
  libraryName: 'foo',
78
80
  style: true,
79
- }
81
+ },
80
82
  ],
81
83
  }),
82
84
  ],
@@ -117,10 +119,12 @@ export default defineConfig({
117
119
  plugins: [
118
120
  moduleTools(),
119
121
  modulePluginImport({
120
- pluginImport: [{
121
- libraryName: 'foo',
122
- customName: 'foo/es/{{ member }}'
123
- }],
122
+ pluginImport: [
123
+ {
124
+ libraryName: 'foo',
125
+ customName: 'foo/es/{{ member }}',
126
+ },
127
+ ],
124
128
  }),
125
129
  ],
126
130
  });
@@ -138,16 +142,19 @@ export default defineConfig({
138
142
  plugins: [
139
143
  moduleTools(),
140
144
  modulePluginImport({
141
- pluginImport: [{
142
- libraryName: 'foo',
143
- customName: 'foo/es/{{ member }}'
144
- }],
145
+ pluginImport: [
146
+ {
147
+ libraryName: 'foo',
148
+ customName: 'foo/es/{{ member }}',
149
+ },
150
+ ],
145
151
  }),
146
152
  ],
147
153
  });
148
154
  ```
149
155
 
150
156
  ---
157
+
151
158
  转换后:
152
159
 
153
160
  ```ts
@@ -168,10 +175,12 @@ export default defineConfig({
168
175
  plugins: [
169
176
  moduleTools(),
170
177
  modulePluginImport({
171
- pluginImport: [{
172
- libraryName: 'foo',
173
- customName: 'foo/es/{{ kebabCase member }}',
174
- }],
178
+ pluginImport: [
179
+ {
180
+ libraryName: 'foo',
181
+ customName: 'foo/es/{{ kebabCase member }}',
182
+ },
183
+ ],
175
184
  }),
176
185
  ],
177
186
  });
package/package.json CHANGED
@@ -9,15 +9,15 @@
9
9
  "directory": "packages/document/module-doc"
10
10
  },
11
11
  "license": "MIT",
12
- "version": "2.25.0",
12
+ "version": "2.25.1",
13
13
  "main": "index.js",
14
14
  "dependencies": {
15
15
  "@code-hike/mdx": "^0.7.4",
16
16
  "react": "^18.2.0",
17
17
  "react-dom": "^18.2.0",
18
18
  "shiki": "^0.11.1",
19
- "@modern-js/doc-plugin-auto-sidebar": "2.25.0",
20
- "@modern-js/doc-tools": "2.25.0"
19
+ "@modern-js/doc-plugin-auto-sidebar": "2.25.1",
20
+ "@modern-js/doc-tools": "2.25.1"
21
21
  },
22
22
  "scripts": {
23
23
  "dev": "modern dev",