@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.
- package/CHANGELOG.md +15 -0
- package/docs/en/api/config/build-config.mdx +80 -53
- 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 +21 -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 +83 -56
- 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 +20 -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
|
@@ -17,7 +17,7 @@ sidebar_position: 5
|
|
|
17
17
|
|
|
18
18
|
对应 [Jest](https://jestjs.io/docs/configuration) 的配置,当为 `object` 类型时,可以配置 Jest 所支持的所有底层配置 。
|
|
19
19
|
|
|
20
|
-
```js modern.config.ts
|
|
20
|
+
```js title="modern.config.ts"
|
|
21
21
|
import { defineConfig } from '@modern-js/module-tools';
|
|
22
22
|
|
|
23
23
|
export default defineConfig({
|
|
@@ -31,7 +31,7 @@ export default defineConfig({
|
|
|
31
31
|
|
|
32
32
|
值为 `Function` 类型时,默认配置作为第一个参数传入,需要返回新的 Jest 配置对象。
|
|
33
33
|
|
|
34
|
-
```js modern.config.ts
|
|
34
|
+
```js title="modern.config.ts"
|
|
35
35
|
import { defineConfig } from '@modern-js/module-tools';
|
|
36
36
|
|
|
37
37
|
export default defineConfig({
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
```js modern.config.ts
|
|
1
|
+
```js title="modern.config.ts"
|
|
2
2
|
import { myEsbuildPlugin } from './myEsbuildPlugin';
|
|
3
3
|
|
|
4
4
|
export default defineConfig({
|
|
5
5
|
buildConfig: {
|
|
6
6
|
esbuildOptions: options => {
|
|
7
7
|
options.plugins = [myEsbuildPlugin, ...options.plugins];
|
|
8
|
-
return
|
|
8
|
+
return options;
|
|
9
9
|
},
|
|
10
10
|
},
|
|
11
11
|
});
|
|
@@ -19,44 +19,30 @@ sidebar_position: 7
|
|
|
19
19
|
- 设置静态资源路径为 `./assets`。
|
|
20
20
|
- 对于不超过 **10kb** 的文件会内联到代码中。
|
|
21
21
|
|
|
22
|
+
### 示例
|
|
23
|
+
|
|
22
24
|
让我们看下面的例子:
|
|
23
25
|
|
|
24
|
-
|
|
26
|
+
- 项目源代码:
|
|
25
27
|
|
|
26
|
-
```ts ./src/asset.ts
|
|
28
|
+
```ts title="./src/asset.ts"
|
|
27
29
|
import img from './bg.png';
|
|
28
30
|
console.log(img);
|
|
29
31
|
```
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
项目源代码。
|
|
34
|
-
|
|
35
|
-
---
|
|
36
|
-
|
|
37
|
-
如果 `bg.png` 的大小小于 10 kb,则此时产物目录结构和产物内容为。
|
|
38
|
-
|
|
39
|
-
<CH.Code>
|
|
33
|
+
- 如果 `bg.png` 的大小小于 10 kb,则此时产物目录结构和产物内容为:
|
|
40
34
|
|
|
41
35
|
```bash
|
|
42
36
|
./dist
|
|
43
37
|
└── asset.js
|
|
44
38
|
```
|
|
45
39
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
```js ./dist/asset.js
|
|
40
|
+
```js title="./dist/asset.js"
|
|
49
41
|
var img_default = 'data:image/png;base64,';
|
|
50
42
|
console.info(img_default);
|
|
51
43
|
```
|
|
52
44
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
---
|
|
56
|
-
|
|
57
|
-
如果 `bg.png` 的大小大于 10 kb,则此时产物目录结构和产物内容为。
|
|
58
|
-
|
|
59
|
-
<CH.Code>
|
|
45
|
+
- 如果 `bg.png` 的大小大于 10 kb,则此时产物目录结构和产物内容为:
|
|
60
46
|
|
|
61
47
|
```bash
|
|
62
48
|
./dist
|
|
@@ -65,19 +51,12 @@ console.info(img_default);
|
|
|
65
51
|
└── bg.13e2aba2.png
|
|
66
52
|
```
|
|
67
53
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
```js ./dist/asset.js
|
|
54
|
+
```js title="./dist/asset.js"
|
|
71
55
|
import img from './assets/bg.13e2aba2.png';
|
|
72
56
|
console.info(img);
|
|
73
57
|
```
|
|
74
58
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
</CH.Spotlight>
|
|
78
|
-
|
|
79
|
-
当想要修改默认行为的时候,可以使用以下 API:
|
|
59
|
+
当你想要修改默认行为的时候,可以使用以下 API:
|
|
80
60
|
|
|
81
61
|
- `asset.path`:修改静态资源文件输出路径。
|
|
82
62
|
- `asset.limit`:修改内联静态资源文件的阈值。
|
|
83
|
-
|
|
@@ -25,35 +25,21 @@ export default defineConfig({
|
|
|
25
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
|
+
### 示例
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"react": "^17"
|
|
34
|
-
//...other dependencies
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
```
|
|
30
|
+
- 如果项目依赖了 `react`:
|
|
38
31
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
如果项目依赖了 `react`。
|
|
42
|
-
|
|
43
|
-
```json package.json
|
|
32
|
+
```json title="package.json"
|
|
44
33
|
{
|
|
45
34
|
"dependencies": {
|
|
46
35
|
"react": "^17"
|
|
47
|
-
//...other dependencies
|
|
48
36
|
}
|
|
49
37
|
}
|
|
50
38
|
```
|
|
51
39
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
`modern.config.ts` 配置。
|
|
40
|
+
- `modern.config.ts` 配置:
|
|
55
41
|
|
|
56
|
-
```ts
|
|
42
|
+
```ts title="modern.config.ts"
|
|
57
43
|
export default defineConfig({
|
|
58
44
|
buildConfig: {
|
|
59
45
|
format: 'umd',
|
|
@@ -63,20 +49,16 @@ export default defineConfig({
|
|
|
63
49
|
});
|
|
64
50
|
```
|
|
65
51
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
当源码中使用了 `react` 依赖。
|
|
52
|
+
- 当源码中使用了 `react` 依赖:
|
|
69
53
|
|
|
70
|
-
```tsx src/index.ts
|
|
54
|
+
```tsx title="src/index.ts"
|
|
71
55
|
import React from 'react';
|
|
72
56
|
console.info(React);
|
|
73
57
|
```
|
|
74
58
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
此时产物中不会将 `react` 代码打包到产物中。
|
|
59
|
+
- 此时产物中不会将 `react` 代码打包到产物中:
|
|
78
60
|
|
|
79
|
-
```js dist/index.js
|
|
61
|
+
```js title="dist/index.js"
|
|
80
62
|
(function (global, factory) {
|
|
81
63
|
if (typeof module === 'object' && typeof module.exports === 'object')
|
|
82
64
|
factory(exports, require('react'));
|
|
@@ -103,42 +85,18 @@ console.info(React);
|
|
|
103
85
|
});
|
|
104
86
|
```
|
|
105
87
|
|
|
106
|
-
</CH.Spotlight>
|
|
107
|
-
|
|
108
88
|
通过上面的例子我们知道,当使用 `autoExternal` 和 `externals` API 后:
|
|
109
89
|
|
|
110
90
|
- 在 Node.js 环境下,可以通过 `require('react')` 获取 react 依赖。
|
|
111
91
|
- 在 浏览器环境下,可以通过 `global.react` 获取 react 依赖。
|
|
112
92
|
|
|
93
|
+
### 三方依赖的全局变量名称
|
|
94
|
+
|
|
113
95
|
然而在浏览器环境下,获取第三方依赖的时候,**全局变量名称不一定与依赖名称完全相同**,此时就要使用 [`buildConfig.umdGlobals`](/api/config/build-config#umdglobals) API。
|
|
114
96
|
|
|
115
97
|
还是使用之前的例子,当 `react` 依赖以 `windows.React` 或者 `global.React` 全局变量的形式存在于浏览器环境下,那么此时:
|
|
116
98
|
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
```json package.json
|
|
120
|
-
{
|
|
121
|
-
"devDependencies": {
|
|
122
|
-
"react": "^17"
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
---
|
|
128
|
-
|
|
129
|
-
如果项目依赖了 `react`。
|
|
130
|
-
|
|
131
|
-
```json package.json
|
|
132
|
-
{
|
|
133
|
-
"devDependencies": {
|
|
134
|
-
"react": "^17"
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
---
|
|
140
|
-
|
|
141
|
-
`modern.config.ts` 配置。
|
|
99
|
+
- `modern.config.ts` 配置:
|
|
142
100
|
|
|
143
101
|
```ts
|
|
144
102
|
export default defineConfig({
|
|
@@ -151,20 +109,16 @@ export default defineConfig({
|
|
|
151
109
|
});
|
|
152
110
|
```
|
|
153
111
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
当源码中使用了 `react` 依赖。
|
|
112
|
+
- 当源码中使用了 `react` 依赖:
|
|
157
113
|
|
|
158
|
-
```tsx src/index.ts
|
|
114
|
+
```tsx title="src/index.ts"
|
|
159
115
|
import React from 'react';
|
|
160
116
|
console.info(React);
|
|
161
117
|
```
|
|
162
118
|
|
|
163
|
-
|
|
119
|
+
- 此时我们会看到这样的产物代码:
|
|
164
120
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
```js dist/index.js focus=12:18
|
|
121
|
+
```js title="dist/index.js"
|
|
168
122
|
(function (global, factory) {
|
|
169
123
|
if (typeof module === 'object' && typeof module.exports === 'object')
|
|
170
124
|
factory();
|
|
@@ -187,15 +141,13 @@ console.info(React);
|
|
|
187
141
|
});
|
|
188
142
|
```
|
|
189
143
|
|
|
190
|
-
</CH.Spotlight>
|
|
191
|
-
|
|
192
144
|
此时项目就可以运行在浏览器中,并使用存在于全局对象上的 `React` 变量了。
|
|
193
145
|
|
|
194
146
|
## 更改项目的全局变量名称
|
|
195
147
|
|
|
196
148
|
当我们将下面的代码打包成 umd 产物并运行在浏览器的时候,我们可以通过 `window.index` 来使用该模块。
|
|
197
149
|
|
|
198
|
-
```ts ./src/index.ts
|
|
150
|
+
```ts title="./src/index.ts"
|
|
199
151
|
export default () => {
|
|
200
152
|
console.info('hello world');
|
|
201
153
|
};
|
|
@@ -203,7 +155,7 @@ export default () => {
|
|
|
203
155
|
|
|
204
156
|
**默认情况下,以源码文件名称作为该模块在浏览器里全局变量的名称**。对于上面的例子,其产物内容如下:
|
|
205
157
|
|
|
206
|
-
```js ./dist/index.js
|
|
158
|
+
```js title="./dist/index.js"
|
|
207
159
|
(function (global, factory) {
|
|
208
160
|
if (typeof module === 'object' && typeof module.exports === 'object')
|
|
209
161
|
factory(exports);
|
|
@@ -233,7 +185,7 @@ export default defineConfig({
|
|
|
233
185
|
|
|
234
186
|
此时构建产物的内容为:
|
|
235
187
|
|
|
236
|
-
```js ./dist/index.js
|
|
188
|
+
```js title="./dist/index.js"
|
|
237
189
|
(function (global, factory) {
|
|
238
190
|
if (typeof module === 'object' && typeof module.exports === 'object')
|
|
239
191
|
factory(exports);
|
|
@@ -6,7 +6,7 @@ sidebar_position: 4
|
|
|
6
6
|
|
|
7
7
|
一般来说,项目所需要的第三方依赖可以通过包管理器的 `install` 命令安装,在安装第三方依赖成功后,这些第三方依赖一般会出现在项目 `package.json` 的 `dependencies` 和 `devDependencies` 下。
|
|
8
8
|
|
|
9
|
-
```json pacakge.json
|
|
9
|
+
```json title="pacakge.json"
|
|
10
10
|
{
|
|
11
11
|
"dependencies": {},
|
|
12
12
|
"devDependencies": {}
|
|
@@ -25,25 +25,11 @@ sidebar_position: 4
|
|
|
25
25
|
|
|
26
26
|
如果需要打包某些依赖,建议将它们从 `"dependencies"` 挪到 `"devDependencies"` ,这相当于对依赖进行 **prebundle** ,可以减小依赖安装的体积。
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
### 示例
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
{
|
|
32
|
-
"dependencies": {
|
|
33
|
-
"react": "^17"
|
|
34
|
-
},
|
|
35
|
-
// or
|
|
36
|
-
"peerDependencies": {
|
|
37
|
-
"react": "^17"
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
---
|
|
30
|
+
如果项目依赖了 `react`:
|
|
43
31
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
```json ./v1/package.json
|
|
32
|
+
```json title="package.json"
|
|
47
33
|
{
|
|
48
34
|
"dependencies": {
|
|
49
35
|
"react": "^17"
|
|
@@ -55,26 +41,20 @@ sidebar_position: 4
|
|
|
55
41
|
}
|
|
56
42
|
```
|
|
57
43
|
|
|
58
|
-
|
|
44
|
+
当源码中使用了 `react` 依赖:
|
|
59
45
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
```tsx src/index.ts
|
|
46
|
+
```tsx title="src/index.ts"
|
|
63
47
|
import React from 'react';
|
|
64
48
|
console.info(React);
|
|
65
49
|
```
|
|
66
50
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
此时产物中不会将 `react` 代码打包到产物中。
|
|
51
|
+
此时产物中不会包含 `react` 的代码:
|
|
70
52
|
|
|
71
|
-
```js dist/index.js
|
|
53
|
+
```js title="dist/index.js"
|
|
72
54
|
import React from 'react';
|
|
73
55
|
console.info(React);
|
|
74
56
|
```
|
|
75
57
|
|
|
76
|
-
</CH.Spotlight>
|
|
77
|
-
|
|
78
58
|
如果想要修改默认的处理方式,可以通过下面的 API 进行修改:
|
|
79
59
|
|
|
80
60
|
- [`buildConfig.autoExternal`](/api/config/build-config#autoexternal)
|
|
@@ -50,7 +50,7 @@ Bundleless 是单文件编译模式,因此对于类型的引用和导出你需
|
|
|
50
50
|
|
|
51
51
|
在 Bundle 构建过程中,除了将 `input` 设置为一个数组,也可以将它设置为一个对象。**通过使用对象的形式,我们可以修改构建产物输出的文件名称**。那么对于下面的例子,`./src/index.ts` 对应的构建产物文件路径为 `./dist/main.js`。
|
|
52
52
|
|
|
53
|
-
```js modern.config.ts
|
|
53
|
+
```js title="modern.config.ts"
|
|
54
54
|
import { defineConfig } from '@modern-js/module-tools';
|
|
55
55
|
|
|
56
56
|
export default defineConfig({
|
|
@@ -85,7 +85,7 @@ export default defineConfig({
|
|
|
85
85
|
|
|
86
86
|
默认情况下类型生成功能是开启的,如果需要关闭的话,可以按照如下配置:
|
|
87
87
|
|
|
88
|
-
```js modern.config.ts
|
|
88
|
+
```js title="modern.config.ts"
|
|
89
89
|
import { defineConfig } from '@modern-js/module-tools';
|
|
90
90
|
|
|
91
91
|
export default defineConfig({
|
|
@@ -112,7 +112,7 @@ export default defineConfig({
|
|
|
112
112
|
|
|
113
113
|
在 Bundleless 构建过程中,如果源代码中出现了别名,例如:
|
|
114
114
|
|
|
115
|
-
```js ./src/index.ts
|
|
115
|
+
```js title="./src/index.ts"
|
|
116
116
|
import utils from '@common/utils';
|
|
117
117
|
```
|
|
118
118
|
|
|
@@ -231,7 +231,7 @@ console.log('1.0.0');
|
|
|
231
231
|
|
|
232
232
|
> 如果不存在 `d.ts` 文件,则可以手动创建。
|
|
233
233
|
|
|
234
|
-
```ts env.d.ts
|
|
234
|
+
```ts title="env.d.ts"
|
|
235
235
|
declare const YOUR_ADD_GLOBAL_VAR;
|
|
236
236
|
```
|
|
237
237
|
|
|
@@ -24,7 +24,7 @@ sidebar_position: 2
|
|
|
24
24
|
|
|
25
25
|
一般来说,实现一个什么都不做的调试工具,其实现代码以及相关配置如下:
|
|
26
26
|
|
|
27
|
-
```
|
|
27
|
+
```ts do-nothing.ts
|
|
28
28
|
export const myPlugin = (): CliPlugin<ModuleTools> => ({
|
|
29
29
|
name: 'do-nothing',
|
|
30
30
|
setup() {
|
|
@@ -53,7 +53,7 @@ export const myPlugin = (): CliPlugin<ModuleTools> => ({
|
|
|
53
53
|
|
|
54
54
|
如果需要使用该调试工具插件,则需要在配置文件中增加它:
|
|
55
55
|
|
|
56
|
-
```
|
|
56
|
+
```ts
|
|
57
57
|
import doNothingPlugin from './plugins/do-nothing';
|
|
58
58
|
|
|
59
59
|
export default defineConfig({
|
|
@@ -31,7 +31,7 @@ sidebar_position: 6
|
|
|
31
31
|
|
|
32
32
|
例如在下面的配置中扩展了原有的颜色配置:
|
|
33
33
|
|
|
34
|
-
```ts
|
|
34
|
+
```ts title="modern.config.ts"
|
|
35
35
|
export default {
|
|
36
36
|
designSystem: {
|
|
37
37
|
extend: {
|
|
@@ -47,7 +47,7 @@ export default {
|
|
|
47
47
|
|
|
48
48
|
#### HTML 类名
|
|
49
49
|
|
|
50
|
-
```tsx ./src/index.tsx
|
|
50
|
+
```tsx title="./src/index.tsx"
|
|
51
51
|
import 'tailwindcss/utilities.css';
|
|
52
52
|
|
|
53
53
|
export default () => {
|
|
@@ -59,9 +59,7 @@ export default () => {
|
|
|
59
59
|
|
|
60
60
|
关于 [`@apply`](https://tailwindcss.com/docs/functions-and-directives#apply)。
|
|
61
61
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
```tsx ./src/index.tsx
|
|
62
|
+
```tsx title="./src/index.tsx"
|
|
65
63
|
import './index.css';
|
|
66
64
|
|
|
67
65
|
export default () => {
|
|
@@ -69,10 +67,8 @@ export default () => {
|
|
|
69
67
|
};
|
|
70
68
|
```
|
|
71
69
|
|
|
72
|
-
```css ./src/index.css
|
|
70
|
+
```css title="./src/index.css"
|
|
73
71
|
.btn-primary {
|
|
74
72
|
@apply bg-primary;
|
|
75
73
|
}
|
|
76
74
|
```
|
|
77
|
-
|
|
78
|
-
</CH.Code>
|
|
@@ -41,7 +41,7 @@ $ npx modern change
|
|
|
41
41
|
|
|
42
42
|
当执行成功后,生成的包含变更记录的 Markdown 文件会保存在项目的 `.changeset` 目录下面。其内容类似下面这样:
|
|
43
43
|
|
|
44
|
-
```markdown .changeset/brave-dryers-agree.md
|
|
44
|
+
```markdown title=".changeset/brave-dryers-agree.md"
|
|
45
45
|
---
|
|
46
46
|
'module-example': patch
|
|
47
47
|
---
|
|
@@ -57,7 +57,7 @@ publish test
|
|
|
57
57
|
|
|
58
58
|
执行 `modern bump` 将会基于 `.changeset/` 目录下记录了变更的 Markdown 文件内容来修改 `package.json` 中的版本号,同时生成 `CHANGELOG.md` 文件。**而当版本更新完成后,这些记录变更的 Markdown 文件也会被删除,也可说这些 Markdown 文件被“消耗”掉了**。
|
|
59
59
|
|
|
60
|
-
```markdown CHANGELOG.md
|
|
60
|
+
```markdown title="CHANGELOG.md"
|
|
61
61
|
# module
|
|
62
62
|
|
|
63
63
|
## 0.1.1
|
|
@@ -10,7 +10,7 @@ sidebar_position: 6
|
|
|
10
10
|
|
|
11
11
|
想要使用项目的测试功能,需要确保项目中包含依赖:`"@modern-js/plugin-testing"`,以及按照类似下面的内容进行配置:
|
|
12
12
|
|
|
13
|
-
```
|
|
13
|
+
```ts
|
|
14
14
|
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
15
15
|
import { testingPlugin } from '@modern-js/plugin-testing';
|
|
16
16
|
|
|
@@ -59,31 +59,17 @@ modern test --updateSnapshot
|
|
|
59
59
|
|
|
60
60
|
对于普通的模块,我们可以按照如下方式使用测试功能:
|
|
61
61
|
|
|
62
|
-
|
|
62
|
+
- 首先是模块的代码:
|
|
63
63
|
|
|
64
|
-
```ts ./src/index.ts
|
|
64
|
+
```ts title="./src/index.ts"
|
|
65
65
|
export default function () {
|
|
66
66
|
return 'hello world';
|
|
67
67
|
}
|
|
68
68
|
```
|
|
69
69
|
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
首先是模块的代码。
|
|
73
|
-
|
|
74
|
-
```ts ./src/index.ts
|
|
75
|
-
export default function () {
|
|
76
|
-
return 'hello world';
|
|
77
|
-
}
|
|
78
|
-
```
|
|
70
|
+
- 然后在测试文件中,我们可以按以下方式引用,其中 `@` 指向了源码目录,在初始化项目的 `tests/tsconfig.json` 的 `paths` 中定义了。
|
|
79
71
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
然后在测试文件中,我们可以这样。
|
|
83
|
-
|
|
84
|
-
其中 `@` 指向了源码目录,在初始化项目的 `tests/tsconfig.json` 的 `paths` 中定义了。
|
|
85
|
-
|
|
86
|
-
```ts ./tests/index.test.ts
|
|
72
|
+
```ts title="./tests/index.test.ts"
|
|
87
73
|
import main from '@/index';
|
|
88
74
|
|
|
89
75
|
describe('默认值 cases', () => {
|
|
@@ -95,9 +81,7 @@ describe('默认值 cases', () => {
|
|
|
95
81
|
});
|
|
96
82
|
```
|
|
97
83
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
最后我们可以执行 `modern test`。
|
|
84
|
+
- 最后我们可以执行 `modern test`:
|
|
101
85
|
|
|
102
86
|
```bash
|
|
103
87
|
pnpm test
|
|
@@ -107,8 +91,6 @@ yarn test
|
|
|
107
91
|
npm run test
|
|
108
92
|
```
|
|
109
93
|
|
|
110
|
-
</CH.Spotlight>
|
|
111
|
-
|
|
112
94
|
### 组件
|
|
113
95
|
|
|
114
96
|
{/* 链接待补充 */}
|
|
@@ -119,21 +101,9 @@ npm run test
|
|
|
119
101
|
如果需要使用 Runtime API,那么可以通过 [微生成器](/guide/basic/command-preview) 开启。
|
|
120
102
|
:::
|
|
121
103
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
```tsx ./src/index.tsx
|
|
125
|
-
export const default () {
|
|
126
|
-
return (
|
|
127
|
-
<div>This is a UI Component</div>
|
|
128
|
-
);
|
|
129
|
-
}
|
|
130
|
-
```
|
|
131
|
-
|
|
132
|
-
---
|
|
104
|
+
- 首先是组件的代码:
|
|
133
105
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
```tsx ./src/index.tsx
|
|
106
|
+
```tsx title="./src/index.tsx"
|
|
137
107
|
export const default () {
|
|
138
108
|
return (
|
|
139
109
|
<div>This is a UI Component</div>
|
|
@@ -141,13 +111,9 @@ export const default () {
|
|
|
141
111
|
}
|
|
142
112
|
```
|
|
143
113
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
然后在测试文件中,我们可以这样。
|
|
147
|
-
|
|
148
|
-
其中 `@` 指向了源码目录,在初始化项目的 `tests/tsconfig.json` 的 `paths` 中定义了。
|
|
114
|
+
- 然后在测试文件中,我们可以按以下方式引用,其中 `@` 指向了源码目录,在初始化项目的 `tests/tsconfig.json` 的 `paths` 中定义了。
|
|
149
115
|
|
|
150
|
-
```tsx ./tests/index.test.tsx
|
|
116
|
+
```tsx title="./tests/index.test.tsx"
|
|
151
117
|
import { render, screen } from '@modern-js/runtime/testing';
|
|
152
118
|
|
|
153
119
|
import Component from '@/index';
|
|
@@ -160,9 +126,7 @@ describe('默认值 cases', () => {
|
|
|
160
126
|
});
|
|
161
127
|
```
|
|
162
128
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
最后我们可以执行 `modern test`。
|
|
129
|
+
- 最后我们可以执行 `modern test`。
|
|
166
130
|
|
|
167
131
|
```bash
|
|
168
132
|
pnpm test
|
|
@@ -171,5 +135,3 @@ yarn test
|
|
|
171
135
|
## or
|
|
172
136
|
npm run test
|
|
173
137
|
```
|
|
174
|
-
|
|
175
|
-
</CH.Spotlight>
|
|
@@ -20,7 +20,7 @@ sidebar_position: 4
|
|
|
20
20
|
|
|
21
21
|
:::tip
|
|
22
22
|
在成功开启后,会提示需要手动在配置中增加如下类似的代码。
|
|
23
|
-
```
|
|
23
|
+
```ts
|
|
24
24
|
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
25
25
|
import { testingPlugin } from '@modern-js/plugin-testing';
|
|
26
26
|
|
|
@@ -39,7 +39,7 @@ export default defineConfig({
|
|
|
39
39
|
|
|
40
40
|
:::tip
|
|
41
41
|
在成功开启后,会提示需要手动在配置中增加如下类似的代码。
|
|
42
|
-
```
|
|
42
|
+
```ts
|
|
43
43
|
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
44
44
|
import { storybookPlugin } from '@modern-js/plugin-storybook';
|
|
45
45
|
|
|
@@ -67,7 +67,7 @@ export default defineConfig({
|
|
|
67
67
|
|
|
68
68
|
:::tip
|
|
69
69
|
在成功开启后,会提示需要手动在配置中增加如下类似的代码。
|
|
70
|
-
```
|
|
70
|
+
```ts
|
|
71
71
|
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
72
72
|
import { tailwindcssPlugin } from '@modern-js/plugin-tailwindcss';
|
|
73
73
|
|
|
@@ -88,7 +88,7 @@ export default defineConfig({
|
|
|
88
88
|
|
|
89
89
|
:::tip
|
|
90
90
|
在成功开启后,会提示需要手动在配置中增加如下类似的代码。
|
|
91
|
-
```
|
|
91
|
+
```ts
|
|
92
92
|
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
93
93
|
import runtime from '@modern-js/runtime/cli';
|
|
94
94
|
|