@modern-js/module-tools-docs 2.29.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 +15 -0
  2. package/docs/en/api/config/build-config.mdx +80 -53
  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 +21 -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 +83 -56
  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 +20 -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
@@ -6,7 +6,7 @@ sidebar_position: 3
6
6
 
7
7
  ## 3 minute demo
8
8
 
9
- Want to experience Module Tools in action? The only prerequisite you need is [Node.js LTS](https://github.com/nodejs/Release) and make sure your Node version is **>= 14.18.0**.We recommend using the LTS version of Node.js 16.
9
+ Want to experience Module Tools in action? The only prerequisite you need is [Node.js LTS](https://github.com/nodejs/Release) and make sure your Node version is **>= 14.18.0**.We recommend using the LTS version of Node.js 18.
10
10
 
11
11
  ### Create new project
12
12
 
@@ -53,7 +53,7 @@ npm install -D @modern-js/module-tools typescript
53
53
 
54
54
  Next, create the `modern.config.(t|j)s` file in the root of the project.
55
55
 
56
- ``` ts
56
+ ```ts
57
57
  import { moduleTools, defineConfig } from '@modern-js/module-tools';
58
58
 
59
59
  export default defineConfig({
@@ -73,6 +73,25 @@ Finally, add the command `"build": "modern build"` to the project's `package.jso
73
73
 
74
74
  If your project has a `src/index.(js|jsx)` file or both `src/index.(ts|tsx)` and `tsconfig.json` files, then congratulations you can run the `npm run build` command directly to build your project with Module Tools.
75
75
 
76
+ ### Core npm Package
77
+
78
+ `@modern-js/module-tools` is the core npm package of Module Tools, providing the following capabilities:
79
+
80
+ - It offers commonly used CLI commands such as `modern dev`, `modern build`, and more.
81
+ - It integrates Modern.js Core, providing capabilities for configuration parsing, plugin loading, and more.
82
+ - It integrates esbuild and SWC, providing build capabilities.
83
+ - It integrates some commonly used plugins, such as `plugin-lint`, `plugin-changeset`, and others.
84
+
85
+ `@modern-js/module-tools` is implemented based on the plugin system of Modern.js. Essentially, it is a plugin. Therefore, you need to register `moduleTools` in the `plugins` field of the configuration file:
86
+
87
+ ```ts title="modern.config.ts"
88
+ import { moduleTools, defineConfig } from '@modern-js/module-tools';
89
+
90
+ export default defineConfig({
91
+ plugins: [moduleTools()],
92
+ });
93
+ ```
94
+
76
95
  ### View official example
77
96
 
78
97
  **If you want to see the complete project using the modular engineering scheme, you can execute the following command**.
@@ -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