@modern-js/module-tools-docs 2.24.1 → 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 (46) hide show
  1. package/CHANGELOG.md +16 -3
  2. package/docs/en/api/config/build-config.md +185 -29
  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/api/plugin-api/plugin-hooks.md +13 -13
  9. package/docs/en/guide/advance/build-umd.mdx +1 -1
  10. package/docs/en/guide/advance/in-depth-about-dev-command.md +1 -1
  11. package/docs/en/guide/basic/before-getting-started.md +2 -2
  12. package/docs/en/guide/basic/command-preview.md +2 -2
  13. package/docs/en/guide/basic/modify-output-product.md +18 -6
  14. package/docs/en/guide/basic/use-micro-generator.md +8 -8
  15. package/docs/en/guide/best-practices/components.mdx +3 -3
  16. package/docs/en/guide/intro/getting-started.md +1 -1
  17. package/docs/en/plugins/guide/setup-function.mdx +4 -4
  18. package/docs/en/plugins/official-list/plugin-babel.md +2 -2
  19. package/docs/en/plugins/official-list/plugin-banner.md +3 -3
  20. package/docs/en/plugins/official-list/plugin-import.mdx +34 -25
  21. package/docs/en/plugins/official-list/plugin-node-polyfill.md +3 -3
  22. package/docs/en/plugins/official-list/plugin-polyfill.md +2 -2
  23. package/docs/zh/api/config/build-config.md +190 -33
  24. package/docs/zh/api/config/build-preset.mdx +1 -1
  25. package/docs/zh/api/config/design-system.md +3 -3
  26. package/docs/zh/api/config/dev.md +23 -26
  27. package/docs/zh/api/config/plugins.md +50 -5
  28. package/docs/zh/api/config/testing.md +3 -3
  29. package/docs/zh/api/plugin-api/plugin-hooks.md +13 -13
  30. package/docs/zh/guide/advance/build-umd.mdx +1 -1
  31. package/docs/zh/guide/advance/in-depth-about-dev-command.md +1 -1
  32. package/docs/zh/guide/basic/before-getting-started.md +3 -3
  33. package/docs/zh/guide/basic/command-preview.md +3 -3
  34. package/docs/zh/guide/basic/modify-output-product.md +20 -9
  35. package/docs/zh/guide/basic/test-your-project.mdx +3 -3
  36. package/docs/zh/guide/basic/use-micro-generator.md +8 -8
  37. package/docs/zh/guide/best-practices/components.mdx +3 -3
  38. package/docs/zh/guide/intro/getting-started.md +1 -1
  39. package/docs/zh/plugins/guide/setup-function.mdx +4 -4
  40. package/docs/zh/plugins/official-list/plugin-babel.md +2 -2
  41. package/docs/zh/plugins/official-list/plugin-banner.md +3 -3
  42. package/docs/zh/plugins/official-list/plugin-import.mdx +35 -26
  43. package/docs/zh/plugins/official-list/plugin-node-polyfill.md +3 -3
  44. package/docs/zh/plugins/official-list/plugin-polyfill.md +2 -2
  45. package/modern.config.ts +1 -1
  46. package/package.json +3 -3
@@ -22,7 +22,7 @@
22
22
  执行整体构建流程之前触发。
23
23
 
24
24
  ```ts
25
- export default (): CliPlugin<ModuleTools> => ({
25
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
26
26
  name: 'my-plugin',
27
27
 
28
28
  setup() {
@@ -61,7 +61,7 @@ type Return = BuildConfig;
61
61
  根据构建配置,Module Tools 会将整体构建分成多个子构建任务。该 Hook 将会在每一个构建子任务之前触发。
62
62
 
63
63
  ```ts
64
- export default (): CliPlugin<ModuleTools> => ({
64
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
65
65
  name: 'my-plugin',
66
66
 
67
67
  setup() {
@@ -83,7 +83,7 @@ export default (): CliPlugin<ModuleTools> => ({
83
83
  每一个构建子任务结束之后触发。
84
84
 
85
85
  ```ts
86
- export default (): CliPlugin<ModuleTools> => ({
86
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
87
87
  name: 'my-plugin',
88
88
 
89
89
  setup() {
@@ -111,7 +111,7 @@ export interface BuildTaskResult {
111
111
  整体构建流程结束之后触发。
112
112
 
113
113
  ```ts
114
- export default (): CliPlugin<ModuleTools> => ({
114
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
115
115
  name: 'my-plugin',
116
116
 
117
117
  setup() {
@@ -154,7 +154,7 @@ module-tools 还提供了 `build --platform` 命令来执行特定的构建任
154
154
  获取在执行 `build --platform` 命令时候需要运行的任务信息。
155
155
 
156
156
  ```ts
157
- export default (): CliPlugin<ModuleTools> => ({
157
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
158
158
  name: 'my-plugin',
159
159
 
160
160
  setup() {
@@ -190,7 +190,7 @@ export interface RegisterBuildPlatformResult {
190
190
  当执行 `build --platform` 命令的时候,会触发所有已注册的构建任务。`beforeBuildPlatform` 会在执行整体的构建任务之前触发。
191
191
 
192
192
  ```ts
193
- export default (): CliPlugin<ModuleTools> => ({
193
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
194
194
  name: 'my-plugin',
195
195
 
196
196
  setup() {
@@ -220,7 +220,7 @@ export interface RegisterBuildPlatformResult {
220
220
  当执行 `build --platform` 命令的时候,会触发所有已注册的构建任务。`buildPlatform` 会在每个构建任务执行之前触发。
221
221
 
222
222
  ```ts
223
- export default (): CliPlugin<ModuleTools> => ({
223
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
224
224
  name: 'my-plugin',
225
225
 
226
226
  setup() {
@@ -246,7 +246,7 @@ export interface Options {
246
246
  当执行 `build --platform` 命令的时候,会触发所有已注册的构建任务。`afterBuildPlatform` 会在整体 platform 构建任务结束后触发。
247
247
 
248
248
  ```ts
249
- export default (): CliPlugin<ModuleTools> => ({
249
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
250
250
  name: 'my-plugin',
251
251
 
252
252
  setup() {
@@ -294,7 +294,7 @@ export interface BuildPlatformResult {
294
294
  - 执行调试任务的函数。
295
295
 
296
296
  ```ts
297
- export default (): CliPlugin<ModuleTools> => ({
297
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
298
298
  name: 'my-plugin',
299
299
 
300
300
  setup() {
@@ -348,7 +348,7 @@ export interface DevToolData {
348
348
  在收集完所有调试工具元数据后,执行 dev 任务之前触发。
349
349
 
350
350
  ```ts
351
- export default (): CliPlugin<ModuleTools> => ({
351
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
352
352
  name: 'my-plugin',
353
353
 
354
354
  setup() {
@@ -397,7 +397,7 @@ const question = [
397
397
  `afterDevMenu` 选择调试列表/菜单选项后触发。
398
398
 
399
399
  ```ts
400
- export default (): CliPlugin<ModuleTools> => ({
400
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
401
401
  name: 'my-plugin',
402
402
 
403
403
  setup() {
@@ -444,7 +444,7 @@ export interface DevToolData {
444
444
  执行调试任务之前触发。
445
445
 
446
446
  ```ts
447
- export default (): CliPlugin<ModuleTools> => ({
447
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
448
448
  name: 'my-plugin',
449
449
 
450
450
  setup() {
@@ -479,7 +479,7 @@ export interface DevToolData {
479
479
  在中断调试任务进程时触发。
480
480
 
481
481
  ```ts
482
- export default (): CliPlugin<ModuleTools> => ({
482
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
483
483
  name: 'my-plugin',
484
484
 
485
485
  setup() {
@@ -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>
@@ -25,7 +25,7 @@ sidebar_position: 2
25
25
  一般来说,实现一个什么都不做的调试工具,其实现代码以及相关配置如下:
26
26
 
27
27
  ``` ts do-nothing.ts
28
- export default (): CliPlugin<ModuleTools> => ({
28
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
29
29
  name: 'do-nothing',
30
30
  setup() {
31
31
  return {
@@ -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
 
@@ -167,7 +167,7 @@ npm install -g pnpm
167
167
  默认情况下,生成的配置文件的内容如下:
168
168
 
169
169
  ```ts title="modern.config.ts"
170
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
170
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
171
171
 
172
172
  export default defineConfig({
173
173
  plugins: [moduleTools()],
@@ -178,7 +178,7 @@ export default defineConfig({
178
178
  **我们推荐使用 `defineConfig` 函数**,不过并不强制使用它。因此你也可以在配置文件中直接返回一个对象:
179
179
 
180
180
  ```ts title="modern.config.ts"
181
- import moduleTools from '@modern-js/module-tools';
181
+ import { moduleTools } from '@modern-js/module-tools';
182
182
 
183
183
  export default {
184
184
  plugins: [moduleTools()],
@@ -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
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
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
 
@@ -58,7 +62,7 @@ export default defineConfig({
58
62
  例如,如果使用预设函数的形式达到预设字符串 `"npm-library-es5"` 同样的效果,可以按照如下的方式:
59
63
 
60
64
  ```ts title="modern.config.ts"
61
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
65
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
62
66
 
63
67
  export default defineConfig({
64
68
  plugins: [moduleTools()],
@@ -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
 
@@ -11,13 +11,13 @@ sidebar_position: 6
11
11
  想要使用项目的测试功能,需要确保项目中包含依赖:`"@modern-js/plugin-testing"`,以及按照类似下面的内容进行配置:
12
12
 
13
13
  ``` ts
14
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
15
- import testPlugin from '@modern-js/plugin-testing';
14
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
15
+ import { testingPlugin } from '@modern-js/plugin-testing';
16
16
 
17
17
  export default defineConfig({
18
18
  plugins: [
19
19
  moduleTools(),
20
- testPlugin(),
20
+ testingPlugin(),
21
21
  ],
22
22
  });
23
23
  ```
@@ -21,13 +21,13 @@ sidebar_position: 4
21
21
  :::tip
22
22
  在成功开启后,会提示需要手动在配置中增加如下类似的代码。
23
23
  ``` ts
24
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
25
- import testPlugin from '@modern-js/plugin-testing';
24
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
25
+ import { testingPlugin } from '@modern-js/plugin-testing';
26
26
 
27
27
  export default defineConfig({
28
28
  plugins: [
29
29
  moduleTools(),
30
- testPlugin(),
30
+ testingPlugin(),
31
31
  ],
32
32
  });
33
33
  ```
@@ -40,8 +40,8 @@ export default defineConfig({
40
40
  :::tip
41
41
  在成功开启后,会提示需要手动在配置中增加如下类似的代码。
42
42
  ``` ts
43
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
44
- import storybookPlugin from '@modern-js/plugin-storybook';
43
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
44
+ import { storybookPlugin } from '@modern-js/plugin-storybook';
45
45
 
46
46
  export default defineConfig({
47
47
  plugins: [
@@ -68,8 +68,8 @@ export default defineConfig({
68
68
  :::tip
69
69
  在成功开启后,会提示需要手动在配置中增加如下类似的代码。
70
70
  ``` ts
71
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
72
- import tailwindPlugin from '@modern-js/plugin-tailwindcss';
71
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
72
+ import { tailwindcssPlugin } from '@modern-js/plugin-tailwindcss';
73
73
 
74
74
  export default defineConfig({
75
75
  plugins: [
@@ -89,7 +89,7 @@ export default defineConfig({
89
89
  :::tip
90
90
  在成功开启后,会提示需要手动在配置中增加如下类似的代码。
91
91
  ``` ts
92
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
92
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
93
93
  import runtime from '@modern-js/runtime/cli';
94
94
 
95
95
  export default defineConfig({
@@ -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)。
@@ -51,7 +51,7 @@ npm install -D @modern-js/module-tools typescript
51
51
  接着在项目的根目录下创建 `modern.config.(t|j)s` 文件:
52
52
 
53
53
  ```ts
54
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
54
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
55
55
 
56
56
  export default defineConfig({
57
57
  plugins: [moduleTools()],
@@ -4,14 +4,14 @@ 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
 
11
11
  插件的 `setup` 函数会提供一个 `api` 对象参数,你可以调用该对象上提供的一些方法来获取到配置、项目上下文等信息。
12
12
 
13
13
  ```ts
14
- export default (): CliPlugin<ModuleTools> => ({
14
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
15
15
  name: 'my-plugin',
16
16
 
17
17
  setup(api) {
@@ -79,7 +79,7 @@ interface NormalizedConfig {
79
79
  ```ts
80
80
  import type { CliPlugin } from '@modern-js/core';
81
81
 
82
- export default (): CliPlugin => ({
82
+ export const myPlugin = (): CliPlugin => ({
83
83
  name: 'my-plugin',
84
84
 
85
85
  async setup(api) {
@@ -95,7 +95,7 @@ export default (): CliPlugin => ({
95
95
  CLI 插件的 setup 可以是一个异步函数,在初始化过程中执行异步逻辑。
96
96
 
97
97
  ```ts
98
- export default (): CliPlugin<ModuleTools> => ({
98
+ export const myPlugin = (): CliPlugin<ModuleTools> => ({
99
99
  name: 'my-plugin',
100
100
 
101
101
  async setup(api) {
@@ -24,7 +24,7 @@ pnpm add @modern-js/plugin-module-babel -D
24
24
  在 Module Tools 中,你可以按照如下方式注册插件:
25
25
 
26
26
  ```ts
27
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
27
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
28
28
  import { modulePluginBabel } from '@modern-js/plugin-module-babel';
29
29
 
30
30
  export default defineConfig({
@@ -42,7 +42,7 @@ See [Babel options](https://babeljs.io/docs/options)
42
42
  下面是一个配置了`@babel/preset-env`的例子:
43
43
 
44
44
  ```ts
45
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
45
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
46
46
  import { modulePluginBabel } from '@modern-js/plugin-module-babel';
47
47
 
48
48
  export default defineConfig({
@@ -22,7 +22,7 @@ pnpm add @modern-js/plugin-module-banner -D
22
22
  在 Module Tools 中,你可以按照如下方式注册插件:
23
23
 
24
24
  ```ts
25
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
25
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
26
26
  import { modulePluginBanner } from '@modern-js/plugin-module-banner';
27
27
 
28
28
  export default defineConfig({
@@ -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
  ## 示例
@@ -48,7 +48,7 @@ export default defineConfig({
48
48
 
49
49
  ```ts
50
50
  import { modulePluginBanner } from '@modern-js/plugin-module-banner';
51
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
51
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
52
52
 
53
53
  const copyRight = `/*
54
54
  © Copyright 2020 xxx.com or one of its affiliates.
@@ -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
 
@@ -27,17 +27,19 @@ pnpm add @modern-js/plugin-module-import -D
27
27
  在 Module Tools 中,你可以按照如下方式注册插件:
28
28
 
29
29
  ```ts
30
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
30
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
31
31
  import { modulePluginImport } from '@modern-js/plugin-module-import';
32
32
 
33
33
  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
 
@@ -65,7 +67,7 @@ type Options = {
65
67
 
66
68
  ```ts
67
69
  import { modulePluginImport } from '@modern-js/plugin-module-import';
68
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
70
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
69
71
 
70
72
  export default defineConfig({
71
73
  plugins: [
@@ -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
  ],
@@ -111,16 +113,18 @@ import { MyButton as Btn } from 'foo';
111
113
 
112
114
  ```ts
113
115
  import { modulePluginImport } from '@modern-js/plugin-module-import';
114
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
116
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
115
117
 
116
118
  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
  });
@@ -132,22 +136,25 @@ export default defineConfig({
132
136
 
133
137
  ```ts focus=8:8
134
138
  import { modulePluginImport } from '@modern-js/plugin-module-import';
135
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
139
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
136
140
 
137
141
  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
@@ -162,16 +169,18 @@ import Btn from 'foo/es/MyButton';
162
169
 
163
170
  ```ts focus=8:8
164
171
  import { modulePluginImport } from '@modern-js/plugin-module-import';
165
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
172
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
166
173
 
167
174
  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
  });
@@ -26,7 +26,7 @@ pnpm add @modern-js/plugin-module-node-polyfill -D
26
26
  在 Module Tools 中,你可以按照如下方式注册插件:
27
27
 
28
28
  ```ts
29
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
29
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
30
30
  import { modulePluginNodePolyfill } from '@modern-js/plugin-module-node-polyfill';
31
31
 
32
32
  export default defineConfig({
@@ -53,7 +53,7 @@ type NodePolyfillOptions = {
53
53
  排除要注入的 Node Polyfill。
54
54
 
55
55
  ``` ts focus=7:9
56
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
56
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
57
57
  import { modulePluginNodePolyfill } from '@modern-js/plugin-module-node-polyfill';
58
58
 
59
59
  export default defineConfig({
@@ -71,7 +71,7 @@ export default defineConfig({
71
71
  覆盖内置的 Node Polyfill。
72
72
 
73
73
  ``` ts focus=7:9
74
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
74
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
75
75
  import { modulePluginNodePolyfill } from '@modern-js/plugin-module-node-polyfill';
76
76
 
77
77
  export default defineConfig({
@@ -27,7 +27,7 @@ pnpm add @modern-js/plugin-module-polyfill -D
27
27
  在 Module Tools 中,你可以按照如下方式注册插件:
28
28
 
29
29
  ```ts
30
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
30
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
31
31
  import { modulePluginPolyfill } from '@modern-js/plugin-module-polyfill';
32
32
 
33
33
  export default defineConfig({
@@ -55,7 +55,7 @@ type options = {
55
55
  下面是一个例子:
56
56
 
57
57
  ```ts
58
- import moduleTools, { defineConfig } from '@modern-js/module-tools';
58
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
59
59
  import { modulePluginPolyfill } from '@modern-js/plugin-module-polyfill';
60
60
 
61
61
  export default defineConfig({
package/modern.config.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import path from 'path';
2
- import docTools, { defineConfig, NavItem } from '@modern-js/doc-tools';
2
+ import { docTools, defineConfig, NavItem } from '@modern-js/doc-tools';
3
3
  import { remarkCodeHike } from '@code-hike/mdx';
4
4
  import { pluginAutoSidebar } from '@modern-js/doc-plugin-auto-sidebar';
5
5
 
package/package.json CHANGED
@@ -9,15 +9,15 @@
9
9
  "directory": "packages/document/module-doc"
10
10
  },
11
11
  "license": "MIT",
12
- "version": "2.24.1",
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-tools": "2.24.1",
20
- "@modern-js/doc-plugin-auto-sidebar": "2.24.1"
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",