@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.
- package/CHANGELOG.md +7 -0
- package/docs/en/api/config/build-config.mdx +49 -49
- package/docs/en/api/config/build-preset.mdx +15 -33
- package/docs/en/api/config/design-system.md +42 -34
- package/docs/en/api/config/plugins.md +3 -3
- package/docs/en/api/config/testing.md +2 -2
- package/docs/en/api/plugin-api/plugin-hooks.md +24 -24
- package/docs/en/components/register-esbuild-plugin.mdx +2 -2
- package/docs/en/guide/advance/asset.mdx +8 -27
- package/docs/en/guide/advance/build-umd.mdx +18 -66
- package/docs/en/guide/advance/external-dependency.mdx +7 -27
- package/docs/en/guide/advance/in-depth-about-build.md +4 -4
- package/docs/en/guide/advance/in-depth-about-dev-command.md +2 -2
- package/docs/en/guide/advance/theme-config.mdx +4 -8
- package/docs/en/guide/basic/before-getting-started.md +1 -1
- package/docs/en/guide/basic/publish-your-project.md +8 -7
- package/docs/en/guide/basic/test-your-project.mdx +10 -47
- package/docs/en/guide/basic/use-micro-generator.md +4 -4
- package/docs/en/guide/basic/using-storybook.mdx +12 -44
- package/docs/en/guide/best-practices/components.mdx +44 -402
- package/docs/en/guide/faq/build.mdx +16 -0
- package/docs/en/guide/intro/getting-started.md +2 -2
- package/docs/en/plugins/guide/getting-started.mdx +8 -24
- package/docs/en/plugins/guide/plugin-object.mdx +2 -8
- package/docs/en/plugins/official-list/plugin-import.mdx +9 -52
- package/docs/en/plugins/official-list/plugin-node-polyfill.md +2 -2
- package/docs/zh/api/config/build-config.mdx +52 -52
- package/docs/zh/api/config/build-preset.mdx +12 -30
- package/docs/zh/api/config/design-system.md +6 -6
- package/docs/zh/api/config/plugins.md +3 -3
- package/docs/zh/api/config/testing.md +2 -2
- package/docs/zh/components/register-esbuild-plugin.mdx +2 -2
- package/docs/zh/guide/advance/asset.mdx +9 -30
- package/docs/zh/guide/advance/build-umd.mdx +19 -67
- package/docs/zh/guide/advance/external-dependency.mdx +8 -28
- package/docs/zh/guide/advance/in-depth-about-build.md +4 -4
- package/docs/zh/guide/advance/in-depth-about-dev-command.md +2 -2
- package/docs/zh/guide/advance/theme-config.mdx +4 -8
- package/docs/zh/guide/basic/publish-your-project.md +2 -2
- package/docs/zh/guide/basic/test-your-project.mdx +11 -49
- package/docs/zh/guide/basic/use-micro-generator.md +4 -4
- package/docs/zh/guide/basic/using-storybook.mdx +13 -45
- package/docs/zh/guide/best-practices/components.mdx +50 -410
- package/docs/zh/guide/faq/build.mdx +16 -0
- package/docs/zh/guide/intro/getting-started.md +1 -1
- package/docs/zh/plugins/guide/getting-started.mdx +8 -24
- package/docs/zh/plugins/guide/plugin-object.mdx +2 -8
- package/docs/zh/plugins/official-list/plugin-import.mdx +10 -55
- package/docs/zh/plugins/official-list/plugin-node-polyfill.md +2 -2
- package/modern.config.ts +1 -12
- package/package.json +3 -5
- package/theme/index.ts +0 -2
- package/theme/index.css +0 -9
|
@@ -8,9 +8,9 @@ sidebar_position: 1
|
|
|
8
8
|
|
|
9
9
|
我们可以通过下面的例子来快速了解如何编写一个 Module Tools 插件:
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
1. 首先我们在初始化的项目下创建 `./plugins/example.ts` 文件。
|
|
12
12
|
|
|
13
|
-
```md ./project
|
|
13
|
+
```md title="./project"
|
|
14
14
|
./
|
|
15
15
|
├── plugins
|
|
16
16
|
│ └── example.ts
|
|
@@ -18,17 +18,7 @@ sidebar_position: 1
|
|
|
18
18
|
└── modern.config.ts
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
首先我们在初始化的项目下创建 `./plugins/example.ts` 文件。
|
|
24
|
-
|
|
25
|
-
```md ./project
|
|
26
|
-
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
---
|
|
30
|
-
|
|
31
|
-
接着在 `example.ts` 文件中增加插件的代码。
|
|
21
|
+
2. 接着在 `example.ts` 文件中增加插件的代码。
|
|
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
|
-
然后我们通过 [`plugins`](/api/config/plugins) API,将刚刚写好的插件进行注册。
|
|
42
|
+
3. 然后我们通过 [`plugins`](/api/config/plugins) API,将刚刚写好的插件进行注册。
|
|
55
43
|
|
|
56
|
-
```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
|
-
最后运行 `modern build`,就可以看到。
|
|
51
|
+
4. 最后运行 `modern build`,就可以看到:
|
|
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
|
通过上面这个例子,我们了解到了下面几件事:
|
|
76
60
|
|
|
77
61
|
- 推荐的插件目录结构
|
|
@@ -11,9 +11,7 @@ Module-tools 插件是一个对象,对象包含以下属性:
|
|
|
11
11
|
|
|
12
12
|
例如在下面的插件代码示例中,在项目开始执行构建任务之前会触发 `beforeBuild` 函数的执行,并打印 `build start` 的 log 内容。
|
|
13
13
|
|
|
14
|
-
|
|
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
|
## 插件类型定义
|
|
45
39
|
|
|
46
40
|
使用 TypeScript 时,可以引入内置的 `CliPlugin` 和 `ModuleTools` 类型,为插件提供正确的类型推导:
|
|
@@ -93,81 +93,36 @@ export default defineConfig({
|
|
|
93
93
|
|
|
94
94
|
简单的函数逻辑其实可以通过模版语言来代替,因此 `customName`,`customStyleName` 等这些配置除了可以传入函数,也可以传入字符串作为模版来代替函数,提高性能。
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
我们以这段代码作为示例:
|
|
97
97
|
|
|
98
98
|
```ts
|
|
99
99
|
import { MyButton as Btn } from 'foo';
|
|
100
100
|
```
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
我们以这段代码进行说明。
|
|
102
|
+
添加以下配置:
|
|
105
103
|
|
|
106
104
|
```ts
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
```ts
|
|
115
|
-
import { modulePluginImport } from '@modern-js/plugin-module-import';
|
|
116
|
-
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
117
|
-
|
|
118
|
-
export default defineConfig({
|
|
119
|
-
plugins: [
|
|
120
|
-
moduleTools(),
|
|
121
|
-
modulePluginImport({
|
|
122
|
-
pluginImport: [
|
|
123
|
-
{
|
|
124
|
-
libraryName: 'foo',
|
|
125
|
-
customName: 'foo/es/{{ member }}',
|
|
126
|
-
},
|
|
127
|
-
],
|
|
128
|
-
}),
|
|
129
|
-
],
|
|
130
|
-
});
|
|
131
|
-
```
|
|
132
|
-
|
|
133
|
-
---
|
|
134
|
-
|
|
135
|
-
其中的 `{{ member }}` 会被替换为相应的引入成员
|
|
136
|
-
|
|
137
|
-
```ts focus=8:8
|
|
138
|
-
import { modulePluginImport } from '@modern-js/plugin-module-import';
|
|
139
|
-
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
140
|
-
|
|
141
|
-
export default defineConfig({
|
|
142
|
-
plugins: [
|
|
143
|
-
moduleTools(),
|
|
144
|
-
modulePluginImport({
|
|
145
|
-
pluginImport: [
|
|
146
|
-
{
|
|
147
|
-
libraryName: 'foo',
|
|
148
|
-
customName: 'foo/es/{{ member }}',
|
|
149
|
-
},
|
|
150
|
-
],
|
|
151
|
-
}),
|
|
105
|
+
modulePluginImport({
|
|
106
|
+
pluginImport: [
|
|
107
|
+
{
|
|
108
|
+
libraryName: 'foo',
|
|
109
|
+
customName: 'foo/es/{{ member }}',
|
|
110
|
+
},
|
|
152
111
|
],
|
|
153
112
|
});
|
|
154
113
|
```
|
|
155
114
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
转换后:
|
|
115
|
+
其中的 `{{ member }}` 会被替换为相应的引入成员,转换后:
|
|
159
116
|
|
|
160
117
|
```ts
|
|
161
118
|
import Btn from 'foo/es/MyButton';
|
|
162
119
|
```
|
|
163
120
|
|
|
164
|
-
</CH.Spotlight>
|
|
165
|
-
|
|
166
121
|
可以看出配置 `customName: "foo/es/{{ member }}"` 的效果等同于配置 `` customName: (member) => `foo/es/${member}` `` ,但是不会有 Node-API 的调用开销。
|
|
167
122
|
|
|
168
123
|
这里使用到的模版是 [handlebars](https://handlebarsjs.com),模版配置中还内置了一些有用的辅助工具,还是以上面的导入语句为例,配置成:
|
|
169
124
|
|
|
170
|
-
```ts
|
|
125
|
+
```ts
|
|
171
126
|
import { modulePluginImport } from '@modern-js/plugin-module-import';
|
|
172
127
|
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
173
128
|
|
|
@@ -52,7 +52,7 @@ type NodePolyfillOptions = {
|
|
|
52
52
|
|
|
53
53
|
排除要注入的 Node Polyfill。
|
|
54
54
|
|
|
55
|
-
```
|
|
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
|
覆盖内置的 Node Polyfill。
|
|
72
72
|
|
|
73
|
-
```
|
|
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
|
|
package/modern.config.ts
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import path from 'path';
|
|
2
2
|
import { docTools, defineConfig, NavItem } from '@modern-js/doc-tools';
|
|
3
|
-
import { remarkCodeHike } from '@code-hike/mdx';
|
|
4
3
|
import { pluginAutoSidebar } from '@modern-js/doc-plugin-auto-sidebar';
|
|
5
4
|
|
|
6
|
-
const theme = require('shiki/themes/nord.json');
|
|
7
5
|
const { version } = require('./package.json');
|
|
8
6
|
|
|
9
7
|
function getI18nHelper(lang: 'zh' | 'en') {
|
|
@@ -71,16 +69,7 @@ export default defineConfig({
|
|
|
71
69
|
],
|
|
72
70
|
markdown: {
|
|
73
71
|
checkDeadLinks: true,
|
|
74
|
-
|
|
75
|
-
[
|
|
76
|
-
remarkCodeHike,
|
|
77
|
-
{
|
|
78
|
-
theme,
|
|
79
|
-
autoImport: true,
|
|
80
|
-
showCopyButton: true,
|
|
81
|
-
},
|
|
82
|
-
],
|
|
83
|
-
],
|
|
72
|
+
experimentalMdxRs: true,
|
|
84
73
|
},
|
|
85
74
|
themeConfig: {
|
|
86
75
|
footer: {
|
package/package.json
CHANGED
|
@@ -9,15 +9,13 @@
|
|
|
9
9
|
"directory": "packages/document/module-doc"
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "2.
|
|
12
|
+
"version": "2.31.0",
|
|
13
13
|
"main": "index.js",
|
|
14
14
|
"dependencies": {
|
|
15
|
-
"@code-hike/mdx": "^0.7.4",
|
|
16
15
|
"react": "^18.2.0",
|
|
17
16
|
"react-dom": "^18.2.0",
|
|
18
|
-
"
|
|
19
|
-
"@modern-js/doc-plugin-auto-sidebar": "2.
|
|
20
|
-
"@modern-js/doc-tools": "2.30.0"
|
|
17
|
+
"@modern-js/doc-tools": "2.31.0",
|
|
18
|
+
"@modern-js/doc-plugin-auto-sidebar": "2.31.0"
|
|
21
19
|
},
|
|
22
20
|
"scripts": {
|
|
23
21
|
"dev": "modern dev",
|
package/theme/index.ts
CHANGED