@modern-js/module-tools-docs 2.0.0-beta.4 → 2.0.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.
- package/.eslintrc.js +13 -0
- package/docs/en/api/config/_category_.json +4 -0
- package/docs/en/api/{build-config.md → config/build-config.md} +198 -105
- package/docs/en/api/{build-preset.md → config/build-preset.md} +65 -46
- package/docs/{zh/api → en/api/config}/design-system.md +130 -127
- package/docs/en/api/config/plugins.md +18 -0
- package/docs/en/api/{test.md → config/testing.md} +21 -12
- package/docs/en/api/index.md +3 -1
- package/docs/en/api/plugin-api/_category_.json +4 -0
- package/docs/en/api/plugin-api/plugin-hooks.md +501 -0
- package/docs/en/guide/advance/_category_.json +4 -0
- package/docs/en/guide/advance/asset.mdx +47 -30
- package/docs/en/guide/advance/build-umd.mdx +88 -80
- package/docs/en/guide/advance/copy.md +31 -28
- package/docs/en/guide/advance/external-dependency.mdx +27 -23
- package/docs/en/guide/advance/in-depth-about-build.md +56 -50
- package/docs/en/guide/advance/in-depth-about-dev-command.md +7 -4
- package/docs/en/guide/advance/theme-config.mdx +80 -0
- package/docs/en/guide/basic/_category_.json +4 -0
- package/docs/en/guide/basic/before-getting-started.md +28 -23
- package/docs/en/guide/basic/command-preview.md +18 -14
- package/docs/en/guide/basic/modify-output-product.md +27 -20
- package/docs/en/guide/basic/publish-your-project.md +21 -19
- package/docs/en/guide/basic/test-your-project.mdx +19 -16
- package/docs/en/guide/basic/use-micro-generator.md +10 -7
- package/docs/en/guide/basic/using-storybook.mdx +27 -26
- package/docs/en/guide/best-practices/_category_.json +4 -0
- package/docs/en/guide/best-practices/components.mdx +783 -0
- package/docs/en/guide/intro/_category_.json +4 -0
- package/docs/en/guide/intro/getting-started.md +9 -4
- package/docs/en/guide/intro/welcome.md +4 -0
- package/docs/en/guide/intro/why-module-engineering-solution.md +5 -1
- package/docs/en/index.md +3 -5
- package/docs/en/plugins/guide/_category_.json +4 -0
- package/docs/en/plugins/guide/getting-started.mdx +84 -0
- package/docs/en/plugins/guide/plugin-object.mdx +85 -0
- package/docs/en/plugins/guide/setup-function.mdx +117 -0
- package/docs/en/plugins/official-list/_category_.json +4 -0
- package/docs/en/plugins/official-list/overview.md +6 -0
- package/docs/zh/api/config/_category_.json +4 -0
- package/docs/zh/api/config/build-config.md +658 -0
- package/docs/zh/api/{build-preset.md → config/build-preset.md} +49 -36
- package/docs/zh/api/config/design-system.md +1166 -0
- package/docs/zh/api/config/plugins.md +18 -0
- package/docs/zh/api/{testing.md → config/testing.md} +18 -13
- package/docs/zh/api/index.md +4 -1
- package/docs/zh/api/plugin-api/_category_.json +4 -0
- package/docs/zh/api/plugin-api/plugin-hooks.md +500 -0
- package/docs/zh/guide/advance/_category_.json +4 -0
- package/docs/zh/guide/advance/asset.mdx +47 -30
- package/docs/zh/guide/advance/build-umd.mdx +88 -71
- package/docs/zh/guide/advance/copy.md +31 -28
- package/docs/zh/guide/advance/external-dependency.mdx +27 -23
- package/docs/zh/guide/advance/in-depth-about-build.md +55 -50
- package/docs/zh/guide/advance/in-depth-about-dev-command.md +7 -4
- package/docs/zh/guide/advance/theme-config.mdx +78 -0
- package/docs/zh/guide/basic/_category_.json +4 -0
- package/docs/zh/guide/basic/before-getting-started.md +27 -22
- package/docs/zh/guide/basic/command-preview.md +17 -13
- package/docs/zh/guide/basic/modify-output-product.md +28 -21
- package/docs/zh/guide/basic/publish-your-project.md +22 -17
- package/docs/zh/guide/basic/test-your-project.mdx +20 -16
- package/docs/zh/guide/basic/use-micro-generator.md +10 -7
- package/docs/zh/guide/basic/using-storybook.mdx +27 -24
- package/docs/zh/guide/best-practices/_category_.json +4 -0
- package/docs/zh/guide/best-practices/components.mdx +793 -0
- package/docs/zh/guide/intro/_category_.json +4 -0
- package/docs/zh/guide/intro/getting-started.md +10 -4
- package/docs/zh/guide/intro/welcome.md +4 -0
- package/docs/zh/guide/intro/why-module-engineering-solution.md +5 -1
- package/docs/zh/index.md +3 -2
- package/docs/zh/plugins/guide/_category_.json +4 -0
- package/docs/zh/plugins/guide/getting-started.mdx +84 -0
- package/docs/zh/plugins/guide/plugin-object.mdx +85 -0
- package/docs/zh/plugins/guide/setup-function.mdx +117 -0
- package/docs/zh/plugins/official-list/_category_.json +4 -0
- package/docs/zh/plugins/official-list/overview.md +5 -0
- package/modern.config.ts +118 -0
- package/package.json +8 -6
- package/{docs/.island/styles → theme}/index.css +0 -1
- package/theme/index.ts +4 -0
- package/tsconfig.json +7 -0
- package/docs/.island/config.ts +0 -245
- package/docs/.island/dist/404.html +0 -41
- package/docs/.island/dist/assets/before-getting-started.1b82b538.js +0 -87
- package/docs/.island/dist/assets/before-getting-started.582a31cc.js +0 -87
- package/docs/.island/dist/assets/build-config.72eb0918.js +0 -804
- package/docs/.island/dist/assets/build-config.d8bb1658.js +0 -809
- package/docs/.island/dist/assets/build-preset.96805d7d.js +0 -256
- package/docs/.island/dist/assets/build-preset.c20dcd40.js +0 -256
- package/docs/.island/dist/assets/build-your-ui.7f349247.js +0 -2
- package/docs/.island/dist/assets/build-your-ui.a8361604.js +0 -2
- package/docs/.island/dist/assets/command-preview.2d45fc82.js +0 -264
- package/docs/.island/dist/assets/command-preview.dc51b953.js +0 -264
- package/docs/.island/dist/assets/components.esm.03560353.js +0 -9
- package/docs/.island/dist/assets/design-system.86694ff5.js +0 -1254
- package/docs/.island/dist/assets/design-system.c4745cce.js +0 -639
- package/docs/.island/dist/assets/dev.1d326a37.js +0 -37
- package/docs/.island/dist/assets/dev.1fd06000.js +0 -37
- package/docs/.island/dist/assets/down.f35427d3.svg +0 -1
- package/docs/.island/dist/assets/extension.12299fd6.js +0 -2
- package/docs/.island/dist/assets/extension.96dc63a4.js +0 -2
- package/docs/.island/dist/assets/getting-started.40e9218d.js +0 -117
- package/docs/.island/dist/assets/getting-started.b1ed3f10.js +0 -114
- package/docs/.island/dist/assets/github.3bf8ccee.svg +0 -1
- package/docs/.island/dist/assets/index.2b2347ea.js +0 -33
- package/docs/.island/dist/assets/index.6cef6f5f.js +0 -4
- package/docs/.island/dist/assets/index.cb118238.js +0 -36
- package/docs/.island/dist/assets/index.ccb6ce27.js +0 -4
- package/docs/.island/dist/assets/island_inject.11a12ecc.js +0 -1
- package/docs/.island/dist/assets/island_inject.b13deaee.js +0 -1
- package/docs/.island/dist/assets/loading.8c9bb911.svg +0 -1
- package/docs/.island/dist/assets/modify-output-product.7f6bff35.js +0 -100
- package/docs/.island/dist/assets/modify-output-product.b91eff1f.js +0 -100
- package/docs/.island/dist/assets/moon.6b705924.svg +0 -3
- package/docs/.island/dist/assets/plugin.895932d8.js +0 -42
- package/docs/.island/dist/assets/plugin.d2fbc531.js +0 -42
- package/docs/.island/dist/assets/publish-your-project.21b8309f.js +0 -164
- package/docs/.island/dist/assets/publish-your-project.8d398b17.js +0 -166
- package/docs/.island/dist/assets/right.89674cd7.svg +0 -1
- package/docs/.island/dist/assets/search.0aea6901.svg +0 -1
- package/docs/.island/dist/assets/search.1c85d17c.js +0 -3
- package/docs/.island/dist/assets/search.484eca11.js +0 -222
- package/docs/.island/dist/assets/search.54fca8d0.js +0 -3
- package/docs/.island/dist/assets/style.09015a4b.css +0 -1
- package/docs/.island/dist/assets/style.2e5f7bc2.css +0 -1970
- package/docs/.island/dist/assets/sun.841dac10.svg +0 -11
- package/docs/.island/dist/assets/test-your-project.18bd4582.js +0 -190
- package/docs/.island/dist/assets/test-your-project.f53bebf7.js +0 -190
- package/docs/.island/dist/assets/test.0da1f99f.js +0 -67
- package/docs/.island/dist/assets/test.0e81f002.js +0 -66
- package/docs/.island/dist/assets/translator.b1077c44.svg +0 -1
- package/docs/.island/dist/assets/use-micro-generator.7d9e4016.js +0 -60
- package/docs/.island/dist/assets/use-micro-generator.db5520c1.js +0 -60
- package/docs/.island/dist/assets/using-storybook.57ea6b77.js +0 -260
- package/docs/.island/dist/assets/using-storybook.a2212f2e.js +0 -260
- package/docs/.island/dist/assets/welcome.0449a9c8.js +0 -13
- package/docs/.island/dist/assets/welcome.a8448931.js +0 -13
- package/docs/.island/dist/assets/why-module-engineering-solution.6ae8c0e3.js +0 -26
- package/docs/.island/dist/assets/why-module-engineering-solution.c9a45cbd.js +0 -26
- package/docs/.island/dist/chunk-COLCRJ2V.js +0 -1
- package/docs/.island/dist/chunk-K5FMOYDC.js +0 -10
- package/docs/.island/dist/chunk-WE42KMYS.js +0 -26
- package/docs/.island/dist/client-entry.js +0 -3
- package/docs/.island/dist/en/api/build-config.html +0 -344
- package/docs/.island/dist/en/api/build-preset.html +0 -82
- package/docs/.island/dist/en/api/design-system.html +0 -155
- package/docs/.island/dist/en/api/dev.html +0 -45
- package/docs/.island/dist/en/api/index.html +0 -41
- package/docs/.island/dist/en/api/plugin.html +0 -48
- package/docs/.island/dist/en/api/test.html +0 -58
- package/docs/.island/dist/en/guide/before-getting-started.html +0 -127
- package/docs/.island/dist/en/guide/build-your-ui.html +0 -41
- package/docs/.island/dist/en/guide/command-preview.html +0 -100
- package/docs/.island/dist/en/guide/extension.html +0 -41
- package/docs/.island/dist/en/guide/getting-started.html +0 -76
- package/docs/.island/dist/en/guide/modify-output-product.html +0 -140
- package/docs/.island/dist/en/guide/publish-your-project.html +0 -91
- package/docs/.island/dist/en/guide/test-your-project.html +0 -72
- package/docs/.island/dist/en/guide/use-micro-generator.html +0 -65
- package/docs/.island/dist/en/guide/using-storybook.html +0 -113
- package/docs/.island/dist/en/guide/welcome.html +0 -53
- package/docs/.island/dist/en/guide/why-module-engineering-solution.html +0 -49
- package/docs/.island/dist/en/index.html +0 -42
- package/docs/.island/dist/react-dom.js +0 -1
- package/docs/.island/dist/react-dom_client.js +0 -1
- package/docs/.island/dist/react.js +0 -1
- package/docs/.island/dist/react_jsx-runtime.js +0 -10
- package/docs/.island/dist/ssr-manifest.json +0 -57
- package/docs/.island/dist/test-result.png +0 -0
- package/docs/.island/dist/why-module-solution.png +0 -0
- package/docs/.island/dist/zh/api/build-config.html +0 -347
- package/docs/.island/dist/zh/api/build-preset.html +0 -82
- package/docs/.island/dist/zh/api/design-system.html +0 -149
- package/docs/.island/dist/zh/api/dev.html +0 -46
- package/docs/.island/dist/zh/api/index.html +0 -41
- package/docs/.island/dist/zh/api/plugin.html +0 -48
- package/docs/.island/dist/zh/api/test.html +0 -59
- package/docs/.island/dist/zh/guide/before-getting-started.html +0 -127
- package/docs/.island/dist/zh/guide/build-your-ui.html +0 -41
- package/docs/.island/dist/zh/guide/command-preview.html +0 -100
- package/docs/.island/dist/zh/guide/extension.html +0 -41
- package/docs/.island/dist/zh/guide/getting-started.html +0 -79
- package/docs/.island/dist/zh/guide/modify-output-product.html +0 -140
- package/docs/.island/dist/zh/guide/publish-your-project.html +0 -92
- package/docs/.island/dist/zh/guide/test-your-project.html +0 -72
- package/docs/.island/dist/zh/guide/use-micro-generator.html +0 -65
- package/docs/.island/dist/zh/guide/using-storybook.html +0 -114
- package/docs/.island/dist/zh/guide/welcome.html +0 -53
- package/docs/.island/dist/zh/guide/why-module-engineering-solution.html +0 -49
- package/docs/.island/dist/zh/index.html +0 -42
- package/docs/.island/index.html +0 -39
- package/docs/en/api/design-system.md +0 -524
- package/docs/en/api/dev.md +0 -32
- package/docs/en/api/plugin.md +0 -34
- package/docs/zh/api/build-config.md +0 -570
- package/docs/zh/api/dev.md +0 -33
- package/docs/zh/api/plugins.md +0 -108
|
@@ -1,570 +0,0 @@
|
|
|
1
|
-
# BuildConfig
|
|
2
|
-
本章节描述了Module tools关于构建的所有配置
|
|
3
|
-
## alias
|
|
4
|
-
- type: `Record<string, string | string[]> | Function`
|
|
5
|
-
- default: `{'@': 'src',}`
|
|
6
|
-
|
|
7
|
-
:::tip
|
|
8
|
-
对于 TypeScript 项目,只需要在 `tsconfig.json` 中配置 [compilerOptions.paths](https://www.typescriptlang.org/tsconfig#paths), Module tools会自动识别 `tsconfig.json` 里的别名,因此不需要额外配置 `alias` 字段。
|
|
9
|
-
:::
|
|
10
|
-
|
|
11
|
-
```ts modern.config.ts
|
|
12
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
13
|
-
|
|
14
|
-
export default defineConfig({
|
|
15
|
-
buildConfig: {
|
|
16
|
-
alias: {
|
|
17
|
-
'@common': './src/common',
|
|
18
|
-
},
|
|
19
|
-
},
|
|
20
|
-
});
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
以上配置完成后,如果在代码中引用 `@common/Foo.tsx`, 则会映射到 `<root>/src/common/Foo.tsx` 路径上。
|
|
24
|
-
|
|
25
|
-
`alias` 的值定义为函数时,可以接受预设的 alias 对象,并对其进行修改。
|
|
26
|
-
|
|
27
|
-
```ts modern.config.ts
|
|
28
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
29
|
-
|
|
30
|
-
export default defineConfig({
|
|
31
|
-
buildConfig: {
|
|
32
|
-
alias: alias => {
|
|
33
|
-
alias['@common'] = './src/common';
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
});
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
也可以在函数中返回一个新对象作为最终结果,新对象会覆盖预设的 alias 对象。
|
|
40
|
-
|
|
41
|
-
```ts modern.config.ts
|
|
42
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
43
|
-
|
|
44
|
-
export default defineConfig({
|
|
45
|
-
buildConfig: {
|
|
46
|
-
alias: alias => {
|
|
47
|
-
return {
|
|
48
|
-
'@common': './src/common',
|
|
49
|
-
};
|
|
50
|
-
},
|
|
51
|
-
},
|
|
52
|
-
});
|
|
53
|
-
```
|
|
54
|
-
|
|
55
|
-
## asset
|
|
56
|
-
|
|
57
|
-
### path
|
|
58
|
-
静态资源输出路径,会基于[outdir](/zh/api/build-config/#outdir)进行输出
|
|
59
|
-
|
|
60
|
-
- type: `string`
|
|
61
|
-
- default: `assets`
|
|
62
|
-
|
|
63
|
-
### limit
|
|
64
|
-
打包时自动内联静态资源的阈值,小于 10240 字节的资源会被自动内联进bundle产物中
|
|
65
|
-
|
|
66
|
-
- type: `number`
|
|
67
|
-
- default: `10 * 1024`
|
|
68
|
-
|
|
69
|
-
### publicPath
|
|
70
|
-
打包时给未内联资源的CDN前缀
|
|
71
|
-
- type: `string`
|
|
72
|
-
- default: `undefined`
|
|
73
|
-
```ts modern.config.ts
|
|
74
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
75
|
-
|
|
76
|
-
export default defineConfig({
|
|
77
|
-
buildConfig: {
|
|
78
|
-
asset: {
|
|
79
|
-
publicPath: 'https://xxx/'
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
});
|
|
83
|
-
```
|
|
84
|
-
此时,所有静态资源都会添加`https://xxx/`前缀
|
|
85
|
-
|
|
86
|
-
### svgr
|
|
87
|
-
打包时将svg作为一个React组件处理,options参考[svgr](https://react-svgr.com/docs/options/),另外还支持了`include`和`exclude`两个配置项,用于匹配需要处理的svg文件
|
|
88
|
-
- type: `boolean | Object`
|
|
89
|
-
- default: `true`
|
|
90
|
-
|
|
91
|
-
#### include
|
|
92
|
-
设定匹配的svg文件
|
|
93
|
-
- type: `string | RegExp | (string | RegExp)[]`
|
|
94
|
-
- default: `/\.svg$/`
|
|
95
|
-
|
|
96
|
-
#### exclude
|
|
97
|
-
设定不匹配的svg文件
|
|
98
|
-
- type: `string | RegExp | (string | RegExp)[]`
|
|
99
|
-
- default: `undefined`
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
## autoExternal
|
|
103
|
-
自动外置项目的dependencies和peerDependencies,不会将其打包到最终的bundle中
|
|
104
|
-
- type: `boolean | Object`
|
|
105
|
-
- default: `true`
|
|
106
|
-
|
|
107
|
-
### dependencies
|
|
108
|
-
是否需要外置项目的dep依赖
|
|
109
|
-
- type: `boolean`
|
|
110
|
-
- default: `true`
|
|
111
|
-
|
|
112
|
-
### peerDependencies
|
|
113
|
-
是否需要外置项目的peerDep依赖
|
|
114
|
-
- type: `boolean`
|
|
115
|
-
- default: `true`
|
|
116
|
-
|
|
117
|
-
## buildType
|
|
118
|
-
构建类型,`bundle`会打包你的代码,`bundleless`只做代码的转换
|
|
119
|
-
- type: `'bundle' | 'bundleless'`
|
|
120
|
-
- default: `bundle`
|
|
121
|
-
|
|
122
|
-
## copy
|
|
123
|
-
|
|
124
|
-
将文件或目录拷贝到指定位置。
|
|
125
|
-
|
|
126
|
-
- type: `Object`
|
|
127
|
-
```ts modern.config.ts
|
|
128
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
export default defineConfig({
|
|
132
|
-
buildConfig: {
|
|
133
|
-
copy: {
|
|
134
|
-
patterns: [{ from: './src/assets', to: '' }],
|
|
135
|
-
},
|
|
136
|
-
},
|
|
137
|
-
});
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
### `copy.patterns`
|
|
141
|
-
|
|
142
|
-
- type: `CopyPattern[]`
|
|
143
|
-
- default: `[]`
|
|
144
|
-
|
|
145
|
-
``` ts
|
|
146
|
-
export interface CopyPattern {
|
|
147
|
-
from: string;
|
|
148
|
-
to?: string;
|
|
149
|
-
context?: string;
|
|
150
|
-
globOptions?: globby.GlobbyOptions;
|
|
151
|
-
}
|
|
152
|
-
```
|
|
153
|
-
|
|
154
|
-
### copy.options
|
|
155
|
-
|
|
156
|
-
- type: `Object`
|
|
157
|
-
- default: `{ concurrency: 100, enableCopySync: false }`
|
|
158
|
-
|
|
159
|
-
``` ts
|
|
160
|
-
type Options = {
|
|
161
|
-
concurrency?: number;
|
|
162
|
-
enableCopySync?: boolean;
|
|
163
|
-
};
|
|
164
|
-
```
|
|
165
|
-
|
|
166
|
-
* `concurrency`: 指定并行执行多少个复制任务。
|
|
167
|
-
* `enableCopySync`: 使用 [`fs.copySync`](https://github.com/jprichardson/node-fs-extra/blob/master/lib/copy/copy-sync.js),默认情况下 [`fs.copy`](https://github.com/jprichardson/node-fs-extra/blob/master/lib/copy/copy.js)。
|
|
168
|
-
|
|
169
|
-
## define
|
|
170
|
-
定义全局变量,会被注入到代码中
|
|
171
|
-
- type: `Record<string, string>`
|
|
172
|
-
- default: `{}`
|
|
173
|
-
|
|
174
|
-
由于`define`功能是由全局文本替换实现的,所以需要保证全局变量值为字符串,更为安全的做法是将每个全局变量的值转化为字符串,使用`JSON.stringify`进行转换,如下所示:
|
|
175
|
-
```ts modern.config.ts
|
|
176
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
177
|
-
|
|
178
|
-
export default defineConfig({
|
|
179
|
-
buildConfig: {
|
|
180
|
-
define: {
|
|
181
|
-
'VERSION': JSON.stringify('1.0'),
|
|
182
|
-
|
|
183
|
-
},
|
|
184
|
-
},
|
|
185
|
-
});
|
|
186
|
-
```
|
|
187
|
-
|
|
188
|
-
:::tip
|
|
189
|
-
为了防止全局替换替换过度,建议使用时遵循以下两个原则:
|
|
190
|
-
- 全局常量使用大写
|
|
191
|
-
- 自定义全局常量前缀后缀,确保独一无二
|
|
192
|
-
:::
|
|
193
|
-
|
|
194
|
-
## dts
|
|
195
|
-
dts文件生成相关配置,默认会生成
|
|
196
|
-
|
|
197
|
-
- type: `false | Object`
|
|
198
|
-
- default: `{}`
|
|
199
|
-
|
|
200
|
-
### tsconfigPath
|
|
201
|
-
tsconfig文件的路径
|
|
202
|
-
- type: `string`
|
|
203
|
-
- default: `./tsconfig.json`
|
|
204
|
-
|
|
205
|
-
### distPath
|
|
206
|
-
dts文件的输出路径,基于[outdir]('/zh/api/build-config/#outdir')进行输出
|
|
207
|
-
- type: `string`
|
|
208
|
-
- default: `./types`
|
|
209
|
-
|
|
210
|
-
### only
|
|
211
|
-
只生成dts文件,不生成js文件
|
|
212
|
-
- type: `boolean`
|
|
213
|
-
- default: `false`
|
|
214
|
-
|
|
215
|
-
## externals
|
|
216
|
-
配置外部依赖,不会被打包到最终的bundle中
|
|
217
|
-
- type: `(string | RegExp)[]`
|
|
218
|
-
- default: `[]`
|
|
219
|
-
## format
|
|
220
|
-
js产物输出的格式,其中`iife`和`umd`只能在`buildType`为`bundle`时生效
|
|
221
|
-
- type: `'esm' | 'cjs' | 'iife' | 'umd'`
|
|
222
|
-
- default: `cjs`
|
|
223
|
-
|
|
224
|
-
## input
|
|
225
|
-
指定构建的入口文件,数组形式可以指定目录
|
|
226
|
-
- type: `string[] | Record<string, string>`
|
|
227
|
-
- default: `bundle`模式下默认为`['src/index.ts']`,`bundleless`模式下默认为`['src']`
|
|
228
|
-
|
|
229
|
-
```ts modern.config.ts
|
|
230
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
231
|
-
|
|
232
|
-
export default defineConfig({
|
|
233
|
-
buildConfig: {
|
|
234
|
-
input: ['src/index.ts', 'src/index2.ts'],
|
|
235
|
-
},
|
|
236
|
-
});
|
|
237
|
-
```
|
|
238
|
-
|
|
239
|
-
## jsx
|
|
240
|
-
指定jsx的编译方式, 默认支持React17以上,自动注入jsx运行时代码
|
|
241
|
-
- type: `automatic | classic`
|
|
242
|
-
- default: `automatic`
|
|
243
|
-
|
|
244
|
-
## minify
|
|
245
|
-
使用esbuild或者terser压缩代码,也可以传入[terserOptions](https://github.com/terser/terser#minify-options)
|
|
246
|
-
- type: `'terser' | 'esbuild' | false | Object`
|
|
247
|
-
- default: `false`
|
|
248
|
-
|
|
249
|
-
```ts modern.config.ts
|
|
250
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
251
|
-
|
|
252
|
-
export default defineConfig({
|
|
253
|
-
buildConfig: {
|
|
254
|
-
minify: {
|
|
255
|
-
compress: {
|
|
256
|
-
drop_console: true,
|
|
257
|
-
},
|
|
258
|
-
},
|
|
259
|
-
},
|
|
260
|
-
});
|
|
261
|
-
```
|
|
262
|
-
|
|
263
|
-
## outdir
|
|
264
|
-
指定构建的输出目录
|
|
265
|
-
- type: `string`
|
|
266
|
-
- default: `dist`
|
|
267
|
-
|
|
268
|
-
## platform
|
|
269
|
-
默认生成用于node环境下的代码,你也可以指定为`browser`,会生成用于浏览器环境的代码
|
|
270
|
-
- type: `'browser' | 'node'`
|
|
271
|
-
- default: `node`
|
|
272
|
-
|
|
273
|
-
## sourceDir
|
|
274
|
-
指定构建的源码目录,默认为`src`,用于在`bundleless`构建时基于源码目录结构生成对应的产物目录
|
|
275
|
-
- type: `string`
|
|
276
|
-
- default: `src`
|
|
277
|
-
|
|
278
|
-
## sourceMap
|
|
279
|
-
是否生成sourceMap
|
|
280
|
-
- type: `boolean | 'inline' | 'external'`
|
|
281
|
-
- default: `false`
|
|
282
|
-
|
|
283
|
-
## splitting
|
|
284
|
-
是否开启代码分割
|
|
285
|
-
- type: `boolean`
|
|
286
|
-
- default: `false`
|
|
287
|
-
|
|
288
|
-
## style
|
|
289
|
-
配置样式相关的配置
|
|
290
|
-
|
|
291
|
-
### less
|
|
292
|
-
less相关配置
|
|
293
|
-
#### lessOptions
|
|
294
|
-
详细配置参考[less](https://less.bootcss.com/usage/#less-options)
|
|
295
|
-
- type: `Object`
|
|
296
|
-
- default: `{ javascriptEnabled: true }`
|
|
297
|
-
|
|
298
|
-
#### additionalData
|
|
299
|
-
在入口文件起始添加 `Less` 代码。
|
|
300
|
-
- type: `string`
|
|
301
|
-
- default: `undefined`
|
|
302
|
-
|
|
303
|
-
```ts modern.config.ts
|
|
304
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
305
|
-
|
|
306
|
-
export default defineConfig({
|
|
307
|
-
buildConfig: {
|
|
308
|
-
style: {
|
|
309
|
-
less: {
|
|
310
|
-
additionalData: `@base-color: #c6538c;`,
|
|
311
|
-
},
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
});
|
|
315
|
-
|
|
316
|
-
```
|
|
317
|
-
#### implementation
|
|
318
|
-
配置 `Less` 使用的实现库,在不指定的情况下,使用的内置版本是`4.1.3`
|
|
319
|
-
- type: `string | Object`
|
|
320
|
-
- default: `undefined`
|
|
321
|
-
|
|
322
|
-
`Object` 类型时,指定 `Less` 的实现库
|
|
323
|
-
```ts modern.config.ts
|
|
324
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
325
|
-
|
|
326
|
-
export default defineConfig({
|
|
327
|
-
buildConfig: {
|
|
328
|
-
style: {
|
|
329
|
-
less: {
|
|
330
|
-
implementation: require('less'),
|
|
331
|
-
},
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
});
|
|
335
|
-
```
|
|
336
|
-
|
|
337
|
-
`string` 类型时,指定 `Less` 的实现库的路径
|
|
338
|
-
```ts modern.config.ts
|
|
339
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
340
|
-
|
|
341
|
-
export default defineConfig({
|
|
342
|
-
buildConfig: {
|
|
343
|
-
style: {
|
|
344
|
-
less: {
|
|
345
|
-
implementation: require.resolve('less'),
|
|
346
|
-
},
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
});
|
|
350
|
-
```
|
|
351
|
-
|
|
352
|
-
### sass
|
|
353
|
-
sass相关配置
|
|
354
|
-
#### sassOptions
|
|
355
|
-
详细配置参考[node-sass](https://github.com/sass/node-sass#options)
|
|
356
|
-
- type: `Object`
|
|
357
|
-
- default: `{}`
|
|
358
|
-
#### additionalData
|
|
359
|
-
在入口文件起始添加 `Sass` 代码。
|
|
360
|
-
- type: `string | Function`
|
|
361
|
-
- default: `undefined`
|
|
362
|
-
```ts modern.config.ts
|
|
363
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
364
|
-
|
|
365
|
-
export default defineConfig({
|
|
366
|
-
buildConfig: {
|
|
367
|
-
style: {
|
|
368
|
-
sass: {
|
|
369
|
-
additionalData: `$base-color: #c6538c;
|
|
370
|
-
$border-dark: rgba($base-color, 0.88);`,
|
|
371
|
-
},
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
#### implementation
|
|
378
|
-
配置 `Sass` 使用的实现库,在不指定的情况下,使用的内置版本是`1.5.4`
|
|
379
|
-
- type: `string | Object`
|
|
380
|
-
- default: `undefined`
|
|
381
|
-
|
|
382
|
-
`Object` 类型时,指定 `Sass` 的实现库
|
|
383
|
-
```ts modern.config.ts
|
|
384
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
385
|
-
|
|
386
|
-
export default defineConfig({
|
|
387
|
-
buildConfig: {
|
|
388
|
-
style: {
|
|
389
|
-
sass: {
|
|
390
|
-
implementation: require('sass'),
|
|
391
|
-
},
|
|
392
|
-
}
|
|
393
|
-
}
|
|
394
|
-
});
|
|
395
|
-
```
|
|
396
|
-
|
|
397
|
-
`string` 类型时,指定 `Sass` 的实现库的路径
|
|
398
|
-
```ts modern.config.ts
|
|
399
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
400
|
-
|
|
401
|
-
export default defineConfig({
|
|
402
|
-
buildConfig: {
|
|
403
|
-
style: {
|
|
404
|
-
sass: {
|
|
405
|
-
implementation: require.resolve('sass'),
|
|
406
|
-
},
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
});
|
|
410
|
-
```
|
|
411
|
-
|
|
412
|
-
### postcss
|
|
413
|
-
- plugins
|
|
414
|
-
- processOptions
|
|
415
|
-
|
|
416
|
-
详细配置查看[postcss](https://github.com/postcss/postcss#options)
|
|
417
|
-
### inject
|
|
418
|
-
配置打包模式下是否将style插入到js中
|
|
419
|
-
|
|
420
|
-
- type: `boolean`
|
|
421
|
-
- default: `false`
|
|
422
|
-
|
|
423
|
-
### autoModules
|
|
424
|
-
根据文件名自动启用 CSS Modules。
|
|
425
|
-
|
|
426
|
-
- type: `boolean | RegExp`
|
|
427
|
-
- default: `true `
|
|
428
|
-
|
|
429
|
-
`true` : 为以 `.module.css` `.module.less` `.module.scss` `.module.sass` 文件名结尾的样式文件启用 CSS Modules
|
|
430
|
-
|
|
431
|
-
`false` : 禁用 CSS Modules.
|
|
432
|
-
|
|
433
|
-
`RegExp` : 为匹配正则条件的所有文件启用 CSS Modules.
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
### modules
|
|
437
|
-
CSS Modules配置
|
|
438
|
-
|
|
439
|
-
- type: `Object`
|
|
440
|
-
- default: `{}`
|
|
441
|
-
|
|
442
|
-
一个常用的配置是`localsConvention`,它可以改变css modules的类名生成规则
|
|
443
|
-
```ts modern.config.ts
|
|
444
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
445
|
-
|
|
446
|
-
export default defineConfig({
|
|
447
|
-
buildConfig: {
|
|
448
|
-
style: {
|
|
449
|
-
modules: {
|
|
450
|
-
localsConvention: 'camelCaseOnly',
|
|
451
|
-
},
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
});
|
|
455
|
-
```
|
|
456
|
-
对于以下样式
|
|
457
|
-
```css
|
|
458
|
-
.box-title {
|
|
459
|
-
color: red;
|
|
460
|
-
}
|
|
461
|
-
```
|
|
462
|
-
你可以使用`styles.boxTitle`来访问
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
详细配置查看[postcss-modules](https://github.com/madyankin/postcss-modules#usage)
|
|
466
|
-
|
|
467
|
-
### tailwind
|
|
468
|
-
tailwindcss相关配置
|
|
469
|
-
|
|
470
|
-
- type: `Object | Function`
|
|
471
|
-
- default: `见下方配置详情`
|
|
472
|
-
|
|
473
|
-
<details>
|
|
474
|
-
<summary>TailwindCSS 配置详情</summary>
|
|
475
|
-
|
|
476
|
-
```ts modern.config.ts
|
|
477
|
-
const tailwind = {
|
|
478
|
-
purge: {
|
|
479
|
-
enabled: options.env === 'production',
|
|
480
|
-
content: [
|
|
481
|
-
'./config/html/**/*.html',
|
|
482
|
-
'./config/html/**/*.ejs',
|
|
483
|
-
'./config/html/**/*.hbs',
|
|
484
|
-
'./src/**/*',
|
|
485
|
-
],
|
|
486
|
-
layers: ['utilities'],
|
|
487
|
-
},
|
|
488
|
-
// https://tailwindcss.com/docs/upcoming-changes
|
|
489
|
-
future: {
|
|
490
|
-
removeDeprecatedGapUtilities: false,
|
|
491
|
-
purgeLayersByDefault: true,
|
|
492
|
-
defaultLineHeights: false,
|
|
493
|
-
standardFontWeights: false,
|
|
494
|
-
},
|
|
495
|
-
}
|
|
496
|
-
```
|
|
497
|
-
|
|
498
|
-
值为 `Object` 类型时,与默认配置通过 `Object.assign` 合并。
|
|
499
|
-
|
|
500
|
-
值为 `Function` 类型时,函数返回的对象与默认配置通过 `Object.assign` 合并。
|
|
501
|
-
|
|
502
|
-
不允许出现 `theme` 属性,否则会构建失败, 使用 [`designSystem`](/zh/api/design-system) 作为 `Tailwind CSS Theme` 配置。
|
|
503
|
-
|
|
504
|
-
其他的使用方式和 Tailwind CSS 一致: [快速传送门](https://tailwindcss.com/docs/configuration)。
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
## target
|
|
508
|
-
指定构建的目标环境
|
|
509
|
-
- type: `'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'esnext'`
|
|
510
|
-
- default: `'es2015'`
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
## umdGlobals
|
|
514
|
-
指定umd产物外部导入的全局变量
|
|
515
|
-
- type: `Record<string, string>`
|
|
516
|
-
- default: `{}`
|
|
517
|
-
|
|
518
|
-
```ts modern.config.ts
|
|
519
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
520
|
-
|
|
521
|
-
export default defineConfig({
|
|
522
|
-
buildConfig: {
|
|
523
|
-
umdGlobals: {
|
|
524
|
-
react: 'React',
|
|
525
|
-
'react-dom': 'ReactDOM',
|
|
526
|
-
},
|
|
527
|
-
}
|
|
528
|
-
});
|
|
529
|
-
```
|
|
530
|
-
此时,`react`和`react-dom`会被看做是外部导入的全局变量,不会被打包进umd产物中,而是通过`global.React`和`global.ReactDOM`的方式进行访问
|
|
531
|
-
|
|
532
|
-
## umdModuleName
|
|
533
|
-
指定umd产物的模块名
|
|
534
|
-
|
|
535
|
-
- type: `string` | `Function`
|
|
536
|
-
- default: `name => name`
|
|
537
|
-
|
|
538
|
-
```ts modern.config.ts
|
|
539
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
540
|
-
|
|
541
|
-
export default defineConfig({
|
|
542
|
-
buildConfig: {
|
|
543
|
-
format: 'umd',
|
|
544
|
-
umdModuleName: 'myLib',
|
|
545
|
-
}
|
|
546
|
-
});
|
|
547
|
-
```
|
|
548
|
-
此时umd产物会去挂载到`global.myLib`上
|
|
549
|
-
:::tip
|
|
550
|
-
- 需要遵守umd规范,umd产物的模块名不能和全局变量名冲突
|
|
551
|
-
- 模块名不能含有`-`,`@`,`/`等特殊字符
|
|
552
|
-
:::
|
|
553
|
-
|
|
554
|
-
同时函数形式可以接收一个参数,为当前打包文件的输出路径
|
|
555
|
-
```ts modern.config.ts
|
|
556
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
557
|
-
|
|
558
|
-
export default defineConfig({
|
|
559
|
-
buildConfig: {
|
|
560
|
-
format: 'umd',
|
|
561
|
-
umdModuleName: (path) => {
|
|
562
|
-
if (path.includes('index')) {
|
|
563
|
-
return 'myLib';
|
|
564
|
-
} else {
|
|
565
|
-
return 'myLib2';
|
|
566
|
-
}
|
|
567
|
-
},
|
|
568
|
-
}
|
|
569
|
-
});
|
|
570
|
-
```
|
package/docs/zh/api/dev.md
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
# Dev
|
|
2
|
-
本章描述了调试相关的配置
|
|
3
|
-
## storybook
|
|
4
|
-
|
|
5
|
-
Storybook 配置请查看:[Storybook 配置](https://storybook.js.org/docs/react/configure/overview)
|
|
6
|
-
|
|
7
|
-
:::info
|
|
8
|
-
使用 Storybook 进行调试需要提前在项目下执行 new 命令启用「Visual Testing (Storybook)」模式功能。
|
|
9
|
-
:::
|
|
10
|
-
|
|
11
|
-
```ts modern.config.ts
|
|
12
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
13
|
-
|
|
14
|
-
export default defineConfig({
|
|
15
|
-
dev: {
|
|
16
|
-
storybook: {
|
|
17
|
-
addons: ['@storybook/addon-essentials'],
|
|
18
|
-
babel: async (options) => ({
|
|
19
|
-
// Update your babel configuration here
|
|
20
|
-
...options,
|
|
21
|
-
}),
|
|
22
|
-
framework: '@storybook/react',
|
|
23
|
-
stories: ['../src/**/*.stories.@(js|mdx)'],
|
|
24
|
-
webpackFinal: async (config, { configType }) => {
|
|
25
|
-
// Make whatever fine-grained changes you need
|
|
26
|
-
// Return the altered config
|
|
27
|
-
return config;
|
|
28
|
-
},
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
});
|
|
32
|
-
|
|
33
|
-
```
|
package/docs/zh/api/plugins.md
DELETED
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
# Plugins
|
|
2
|
-
本章介绍插件相关的 API,包括插件的基本用法,插件的钩子,插件的配置等。
|
|
3
|
-
|
|
4
|
-
Modern.js的插件系统借鉴了[follow-pipeline](https://github.com/farrow-js/farrow/tree/master/packages/farrow-pipeline),你可以通过hooks介入到各个流程中。
|
|
5
|
-
|
|
6
|
-
## Basic Usage
|
|
7
|
-
|
|
8
|
-
- type: `CliPlugin<ModuleToolsHooks>[]`
|
|
9
|
-
- default: `[]`
|
|
10
|
-
|
|
11
|
-
```ts modern.config.ts
|
|
12
|
-
import { defineConfig } from '@modern-js/module-tools';
|
|
13
|
-
import myPlugin from '.';
|
|
14
|
-
|
|
15
|
-
export default defineConfig({
|
|
16
|
-
plugins: [myPlugin()]
|
|
17
|
-
});
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
一个插件的基本结构如下:
|
|
21
|
-
```ts myPlugin.ts
|
|
22
|
-
export default (): CliPlugin<ModuleToolsHooks> => {
|
|
23
|
-
return {
|
|
24
|
-
name: 'dev-plugin-example',
|
|
25
|
-
setup: () => {
|
|
26
|
-
return {
|
|
27
|
-
registerDev() {
|
|
28
|
-
return {
|
|
29
|
-
name: 'plugin-example',
|
|
30
|
-
menuItem: {
|
|
31
|
-
name: 'dev-example',
|
|
32
|
-
value: 'dev-example',
|
|
33
|
-
},
|
|
34
|
-
action() {
|
|
35
|
-
console.info('running dev-example');
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
},
|
|
39
|
-
};
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
};
|
|
43
|
-
```
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
## Hooks
|
|
47
|
-
|
|
48
|
-
### Types
|
|
49
|
-
Module tools主要使用到了两种类型的钩子,分别是 `ParallelWorkflow` 和 `AsyncPipeline` 。
|
|
50
|
-
- `ParallelWorkflow` 是一个并行的钩子,可以同时执行多个钩子,但是不会等待钩子执行完毕,而是立即返回。
|
|
51
|
-
- `AsyncPipeline` 是一个串行的钩子,会等待上一个钩子执行完毕后再执行下一个钩子。
|
|
52
|
-
创建钩子时,需要指定钩子的输入和输出类型,例如 `createParallelWorkflow<void, void>` ,表明这个钩子没有输入,也没有输出。
|
|
53
|
-
|
|
54
|
-
### Dev Hooks
|
|
55
|
-
|
|
56
|
-
#### registerDev
|
|
57
|
-
- type: `ParallelWorkflow<void, DevToolData>`
|
|
58
|
-
- 注册dev任务,storybook 就是通过这个hooks注册的
|
|
59
|
-
|
|
60
|
-
#### beforeDev
|
|
61
|
-
- type: `ParallelWorkflow<DevToolData[], void>`
|
|
62
|
-
- 在dev任务执行之前执行
|
|
63
|
-
|
|
64
|
-
#### afterDev
|
|
65
|
-
- type: `ParallelWorkflow<void, void>`
|
|
66
|
-
- 在dev任务执行之后执行
|
|
67
|
-
|
|
68
|
-
#### beforeDevMenu
|
|
69
|
-
- type: `ParallelWorkflow<QuestionCollection, QuestionCollection | void>`
|
|
70
|
-
- 在选择dev任务菜单执行之前执行
|
|
71
|
-
|
|
72
|
-
#### afterDevMenu
|
|
73
|
-
- type: `ParallelWorkflow<{ result: PromptResult; devTools: DevToolData[] }, void>`
|
|
74
|
-
- 在选择dev任务菜单执行之后执行
|
|
75
|
-
|
|
76
|
-
#### beforeDevTask
|
|
77
|
-
- type: `ParallelWorkflow<DevToolData, void>`
|
|
78
|
-
- 在执行每一项dev任务前执行
|
|
79
|
-
|
|
80
|
-
### BuildHooks
|
|
81
|
-
|
|
82
|
-
#### beforeBuild
|
|
83
|
-
- type: `ParallelWorkflow<{ config: BuildConfig; options: BuildCommandOptions }, BuildConfig>`
|
|
84
|
-
- 在所有的构建任务执行之前执行
|
|
85
|
-
|
|
86
|
-
#### afterBuild
|
|
87
|
-
- type: `ParallelWorkflow<BuildResult, void>`
|
|
88
|
-
- 在所有的构建任务执行完后执行
|
|
89
|
-
|
|
90
|
-
#### beforeBuildTask
|
|
91
|
-
- type: `ParallelWorkflow<{ config: BaseBuildConfig; options: BuildCommandOptions }, BaseBuildConfig>`
|
|
92
|
-
- 在每一项构建任务执行之前执行,
|
|
93
|
-
|
|
94
|
-
#### afterBuildTask
|
|
95
|
-
- type: `ParallelWorkflow<BuildTaskResult, void>`
|
|
96
|
-
- 在每一项构建任务执行完后执行
|
|
97
|
-
|
|
98
|
-
#### registerBuildPlatform
|
|
99
|
-
- type: `ParallelWorkflow<void, RegisterBuildPlatformResult>`
|
|
100
|
-
- 注册构建平台, storybook 的构建就是通过这个hooks注册的
|
|
101
|
-
|
|
102
|
-
#### beforeBuildPlatform
|
|
103
|
-
- type: `ParallelWorkflow<RegisterBuildPlatformResult[], void>`
|
|
104
|
-
- 在构建平台之前执行
|
|
105
|
-
|
|
106
|
-
#### afterBuildPlatform
|
|
107
|
-
- type: `ParallelWorkflow<void, BuildPlatformResult>`
|
|
108
|
-
- 在构建平台完后执行
|