@modern-js/module-tools-docs 2.25.0 → 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.
- package/CHANGELOG.md +7 -0
- package/docs/en/api/config/build-config.md +153 -38
- package/docs/en/api/config/build-preset.mdx +3 -3
- package/docs/en/api/config/design-system.md +3 -3
- package/docs/en/api/config/dev.md +22 -25
- package/docs/en/api/config/plugins.md +50 -5
- package/docs/en/api/config/testing.md +3 -3
- package/docs/en/guide/advance/build-umd.mdx +1 -1
- package/docs/en/guide/basic/command-preview.md +2 -2
- package/docs/en/guide/basic/modify-output-product.md +16 -4
- package/docs/en/guide/best-practices/components.mdx +3 -3
- package/docs/en/plugins/guide/setup-function.mdx +1 -1
- package/docs/en/plugins/official-list/plugin-banner.md +1 -1
- package/docs/en/plugins/official-list/plugin-import.mdx +34 -25
- package/docs/zh/api/config/build-config.md +158 -41
- package/docs/zh/api/config/build-preset.mdx +1 -1
- package/docs/zh/api/config/design-system.md +3 -3
- package/docs/zh/api/config/dev.md +23 -26
- package/docs/zh/api/config/plugins.md +50 -5
- package/docs/zh/api/config/testing.md +3 -3
- package/docs/zh/guide/advance/build-umd.mdx +1 -1
- package/docs/zh/guide/basic/before-getting-started.md +1 -1
- package/docs/zh/guide/basic/command-preview.md +3 -3
- package/docs/zh/guide/basic/modify-output-product.md +18 -7
- package/docs/zh/guide/best-practices/components.mdx +3 -3
- package/docs/zh/plugins/guide/setup-function.mdx +1 -1
- package/docs/zh/plugins/official-list/plugin-banner.md +1 -1
- package/docs/zh/plugins/official-list/plugin-import.mdx +30 -21
- package/package.json +3 -3
|
@@ -605,7 +605,7 @@ When adding styles using HTML class names, by default Tailwind will not only add
|
|
|
605
605
|
|
|
606
606
|
For the following code, there is a big difference between the bundle and bundleless modes of building products.
|
|
607
607
|
|
|
608
|
-
> The so-called bundle and bundleless can be found in [
|
|
608
|
+
> The so-called bundle and bundleless can be found in ["Bundle and Bundleless"](/en/guide/advance/in-depth-about-build#bundle- and-bundleless)
|
|
609
609
|
|
|
610
610
|
```tsx ./src/index.tsx
|
|
611
611
|
import 'tailwindcss/utilities.css';
|
|
@@ -782,8 +782,8 @@ If you have special needs for the build product directory structure, you can use
|
|
|
782
782
|
|
|
783
783
|
## Testing components
|
|
784
784
|
|
|
785
|
-
For more information on how to test components, please refer to [
|
|
785
|
+
For more information on how to test components, please refer to ["Test project"](/en/guide/basic/test-your-project).
|
|
786
786
|
|
|
787
787
|
## Releasing components
|
|
788
788
|
|
|
789
|
-
It is recommended to use module project to provide version publishing function, you can refer to [
|
|
789
|
+
It is recommended to use module project to provide version publishing function, you can refer to ["Versioning and publishing"](/en/guide/basic/publish-your-project).
|
|
@@ -4,7 +4,7 @@ sidebar_position: 3
|
|
|
4
4
|
|
|
5
5
|
# Setup function
|
|
6
6
|
|
|
7
|
-
In the [
|
|
7
|
+
In the ["Plugin object"](/plugins/guide/plugin-object) section we know that the plug-in object contains a `setup` function that not only contains an `api` object parameter, but also returns a Hooks object.
|
|
8
8
|
|
|
9
9
|
## Plugin API objects
|
|
10
10
|
|
|
@@ -39,7 +39,7 @@ export default defineConfig({
|
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
:::tip
|
|
42
|
-
Note: CSS comments do not support the `//comment` syntax. Refer to [
|
|
42
|
+
Note: CSS comments do not support the `//comment` syntax. Refer to ["CSS Comments"](https://developer.mozilla.org/en-US/docs/Web/CSS/Comments)
|
|
43
43
|
:::
|
|
44
44
|
|
|
45
45
|
## Example
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Using [SWC](https://swc.rs/) provides the same ability and configuration as [`babel-plugin-import`](https://github.com/umijs/babel-plugin-import).
|
|
4
4
|
|
|
5
5
|
:::tip
|
|
6
|
-
Since
|
|
6
|
+
Since `@modern-js/module-tools` version >= v2.16.0, this plugin functionality is built into Module Tools and is provided by [`transformImport`](api/config/build-config.html#transformimport).
|
|
7
7
|
:::
|
|
8
8
|
|
|
9
9
|
## Quick Start
|
|
@@ -26,17 +26,19 @@ pnpm add @modern-js/plugin-module-import -D
|
|
|
26
26
|
In Module Tools, you can register plugins in the following way:
|
|
27
27
|
|
|
28
28
|
```ts
|
|
29
|
-
import { moduleTools, defineConfig
|
|
29
|
+
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
30
30
|
import { modulePluginImport } from '@modern-js/plugin-module-import';
|
|
31
31
|
|
|
32
32
|
export default defineConfig({
|
|
33
33
|
plugins: [
|
|
34
34
|
moduleTools(),
|
|
35
35
|
modulePluginImport({
|
|
36
|
-
pluginImport: [
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
pluginImport: [
|
|
37
|
+
{
|
|
38
|
+
libraryName: 'antd',
|
|
39
|
+
style: true,
|
|
40
|
+
},
|
|
41
|
+
],
|
|
40
42
|
}),
|
|
41
43
|
],
|
|
42
44
|
});
|
|
@@ -46,17 +48,17 @@ This way we can use the ability of automatic import in Module Tools.
|
|
|
46
48
|
|
|
47
49
|
## Configurations
|
|
48
50
|
|
|
49
|
-
|
|
51
|
+
- **Type**:
|
|
50
52
|
|
|
51
53
|
```ts
|
|
52
54
|
type Options = {
|
|
53
55
|
pluginImport?: ImportItem[];
|
|
54
|
-
}
|
|
56
|
+
};
|
|
55
57
|
```
|
|
56
58
|
|
|
57
59
|
### pluginImport
|
|
58
60
|
|
|
59
|
-
|
|
61
|
+
- **Type**: `object[]`
|
|
60
62
|
|
|
61
63
|
The elements of the array are configuration objects for `babel-plugin-import`, which can be referred to [options](https://github.com/umijs/babel-plugin-import#options)。
|
|
62
64
|
|
|
@@ -64,7 +66,7 @@ The elements of the array are configuration objects for `babel-plugin-import`, w
|
|
|
64
66
|
|
|
65
67
|
```ts
|
|
66
68
|
import { modulePluginImport } from '@modern-js/plugin-module-import';
|
|
67
|
-
import { moduleTools, defineConfig
|
|
69
|
+
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
68
70
|
|
|
69
71
|
export default defineConfig({
|
|
70
72
|
plugins: [
|
|
@@ -75,7 +77,7 @@ export default defineConfig({
|
|
|
75
77
|
{
|
|
76
78
|
libraryName: 'foo',
|
|
77
79
|
style: true,
|
|
78
|
-
}
|
|
80
|
+
},
|
|
79
81
|
],
|
|
80
82
|
}),
|
|
81
83
|
],
|
|
@@ -110,16 +112,18 @@ Add the following configuration on the right-hand side:
|
|
|
110
112
|
|
|
111
113
|
```ts
|
|
112
114
|
import { modulePluginImport } from '@modern-js/plugin-module-import';
|
|
113
|
-
import { moduleTools, defineConfig
|
|
115
|
+
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
114
116
|
|
|
115
117
|
export default defineConfig({
|
|
116
118
|
plugins: [
|
|
117
119
|
moduleTools(),
|
|
118
120
|
modulePluginImport({
|
|
119
|
-
pluginImport: [
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
121
|
+
pluginImport: [
|
|
122
|
+
{
|
|
123
|
+
libraryName: 'foo',
|
|
124
|
+
customName: 'foo/es/{{ member }}',
|
|
125
|
+
},
|
|
126
|
+
],
|
|
123
127
|
}),
|
|
124
128
|
],
|
|
125
129
|
});
|
|
@@ -135,16 +139,19 @@ import { modulePluginImport } from '@modern-js/plugin-module-import';
|
|
|
135
139
|
export default defineConfig({
|
|
136
140
|
plugins: [
|
|
137
141
|
modulePluginImport({
|
|
138
|
-
pluginImport: [
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
+
pluginImport: [
|
|
143
|
+
{
|
|
144
|
+
libraryName: 'foo',
|
|
145
|
+
customName: 'foo/es/{{ member }}',
|
|
146
|
+
},
|
|
147
|
+
],
|
|
142
148
|
}),
|
|
143
149
|
],
|
|
144
150
|
});
|
|
145
151
|
```
|
|
146
152
|
|
|
147
153
|
---
|
|
154
|
+
|
|
148
155
|
After transformation:
|
|
149
156
|
|
|
150
157
|
```ts
|
|
@@ -159,16 +166,18 @@ The template used here is [handlebars](https://handlebarsjs.com). There are some
|
|
|
159
166
|
|
|
160
167
|
```ts focus=8:8
|
|
161
168
|
import { modulePluginImport } from '@modern-js/plugin-module-import';
|
|
162
|
-
import { moduleTools, defineConfig
|
|
169
|
+
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
163
170
|
|
|
164
171
|
export default defineConfig({
|
|
165
172
|
plugins: [
|
|
166
173
|
moduleTools(),
|
|
167
174
|
modulePluginImport({
|
|
168
|
-
pluginImport: [
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
175
|
+
pluginImport: [
|
|
176
|
+
{
|
|
177
|
+
libraryName: 'foo',
|
|
178
|
+
customName: 'foo/es/{{ kebabCase member }}',
|
|
179
|
+
},
|
|
180
|
+
],
|
|
172
181
|
}),
|
|
173
182
|
],
|
|
174
183
|
});
|
|
@@ -2,9 +2,20 @@
|
|
|
2
2
|
sidebar_position: 1
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# buildConfig
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`buildConfig` 是一个用来描述如何编译、生成构建产物的配置项,它包含了构建的所有配置。
|
|
8
|
+
|
|
9
|
+
- 类型:`object | object[]`
|
|
10
|
+
- 默认值: `undefined`
|
|
11
|
+
|
|
12
|
+
:::tip
|
|
13
|
+
在开始使用 `buildConfig` 之前,请先阅读以下文档来了解其作用:
|
|
14
|
+
|
|
15
|
+
- [修改输出产物](/guide/basic/modify-output-product.html)
|
|
16
|
+
- [深入理解构建](/guide/advance/in-depth-about-build.html)
|
|
17
|
+
|
|
18
|
+
:::
|
|
8
19
|
|
|
9
20
|
## alias
|
|
10
21
|
|
|
@@ -110,7 +121,7 @@ export default defineConfig({
|
|
|
110
121
|
|
|
111
122
|
打包时将 SVG 作为一个 React 组件处理,options 参考 [svgr](https://react-svgr.com/docs/options/),另外还支持了 `include` 和 `exclude` 两个配置项,用于匹配需要处理的 SVG 文件。
|
|
112
123
|
|
|
113
|
-
- 类型: `boolean |
|
|
124
|
+
- 类型: `boolean | object`
|
|
114
125
|
- 默认值: `false`
|
|
115
126
|
|
|
116
127
|
开启 svgr 功能后,可以使用默认导出的方式将 SVG 当做组件使用。
|
|
@@ -161,7 +172,7 @@ declare module '*.svg' {
|
|
|
161
172
|
|
|
162
173
|
自动外置项目的 `"dependencies"` 和 `"peerDependencies"`,不会将其打包到最终的 bundle 产物中。
|
|
163
174
|
|
|
164
|
-
- 类型: `boolean |
|
|
175
|
+
- 类型: `boolean | object`
|
|
165
176
|
- 默认值: `true`
|
|
166
177
|
|
|
167
178
|
当我们希望关闭对于第三方依赖的默认处理行为时候,可以通过以下方式来实现:
|
|
@@ -213,7 +224,7 @@ export default defineConfig({
|
|
|
213
224
|
|
|
214
225
|
将文件或目录拷贝到指定位置。
|
|
215
226
|
|
|
216
|
-
- 类型: `
|
|
227
|
+
- 类型: `object`
|
|
217
228
|
|
|
218
229
|
```js modern.config.ts
|
|
219
230
|
export default defineConfig({
|
|
@@ -295,7 +306,7 @@ export default defineConfig({
|
|
|
295
306
|
|
|
296
307
|
类型文件生成的相关配置,默认情况会生成。
|
|
297
308
|
|
|
298
|
-
- 类型: `false |
|
|
309
|
+
- 类型: `false | object`
|
|
299
310
|
- 默认值:
|
|
300
311
|
|
|
301
312
|
```js
|
|
@@ -435,24 +446,105 @@ export var yourCode = function () {
|
|
|
435
446
|
|
|
436
447
|
## externals
|
|
437
448
|
|
|
438
|
-
|
|
449
|
+
用于在打包时排除一些外部依赖,避免将这些依赖打包到最终的 bundle 中。
|
|
450
|
+
|
|
451
|
+
- 类型:
|
|
452
|
+
|
|
453
|
+
```ts
|
|
454
|
+
type Externals = (string | RegExp)[];
|
|
455
|
+
```
|
|
439
456
|
|
|
440
|
-
- 类型: `(string | RegExp)[]`
|
|
441
457
|
- 默认值: `[]`
|
|
458
|
+
- 构建类型:`仅支持 buildType: 'bundle'`
|
|
459
|
+
- 示例:
|
|
460
|
+
|
|
461
|
+
```js modern.config.ts
|
|
462
|
+
export default defineConfig({
|
|
463
|
+
buildConfig: {
|
|
464
|
+
// 避免打包 React
|
|
465
|
+
externals: ['react'],
|
|
466
|
+
},
|
|
467
|
+
});
|
|
468
|
+
```
|
|
442
469
|
|
|
443
470
|
## format
|
|
444
471
|
|
|
445
|
-
|
|
472
|
+
用于设置 JavaScript 产物输出的格式,其中 `iife` 和 `umd` 只在 `buildType` 为 `bundle` 时生效。
|
|
446
473
|
|
|
447
|
-
-
|
|
448
|
-
-
|
|
474
|
+
- 类型:`'esm' | 'cjs' | 'iife' | 'umd'`
|
|
475
|
+
- 默认值:`cjs`
|
|
476
|
+
|
|
477
|
+
### format: 'esm'
|
|
478
|
+
|
|
479
|
+
esm 代表 "ECMAScript 模块",它需要运行环境支持 import 和 export 语法。
|
|
480
|
+
|
|
481
|
+
- 示例:
|
|
482
|
+
|
|
483
|
+
```js modern.config.ts
|
|
484
|
+
export default defineConfig({
|
|
485
|
+
buildConfig: {
|
|
486
|
+
format: 'esm',
|
|
487
|
+
},
|
|
488
|
+
});
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
### format: 'cjs'
|
|
492
|
+
|
|
493
|
+
cjs 代表 "CommonJS",它需要运行环境支持 exports、require 和 module 语法,通常为 Node.js 环境。
|
|
494
|
+
|
|
495
|
+
- 示例:
|
|
496
|
+
|
|
497
|
+
```js modern.config.ts
|
|
498
|
+
export default defineConfig({
|
|
499
|
+
buildConfig: {
|
|
500
|
+
format: 'cjs',
|
|
501
|
+
},
|
|
502
|
+
});
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
### format: 'iife'
|
|
506
|
+
|
|
507
|
+
iife 代表 "立即调用函数表达式",它将代码包裹在函数表达式中,确保代码中的任何变量不会意外地与全局范围中的变量冲突,通常在浏览器环境中运行。
|
|
508
|
+
|
|
509
|
+
- 示例:
|
|
510
|
+
|
|
511
|
+
```js modern.config.ts
|
|
512
|
+
export default defineConfig({
|
|
513
|
+
buildConfig: {
|
|
514
|
+
format: 'iife',
|
|
515
|
+
},
|
|
516
|
+
});
|
|
517
|
+
```
|
|
518
|
+
|
|
519
|
+
### format: 'umd'
|
|
520
|
+
|
|
521
|
+
umd 代表 "Universal Module Definition",用于在不同环境(浏览器、Node.js 等)中运行。umd 格式的模块可以在多种环境下使用,既可以作为全局变量访问,也可以通过模块加载器(如 RequireJS)进行模块化加载。
|
|
522
|
+
|
|
523
|
+
- 示例:
|
|
524
|
+
|
|
525
|
+
```js modern.config.ts
|
|
526
|
+
export default defineConfig({
|
|
527
|
+
buildConfig: {
|
|
528
|
+
format: 'umd',
|
|
529
|
+
},
|
|
530
|
+
});
|
|
531
|
+
```
|
|
449
532
|
|
|
450
533
|
## input
|
|
451
534
|
|
|
452
535
|
指定构建的入口文件,数组形式可以指定目录。
|
|
453
536
|
|
|
454
|
-
- 类型:
|
|
455
|
-
|
|
537
|
+
- 类型:
|
|
538
|
+
|
|
539
|
+
```ts
|
|
540
|
+
type Input =
|
|
541
|
+
| string[];
|
|
542
|
+
| {
|
|
543
|
+
[name: string]: string;
|
|
544
|
+
}
|
|
545
|
+
```
|
|
546
|
+
|
|
547
|
+
- 默认值:`bundle` 模式下默认为 `['src/index.ts']`,`bundleless` 模式下默认为 `['src']`
|
|
456
548
|
|
|
457
549
|
**数组用法:**
|
|
458
550
|
|
|
@@ -483,28 +575,55 @@ export default defineConfig({
|
|
|
483
575
|
|
|
484
576
|
## jsx
|
|
485
577
|
|
|
486
|
-
指定 JSX 的编译方式,默认支持
|
|
578
|
+
指定 JSX 的编译方式,默认支持 React 17 及更高版本,自动注入 JSX 运行时代码。
|
|
487
579
|
|
|
488
|
-
> 关于 JSX Transform,可以参考以下链接:
|
|
489
|
-
>
|
|
490
|
-
> - [React Blog](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)。
|
|
491
|
-
> - [esbuild JSX](https://esbuild.github.io/api/#jsx)
|
|
492
|
-
>
|
|
493
580
|
- 类型: `automatic | transform`
|
|
494
581
|
- 默认值: `automatic`
|
|
495
582
|
|
|
583
|
+
如果你需要支持 React 16,则可以设置 `jsx` 为 `transform`:
|
|
584
|
+
|
|
585
|
+
```js modern.config.ts
|
|
586
|
+
export default defineConfig({
|
|
587
|
+
buildConfig: {
|
|
588
|
+
jsx: 'transform',
|
|
589
|
+
},
|
|
590
|
+
});
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
:::tip
|
|
594
|
+
关于 JSX Transform 的更多说明,可以参考以下链接:
|
|
595
|
+
|
|
596
|
+
- [React Blog - Introducing the New JSX Transform](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html).
|
|
597
|
+
- [esbuild - JSX](https://esbuild.github.io/api/#jsx).
|
|
598
|
+
|
|
599
|
+
:::
|
|
600
|
+
|
|
496
601
|
## metafile
|
|
497
602
|
|
|
498
|
-
esbuild
|
|
603
|
+
这个选项用于构建分析,开启该选项后,esbuild 会以 JSON 格式生成有关构建的一些元数据。
|
|
499
604
|
|
|
500
605
|
- 类型:`boolean`
|
|
501
606
|
- 默认值:`false`
|
|
607
|
+
- 构建类型:`仅支持 buildType: 'bundle'`
|
|
608
|
+
|
|
609
|
+
开启 `metafile` 生成:
|
|
610
|
+
|
|
611
|
+
```js modern.config.ts
|
|
612
|
+
export default defineConfig({
|
|
613
|
+
buildConfig: {
|
|
614
|
+
buildType: 'bundle',
|
|
615
|
+
metafile: true,
|
|
616
|
+
},
|
|
617
|
+
});
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
在执行 build 构建后,产物目录下会生成 `metafile-[xxx].json` 文件,你可以通过 [esbuild analyze](https://esbuild.github.io/analyze/) 和 [bundle-buddy](https://bundle-buddy.com/esbuild) 等工具进行可视化分析。
|
|
502
621
|
|
|
503
622
|
## minify
|
|
504
623
|
|
|
505
624
|
使用 esbuild 或者 terser 压缩代码,也可以传入 [terserOptions](https://github.com/terser/terser#minify-options)。
|
|
506
625
|
|
|
507
|
-
- 类型: `'terser' | 'esbuild' | false |
|
|
626
|
+
- 类型: `'terser' | 'esbuild' | false | object`
|
|
508
627
|
- 默认值: `false`
|
|
509
628
|
|
|
510
629
|
```js modern.config.ts
|
|
@@ -616,8 +735,8 @@ export default defineConfig({
|
|
|
616
735
|
|
|
617
736
|
设置源码的格式。默认情况下,会将源码作为 EsModule 进行处理。当源码使用的是 CommonJS 的时候,需要设置 `commonjs`。
|
|
618
737
|
|
|
619
|
-
- 类型:`commonjs
|
|
620
|
-
- 默认值:`module`
|
|
738
|
+
- 类型:`'commonjs' | 'module'`
|
|
739
|
+
- 默认值:`'module'`
|
|
621
740
|
|
|
622
741
|
## splitting
|
|
623
742
|
|
|
@@ -638,7 +757,7 @@ less 相关配置。
|
|
|
638
757
|
|
|
639
758
|
详细配置参考 [less](https://less.bootcss.com/usage/#less-options)。
|
|
640
759
|
|
|
641
|
-
- 类型: `
|
|
760
|
+
- 类型: `object`
|
|
642
761
|
- 默认值: `{ javascriptEnabled: true }`
|
|
643
762
|
|
|
644
763
|
## style.less.additionalData
|
|
@@ -664,10 +783,10 @@ export default defineConfig({
|
|
|
664
783
|
|
|
665
784
|
配置 `Less` 使用的实现库,在不指定的情况下,使用的内置版本是 `4.1.3`。
|
|
666
785
|
|
|
667
|
-
- 类型: `string |
|
|
786
|
+
- 类型: `string | object`
|
|
668
787
|
- 默认值: `undefined`
|
|
669
788
|
|
|
670
|
-
`
|
|
789
|
+
设置 `object` 类型时,可以指定 `Less` 的实现库。
|
|
671
790
|
|
|
672
791
|
```js modern.config.ts
|
|
673
792
|
export default defineConfig({
|
|
@@ -703,7 +822,7 @@ Sass 相关配置。
|
|
|
703
822
|
|
|
704
823
|
详细配置参考 [node-sass](https://github.com/sass/node-sass#options)
|
|
705
824
|
|
|
706
|
-
- 类型: `
|
|
825
|
+
- 类型: `object`
|
|
707
826
|
- 默认值: `{}`
|
|
708
827
|
|
|
709
828
|
## style.sass.additionalData
|
|
@@ -730,10 +849,10 @@ export default defineConfig({
|
|
|
730
849
|
|
|
731
850
|
配置 `Sass` 使用的实现库,在不指定的情况下,使用的内置版本是 `1.5.4`。
|
|
732
851
|
|
|
733
|
-
- 类型: `string |
|
|
852
|
+
- 类型: `string | object`
|
|
734
853
|
- 默认值: `undefined`
|
|
735
854
|
|
|
736
|
-
`
|
|
855
|
+
设置为 `object` 类型时,可以指定 `Sass` 的实现库。
|
|
737
856
|
|
|
738
857
|
```js modern.config.ts
|
|
739
858
|
export default defineConfig({
|
|
@@ -770,14 +889,12 @@ export default defineConfig({
|
|
|
770
889
|
|
|
771
890
|
**基础使用:**
|
|
772
891
|
|
|
773
|
-
```
|
|
892
|
+
```js modern.config.ts
|
|
774
893
|
export default defineConfig({
|
|
775
894
|
buildConfig: {
|
|
776
895
|
style: {
|
|
777
896
|
postcss: {
|
|
778
|
-
plugins: [
|
|
779
|
-
yourPostCSSPlugin,
|
|
780
|
-
],
|
|
897
|
+
plugins: [yourPostCSSPlugin],
|
|
781
898
|
},
|
|
782
899
|
},
|
|
783
900
|
},
|
|
@@ -847,9 +964,9 @@ style_inject_es_default(css_248z);
|
|
|
847
964
|
|
|
848
965
|
## style.modules
|
|
849
966
|
|
|
850
|
-
CSS Modules
|
|
967
|
+
CSS Modules 配置。
|
|
851
968
|
|
|
852
|
-
- 类型: `
|
|
969
|
+
- 类型: `object`
|
|
853
970
|
- 默认值: `{}`
|
|
854
971
|
|
|
855
972
|
一个常用的配置是 `localsConvention`,它可以改变 CSS Modules 的类名生成规则。
|
|
@@ -874,7 +991,7 @@ export default defineConfig({
|
|
|
874
991
|
}
|
|
875
992
|
```
|
|
876
993
|
|
|
877
|
-
你可以使用 `styles.boxTitle`
|
|
994
|
+
你可以使用 `styles.boxTitle` 来访问。
|
|
878
995
|
|
|
879
996
|
详细配置查看 [postcss-modules](https://github.com/madyankin/postcss-modules#usage)
|
|
880
997
|
|
|
@@ -882,7 +999,7 @@ export default defineConfig({
|
|
|
882
999
|
|
|
883
1000
|
Tailwind CSS 相关配置。
|
|
884
1001
|
|
|
885
|
-
- 类型: `
|
|
1002
|
+
- 类型: `object | Function`
|
|
886
1003
|
- 默认值: `见下方配置详情`
|
|
887
1004
|
|
|
888
1005
|
<details>
|
|
@@ -903,7 +1020,7 @@ const tailwind = {
|
|
|
903
1020
|
};
|
|
904
1021
|
```
|
|
905
1022
|
|
|
906
|
-
值为 `
|
|
1023
|
+
值为 `object` 类型时,与默认配置通过 `Object.assign` 合并。
|
|
907
1024
|
|
|
908
1025
|
值为 `Function` 类型时,函数返回的对象与默认配置通过 `Object.assign` 合并。
|
|
909
1026
|
|
|
@@ -948,7 +1065,7 @@ export default defineConfig({
|
|
|
948
1065
|
|
|
949
1066
|
提供与 babel-plugin-import 等价的能力和配置,基于 SWC 实现。
|
|
950
1067
|
|
|
951
|
-
- 类型:`
|
|
1068
|
+
- 类型:`object[]`
|
|
952
1069
|
- 默认值:`[]`
|
|
953
1070
|
|
|
954
1071
|
数组元素为一个 babel-plugin-import 的配置对象。配置对象可以参考 [options](https://github.com/umijs/babel-plugin-import#options)。
|
|
@@ -971,7 +1088,7 @@ export default defineConfig({
|
|
|
971
1088
|
|
|
972
1089
|
### 注意事项
|
|
973
1090
|
|
|
974
|
-
参考[
|
|
1091
|
+
参考[「Import 插件——注意事项」](plugins/official-list/plugin-import.html#注意事项)
|
|
975
1092
|
|
|
976
1093
|
## umdGlobals
|
|
977
1094
|
|
|
@@ -997,7 +1114,7 @@ export default defineConfig({
|
|
|
997
1114
|
|
|
998
1115
|
指定 UMD 产物的模块名。
|
|
999
1116
|
|
|
1000
|
-
- 类型: `string
|
|
1117
|
+
- 类型: `string | Function`
|
|
1001
1118
|
- 默认值: `name => name`
|
|
1002
1119
|
|
|
1003
1120
|
```js modern.config.ts
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
sidebar_position: 3
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# designSystem
|
|
6
6
|
|
|
7
|
-
本章描述了有关 designSystem
|
|
7
|
+
本章描述了有关 designSystem 相关的配置。
|
|
8
8
|
|
|
9
9
|
:::tip
|
|
10
10
|
需要先通过 `pnpm run new` 启用 Tailwind CSS 功能。
|
|
11
11
|
:::
|
|
12
12
|
|
|
13
|
-
- 类型:`
|
|
13
|
+
- 类型:`object`
|
|
14
14
|
- 默认值: `见下方配置详情`。
|
|
15
15
|
|
|
16
16
|
<details>
|
|
@@ -2,16 +2,18 @@
|
|
|
2
2
|
sidebar_position: 3
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# dev
|
|
6
6
|
|
|
7
7
|
本章节描述了 Module Tools 关于调试工具相关的所有配置。
|
|
8
8
|
|
|
9
|
-
```
|
|
9
|
+
```ts
|
|
10
10
|
export default {
|
|
11
11
|
dev: {
|
|
12
|
-
storybook: {
|
|
12
|
+
storybook: {
|
|
13
|
+
/* Storybook Config */
|
|
14
|
+
},
|
|
13
15
|
},
|
|
14
|
-
}
|
|
16
|
+
};
|
|
15
17
|
```
|
|
16
18
|
|
|
17
19
|
## storybook
|
|
@@ -21,36 +23,34 @@ export default {
|
|
|
21
23
|
- 开启 Storybook 调试功能或者安装 `@modern-js/plugin-storybook` 插件。
|
|
22
24
|
- 注册 `@modern-js/plugin-storybook` 插件。
|
|
23
25
|
|
|
24
|
-
> 关于如何开启 Storybook 调试功能,可以参考:[
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
> 关于如何开启 Storybook 调试功能,可以参考:[「Storybook 调试」](guide/basic/use-micro-generator#storybook-调试)
|
|
27
27
|
|
|
28
28
|
### storybook.webpack
|
|
29
29
|
|
|
30
|
-
- 类型:`
|
|
31
|
-
|
|
30
|
+
- 类型:`object | Function | undefined`
|
|
32
31
|
- 默认值:`undefined`
|
|
33
32
|
|
|
34
|
-
```
|
|
33
|
+
```ts
|
|
35
34
|
export default {
|
|
36
35
|
dev: {
|
|
37
36
|
storybook: {
|
|
38
37
|
webpack(config) {
|
|
39
38
|
return config;
|
|
40
39
|
},
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
}
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
};
|
|
44
43
|
```
|
|
45
44
|
|
|
46
|
-
你可以通过 `dev.storybook.webpack` 来修改 Storybook Preview-iframe 的 webpack 配置。使用方式可以参考 Modern.js Builder 的 [`tools.webpack`](https://modernjs.dev/builder/api/config-tools.html#
|
|
45
|
+
你可以通过 `dev.storybook.webpack` 来修改 Storybook Preview-iframe 的 webpack 配置。使用方式可以参考 Modern.js Builder 的 [`tools.webpack`](https://modernjs.dev/builder/api/config-tools.html#toolswebpack) 配置。
|
|
47
46
|
|
|
48
47
|

|
|
49
48
|
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
#### 配置 Manager App
|
|
50
|
+
|
|
51
|
+
对于 Storybook Manager App 部分的 webpack 配置,可以通过增加 `./config/storybook/main.js` 文件进行配置。
|
|
52
52
|
|
|
53
|
-
```
|
|
53
|
+
```js
|
|
54
54
|
// ./config/storybook/main.js
|
|
55
55
|
|
|
56
56
|
module.exports = {
|
|
@@ -61,25 +61,22 @@ module.exports = {
|
|
|
61
61
|
},
|
|
62
62
|
};
|
|
63
63
|
```
|
|
64
|
-
:::
|
|
65
|
-
|
|
66
64
|
|
|
67
65
|
### storybook.webpackChain
|
|
68
66
|
|
|
69
|
-
- 类型:`Function
|
|
70
|
-
|
|
67
|
+
- 类型:`Function | undefined`
|
|
71
68
|
- 默认值:`undefined`
|
|
72
69
|
|
|
73
|
-
```
|
|
70
|
+
```ts
|
|
74
71
|
export default {
|
|
75
72
|
dev: {
|
|
76
73
|
storybook: {
|
|
77
74
|
webpackChain(chain) {
|
|
78
75
|
return chain;
|
|
79
76
|
},
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
}
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
83
80
|
```
|
|
84
81
|
|
|
85
|
-
你可以通过 `dev.storybook.webpackChain` 来修改 Storybook Preview-iframe 的 webpack 配置。使用方式可以参考 Modern.js Builder 的 [`tools.webpackChain`](https://modernjs.dev/builder/api/config-tools.html#
|
|
82
|
+
你可以通过 `dev.storybook.webpackChain` 来修改 Storybook Preview-iframe 的 webpack 配置。使用方式可以参考 Modern.js Builder 的 [`tools.webpackChain`](https://modernjs.dev/builder/api/config-tools.html#toolswebpackchain) 配置。
|