@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
package/CHANGELOG.md
CHANGED
|
@@ -2,9 +2,20 @@
|
|
|
2
2
|
sidebar_position: 1
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# buildConfig
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
`buildConfig` is a configuration option that describes how to compile and generate build artifacts. It contains all the configurations related to the build process.
|
|
8
|
+
|
|
9
|
+
- **Type**: `object | object[]`
|
|
10
|
+
- **Default**: `undefined`
|
|
11
|
+
|
|
12
|
+
:::tip
|
|
13
|
+
Before start using `buildConfig`, please read the following documentation to understand its purpose:
|
|
14
|
+
|
|
15
|
+
- [Modifying Output Artifacts](/guide/basic/modify-output-product.html)
|
|
16
|
+
- [In-Depth Understanding of the Build Process](/guide/advance/in-depth-about-build.html)
|
|
17
|
+
|
|
18
|
+
:::
|
|
8
19
|
|
|
9
20
|
## alias
|
|
10
21
|
|
|
@@ -110,7 +121,7 @@ At this point, all static resources will be prefixed with `https://xxx/`
|
|
|
110
121
|
|
|
111
122
|
Packaged to handle svg as a React component, options reference [svgr](https://react-svgr.com/docs/options/), plus support for two configuration items `include` and `exclude` to match the svg file to be handled
|
|
112
123
|
|
|
113
|
-
- **Type**: `boolean |
|
|
124
|
+
- **Type**: `boolean | object`
|
|
114
125
|
- **Default**: `false`
|
|
115
126
|
|
|
116
127
|
When svgr feature is enabled, you can use svg as a component using the default export.
|
|
@@ -160,7 +171,7 @@ Set unmatched svg files
|
|
|
160
171
|
|
|
161
172
|
Automatically externalize project dependencies and peerDependencies and not package them into the final bundle
|
|
162
173
|
|
|
163
|
-
- **Type**: `boolean |
|
|
174
|
+
- **Type**: `boolean | object`
|
|
164
175
|
- **Default**: `true`
|
|
165
176
|
|
|
166
177
|
When we want to turn off the default handling behavior for third-party dependencies, we can do so by:
|
|
@@ -212,7 +223,7 @@ The build type, `bundle` will package your code, `bundleless` will only do the c
|
|
|
212
223
|
|
|
213
224
|
Copies the specified file or directory into the build output directory
|
|
214
225
|
|
|
215
|
-
- **Type**: `
|
|
226
|
+
- **Type**: `object[]`
|
|
216
227
|
- **Default**: `[]`
|
|
217
228
|
|
|
218
229
|
```js
|
|
@@ -295,7 +306,7 @@ The use of SWC Transform can reduce the impact of auxiliary functions on the vol
|
|
|
295
306
|
|
|
296
307
|
The dts file generates the relevant configuration, by default it generates.
|
|
297
308
|
|
|
298
|
-
- **Type**: `false |
|
|
309
|
+
- **Type**: `false | object`
|
|
299
310
|
- **Default**:
|
|
300
311
|
|
|
301
312
|
```js
|
|
@@ -438,21 +449,102 @@ export var yourCode = function () {
|
|
|
438
449
|
|
|
439
450
|
Configure external dependencies that will not be packaged into the final bundle
|
|
440
451
|
|
|
441
|
-
- **Type**:
|
|
452
|
+
- **Type**:
|
|
453
|
+
|
|
454
|
+
```ts
|
|
455
|
+
type External = (string | RegExp)[];
|
|
456
|
+
```
|
|
457
|
+
|
|
442
458
|
- **Default**: `[]`
|
|
459
|
+
- **Build Type**: `Only supported for buildType: 'bundle'`
|
|
460
|
+
- **Example**:
|
|
461
|
+
|
|
462
|
+
```js modern.config.ts
|
|
463
|
+
export default defineConfig({
|
|
464
|
+
buildConfig: {
|
|
465
|
+
// do not bundle React
|
|
466
|
+
externals: ['react'],
|
|
467
|
+
},
|
|
468
|
+
});
|
|
469
|
+
```
|
|
443
470
|
|
|
444
471
|
## format
|
|
445
472
|
|
|
446
|
-
|
|
473
|
+
Used to set the output format of JavaScript files. The options `iife` and `umd` only take effect when `buildType` is `bundle`.
|
|
447
474
|
|
|
448
475
|
- **Type**: `'esm' | 'cjs' | 'iife' | 'umd'`
|
|
449
476
|
- **Default**: `cjs`
|
|
450
477
|
|
|
478
|
+
### format: 'esm'
|
|
479
|
+
|
|
480
|
+
`esm` stands for "ECMAScript module" and requires the runtime environment to support import and export syntax.
|
|
481
|
+
|
|
482
|
+
- **Example**:
|
|
483
|
+
|
|
484
|
+
```js modern.config.ts
|
|
485
|
+
export default defineConfig({
|
|
486
|
+
buildConfig: {
|
|
487
|
+
format: 'esm',
|
|
488
|
+
},
|
|
489
|
+
});
|
|
490
|
+
```
|
|
491
|
+
|
|
492
|
+
### format: 'cjs'
|
|
493
|
+
|
|
494
|
+
`cjs` stands for "CommonJS" and requires the runtime environment to support exports, require, and module syntax. This format is commonly used in Node.js environments.
|
|
495
|
+
|
|
496
|
+
- **Example**:
|
|
497
|
+
|
|
498
|
+
```js modern.config.ts
|
|
499
|
+
export default defineConfig({
|
|
500
|
+
buildConfig: {
|
|
501
|
+
format: 'cjs',
|
|
502
|
+
},
|
|
503
|
+
});
|
|
504
|
+
```
|
|
505
|
+
|
|
506
|
+
### format: 'iife'
|
|
507
|
+
|
|
508
|
+
`iife` stands for "immediately-invoked function expression" and wraps the code in a function expression to ensure that any variables in the code do not accidentally conflict with variables in the global scope. This format is commonly used in browser environments.
|
|
509
|
+
|
|
510
|
+
- **Example**:
|
|
511
|
+
|
|
512
|
+
```js modern.config.ts
|
|
513
|
+
export default defineConfig({
|
|
514
|
+
buildConfig: {
|
|
515
|
+
format: 'iife',
|
|
516
|
+
},
|
|
517
|
+
});
|
|
518
|
+
```
|
|
519
|
+
|
|
520
|
+
### format: 'umd'
|
|
521
|
+
|
|
522
|
+
`umd` stands for "Universal Module Definition" and is used to run modules in different environments such as browsers and Node.js. Modules in UMD format can be used in various environments, either as global variables or loaded as modules using module loaders like RequireJS.
|
|
523
|
+
|
|
524
|
+
- **Example**:
|
|
525
|
+
|
|
526
|
+
```js modern.config.ts
|
|
527
|
+
export default defineConfig({
|
|
528
|
+
buildConfig: {
|
|
529
|
+
format: 'umd',
|
|
530
|
+
},
|
|
531
|
+
});
|
|
532
|
+
```
|
|
533
|
+
|
|
451
534
|
## input
|
|
452
535
|
|
|
453
536
|
Specify the entry file for the build, in the form of an array that can specify the directory
|
|
454
537
|
|
|
455
|
-
- **Type**:
|
|
538
|
+
- **Type**:
|
|
539
|
+
|
|
540
|
+
```ts
|
|
541
|
+
type Input =
|
|
542
|
+
| string[];
|
|
543
|
+
| {
|
|
544
|
+
[name: string]: string;
|
|
545
|
+
}
|
|
546
|
+
```
|
|
547
|
+
|
|
456
548
|
- **Default**: `['src/index.ts']` in `bundle` mode, `['src']` in `bundleless` mode
|
|
457
549
|
|
|
458
550
|
**Array usage:**
|
|
@@ -484,29 +576,54 @@ export default defineConfig({
|
|
|
484
576
|
|
|
485
577
|
## jsx
|
|
486
578
|
|
|
487
|
-
Specify the compilation method
|
|
488
|
-
|
|
489
|
-
> For more information about JSX Transform, you can refer to the following links:
|
|
490
|
-
>
|
|
491
|
-
> - [React Blog](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html)。
|
|
492
|
-
> - [esbuild JSX](https://esbuild.github.io/api/#jsx)
|
|
493
|
-
>
|
|
579
|
+
Specify the compilation method for JSX, which by default supports React 17 and higher versions and automatically injects JSX runtime code.
|
|
494
580
|
|
|
495
581
|
- **Type**: `automatic | transform`
|
|
496
582
|
- **Default**: `automatic`
|
|
497
583
|
|
|
584
|
+
If you need to support React 16, you can set `jsx` to `transform`:
|
|
585
|
+
|
|
586
|
+
```js modern.config.ts
|
|
587
|
+
export default defineConfig({
|
|
588
|
+
buildConfig: {
|
|
589
|
+
jsx: 'transform',
|
|
590
|
+
},
|
|
591
|
+
});
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
:::tip
|
|
595
|
+
For more information about JSX Transform, you can refer to the following links:
|
|
596
|
+
|
|
597
|
+
- [React Blog - Introducing the New JSX Transform](https://legacy.reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html).
|
|
598
|
+
- [esbuild - JSX](https://esbuild.github.io/api/#jsx).
|
|
599
|
+
:::
|
|
600
|
+
|
|
498
601
|
## metafile
|
|
499
602
|
|
|
500
|
-
|
|
603
|
+
This option is used for build analysis. When enabled, esbuild will generate metadata about the build in JSON format.
|
|
501
604
|
|
|
502
605
|
- **Type**: `boolean`
|
|
503
606
|
- **Default**: `false`
|
|
607
|
+
- **Build Type**: `Only supported for buildType: 'bundle'`
|
|
608
|
+
|
|
609
|
+
To enable `metafile` generation:
|
|
610
|
+
|
|
611
|
+
```js modern.config.ts
|
|
612
|
+
export default defineConfig({
|
|
613
|
+
buildConfig: {
|
|
614
|
+
buildType: 'bundle',
|
|
615
|
+
metafile: true,
|
|
616
|
+
},
|
|
617
|
+
});
|
|
618
|
+
```
|
|
619
|
+
|
|
620
|
+
After executing the build, a `metafile-[xxx].json` file will be generated in the output directory. You can use tools like [esbuild analyze](https://esbuild.github.io/analyze/) and [bundle-buddy](https://bundle-buddy.com/esbuild) for visual analysis.
|
|
504
621
|
|
|
505
622
|
## minify
|
|
506
623
|
|
|
507
624
|
Use esbuild or terser to compress code, also pass [terserOptions](https://github.com/terser/terser#minify-options)
|
|
508
625
|
|
|
509
|
-
- **Type**: `'terser' | 'esbuild' | false |
|
|
626
|
+
- **Type**: `'terser' | 'esbuild' | false | object`
|
|
510
627
|
- **Default**: `false`
|
|
511
628
|
|
|
512
629
|
```js modern.config.ts
|
|
@@ -617,8 +734,8 @@ Whether to generate sourceMap or not
|
|
|
617
734
|
|
|
618
735
|
Sets the format of the source code. By default, the source code will be treated as EsModule. When the source code is using CommonJS, you need to set `commonjs`.
|
|
619
736
|
|
|
620
|
-
- **Type**: `commonjs
|
|
621
|
-
- **Default**: `module`
|
|
737
|
+
- **Type**: `'commonjs' | 'module'`
|
|
738
|
+
- **Default**: `'module'`
|
|
622
739
|
|
|
623
740
|
## splitting
|
|
624
741
|
|
|
@@ -639,7 +756,7 @@ less-related configuration
|
|
|
639
756
|
|
|
640
757
|
Refer to [less](https://less.bootcss.com/usage/#less-options) for detailed configuration
|
|
641
758
|
|
|
642
|
-
- **Type**: `
|
|
759
|
+
- **Type**: `object`
|
|
643
760
|
- **Default**: `{ javascriptEnabled: true }`
|
|
644
761
|
|
|
645
762
|
## style.less.additionalData
|
|
@@ -663,12 +780,12 @@ export default {
|
|
|
663
780
|
|
|
664
781
|
## style.less.implementation
|
|
665
782
|
|
|
666
|
-
Configure the implementation library used by `Less`, if not specified, the built-in version used is `4.1.3
|
|
783
|
+
Configure the implementation library used by `Less`, if not specified, the built-in version used is `4.1.3`.
|
|
667
784
|
|
|
668
|
-
- **Type**: `string |
|
|
785
|
+
- **Type**: `string | object`
|
|
669
786
|
- **Default**: `undefined`
|
|
670
787
|
|
|
671
|
-
Specify the implementation library for `Less` when the `
|
|
788
|
+
Specify the implementation library for `Less` when the `object` type is specified.
|
|
672
789
|
|
|
673
790
|
```js modern.config.ts
|
|
674
791
|
export default {
|
|
@@ -702,9 +819,9 @@ sass-related configuration.
|
|
|
702
819
|
|
|
703
820
|
## style.sass.sassOptions
|
|
704
821
|
|
|
705
|
-
Refer to [node-sass](https://github.com/sass/node-sass#options) for detailed configuration
|
|
822
|
+
Refer to [node-sass](https://github.com/sass/node-sass#options) for detailed configuration.
|
|
706
823
|
|
|
707
|
-
- **Type**: `
|
|
824
|
+
- **Type**: `object`
|
|
708
825
|
- **Default**: `{}`
|
|
709
826
|
|
|
710
827
|
## style.sass.additionalData
|
|
@@ -729,12 +846,12 @@ export default {
|
|
|
729
846
|
|
|
730
847
|
## style.sass.implementation
|
|
731
848
|
|
|
732
|
-
Configure the implementation library used by `Sass`, the built-in version used is `1.5.4` if not specified
|
|
849
|
+
Configure the implementation library used by `Sass`, the built-in version used is `1.5.4` if not specified.
|
|
733
850
|
|
|
734
|
-
- **Type**: `string |
|
|
851
|
+
- **Type**: `string | object`
|
|
735
852
|
- **Default**: `undefined`
|
|
736
853
|
|
|
737
|
-
Specify the implementation library for `Sass` when the `
|
|
854
|
+
Specify the implementation library for `Sass` when the `object` type is specified.
|
|
738
855
|
|
|
739
856
|
```js modern.config.ts
|
|
740
857
|
export default {
|
|
@@ -771,14 +888,12 @@ See [PostCSS](https://github.com/postcss/postcss#options) for detailed configura
|
|
|
771
888
|
|
|
772
889
|
**Basic usage:**
|
|
773
890
|
|
|
774
|
-
```
|
|
891
|
+
```js modern.config.ts
|
|
775
892
|
export default defineConfig({
|
|
776
893
|
buildConfig: {
|
|
777
894
|
style: {
|
|
778
895
|
postcss: {
|
|
779
|
-
plugins: [
|
|
780
|
-
yourPostCSSPlugin,
|
|
781
|
-
],
|
|
896
|
+
plugins: [yourPostCSSPlugin],
|
|
782
897
|
},
|
|
783
898
|
},
|
|
784
899
|
},
|
|
@@ -848,7 +963,7 @@ Enable CSS Modules automatically based on the filename.
|
|
|
848
963
|
|
|
849
964
|
CSS Modules configuration
|
|
850
965
|
|
|
851
|
-
- **Type**: `
|
|
966
|
+
- **Type**: `object`
|
|
852
967
|
- **Default**: `{}`
|
|
853
968
|
|
|
854
969
|
A common configuration is `localsConvention`, which changes the class name generation rules for css modules
|
|
@@ -881,7 +996,7 @@ For detailed configuration see [postcss-modules](https://github.com/madyankin/po
|
|
|
881
996
|
|
|
882
997
|
tailwindcss related configuration
|
|
883
998
|
|
|
884
|
-
- **Type**: `
|
|
999
|
+
- **Type**: `object | Function`
|
|
885
1000
|
- **Default**: `see configuration details below`
|
|
886
1001
|
|
|
887
1002
|
<details>
|
|
@@ -902,7 +1017,7 @@ const tailwind = {
|
|
|
902
1017
|
};
|
|
903
1018
|
```
|
|
904
1019
|
|
|
905
|
-
When the value is of type `
|
|
1020
|
+
When the value is of type `object`, it is merged with the default configuration via `Object.assign`.
|
|
906
1021
|
|
|
907
1022
|
When the value is of type `Function`, the object returned by the function is merged with the default configuration via `Object.assign`.
|
|
908
1023
|
|
|
@@ -947,7 +1062,7 @@ export default defineConfig({
|
|
|
947
1062
|
|
|
948
1063
|
Using [SWC](https://swc.rs/) provides the same ability and configuration as [`babel-plugin-import`](https://github.com/umijs/babel-plugin-import).
|
|
949
1064
|
|
|
950
|
-
- **Type**: `
|
|
1065
|
+
- **Type**: `object[]`
|
|
951
1066
|
- **Default**: `[]`
|
|
952
1067
|
|
|
953
1068
|
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)。
|
|
@@ -996,7 +1111,7 @@ At this point, `react` and `react-dom` will be seen as global variables imported
|
|
|
996
1111
|
|
|
997
1112
|
Specifies the module name of the umd product
|
|
998
1113
|
|
|
999
|
-
- **Type**: `string
|
|
1114
|
+
- **Type**: `string | Function`
|
|
1000
1115
|
- **Default**: `name => name`
|
|
1001
1116
|
|
|
1002
1117
|
```js
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
sidebar_position: 2
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# buildPreset
|
|
6
6
|
|
|
7
7
|
A build preset string or preset function. Provides out-of-the-box build configuration
|
|
8
8
|
|
|
9
|
-
- Type
|
|
10
|
-
- Default
|
|
9
|
+
- **Type**: `string | Function`
|
|
10
|
+
- **Default**: `undefined`
|
|
11
11
|
|
|
12
12
|
## string
|
|
13
13
|
|
|
@@ -2,15 +2,15 @@
|
|
|
2
2
|
sidebar_position: 3
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# designSystem
|
|
6
6
|
|
|
7
|
-
This chapter describes the configuration related to designSystem
|
|
7
|
+
This chapter describes the configuration related to designSystem.
|
|
8
8
|
|
|
9
9
|
:::tip
|
|
10
10
|
The Tailwind CSS feature needs to be enabled first via `pnpm run new`.
|
|
11
11
|
:::
|
|
12
12
|
|
|
13
|
-
- Type: `
|
|
13
|
+
- Type: `object`
|
|
14
14
|
- Default: `see configuration details below`.
|
|
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
|
This section describes all configuration of Module Tools related to debugging 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
|
- Turn on Storybook debugging or install the `@modern-js/plugin-storybook` plugin.
|
|
22
24
|
- Register the `@modern-js/plugin-storybook` plugin。
|
|
23
25
|
|
|
24
|
-
> For more information on how to enable Storybook debugging, please refer to:[
|
|
25
|
-
|
|
26
|
-
|
|
26
|
+
> For more information on how to enable Storybook debugging, please refer to:["Storybook"](guide/basic/use-micro-generator#storybook)
|
|
27
27
|
|
|
28
28
|
### storybook.webpack
|
|
29
29
|
|
|
30
|
-
- **Type**: `
|
|
31
|
-
|
|
30
|
+
- **Type**: `object | Function | undefined`
|
|
32
31
|
- **Default**: `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
|
-
You can modify the webpack configuration of the Storybook Preview-iframe via `dev.storybook.webpack`. The usage can be found in the [`tools.webpack`](https://modernjs.dev/builder/api/config-tools.html#
|
|
45
|
+
You can modify the webpack configuration of the Storybook Preview-iframe via `dev.storybook.webpack`. The usage can be found in the [`tools.webpack`](https://modernjs.dev/builder/en/api/config-tools.html#toolswebpack) configuration of Modern.js Builder.
|
|
47
46
|
|
|
48
47
|

|
|
49
48
|
|
|
50
|
-
|
|
49
|
+
#### Configure Manager App
|
|
50
|
+
|
|
51
51
|
For the webpack configuration of the Storybook Manager app section, you can configure it by adding the `./config/storybook/main.js` file to configure it.
|
|
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
64
|
|
|
66
65
|
### storybook.webpackChain
|
|
67
66
|
|
|
68
|
-
- **Type**: `Function
|
|
69
|
-
|
|
67
|
+
- **Type**: `Function | undefined`
|
|
70
68
|
- **Default**: `undefined`
|
|
71
69
|
|
|
72
|
-
```
|
|
70
|
+
```ts
|
|
73
71
|
export default {
|
|
74
72
|
dev: {
|
|
75
73
|
storybook: {
|
|
76
74
|
webpackChain(chain) {
|
|
77
75
|
return chain;
|
|
78
76
|
},
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
}
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
};
|
|
82
80
|
```
|
|
83
81
|
|
|
84
|
-
You can modify the webpack configuration of the Storybook Preview-iframe via `dev.storybook.webpackChain`. You can refer to Modern.js Builder's [`tools.webpackChain`](https://modernjs.dev/builder/api/config-tools.html#
|
|
85
|
-
|
|
82
|
+
You can modify the webpack configuration of the Storybook Preview-iframe via `dev.storybook.webpackChain`. You can refer to Modern.js Builder's [`tools.webpackChain`](https://modernjs.dev/builder/en/api/config-tools.html#toolswebpackchain) configuration for how to use it.
|
|
@@ -2,17 +2,62 @@
|
|
|
2
2
|
sidebar_position: 4
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# plugins
|
|
6
6
|
|
|
7
7
|
This chapter describes the configuration of the registered Module Tools plugin.
|
|
8
8
|
|
|
9
|
-
- Type
|
|
9
|
+
- **Type**: `ModuleToolsPlugin[]`
|
|
10
|
+
- **Default**: `undefined`
|
|
11
|
+
|
|
12
|
+
## Plugin Execution Order
|
|
13
|
+
|
|
14
|
+
By default, custom plugins are executed in the order specified in the `plugins` array. The execution of built-in plugins provided by Module Tools happens before the execution of custom plugins.
|
|
15
|
+
|
|
16
|
+
When plugins use fields that control the execution order, such as `pre` and `post`, the execution order is adjusted based on the declared fields. For more information, please refer to the [Relationship Between Plugins](https://modernjs.dev/en/guides/topic-detail/framework-plugin/relationship) guide.
|
|
17
|
+
|
|
18
|
+
## Developing Plugins
|
|
19
|
+
|
|
20
|
+
To learn how to write plugins, please refer to the [Plugin Writing Guide](/plugins/guide/getting-started).
|
|
21
|
+
|
|
22
|
+
## Example
|
|
23
|
+
|
|
24
|
+
### Using Plugins from npm
|
|
25
|
+
|
|
26
|
+
To use plugins from npm, you need to install them using a package manager and import them in your configuration file.
|
|
27
|
+
|
|
28
|
+
```js modern.config.ts
|
|
29
|
+
import { myPlugin } from 'my-plugin';
|
|
30
|
+
|
|
31
|
+
export default defineConfig({
|
|
32
|
+
plugins: [myPlugin()],
|
|
33
|
+
});
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
#### Using Local Plugins
|
|
37
|
+
|
|
38
|
+
To use plugins from a local code repository, you can directly import them using a relative path.
|
|
10
39
|
|
|
11
40
|
```js modern.config.ts
|
|
12
|
-
import {
|
|
41
|
+
import { myPlugin } from './plugins/myPlugin';
|
|
42
|
+
|
|
13
43
|
export default defineConfig({
|
|
14
|
-
plugins: [
|
|
44
|
+
plugins: [myPlugin()],
|
|
15
45
|
});
|
|
16
46
|
```
|
|
17
47
|
|
|
18
|
-
|
|
48
|
+
### Plugin Configuration
|
|
49
|
+
|
|
50
|
+
If a plugin provides custom configuration options, you can pass the configuration through the plugin function's parameters.
|
|
51
|
+
|
|
52
|
+
```js modern.config.ts
|
|
53
|
+
import { myPlugin } from 'my-plugin';
|
|
54
|
+
|
|
55
|
+
export default defineConfig({
|
|
56
|
+
plugins: [
|
|
57
|
+
myPlugin({
|
|
58
|
+
foo: 1,
|
|
59
|
+
bar: 2,
|
|
60
|
+
}),
|
|
61
|
+
],
|
|
62
|
+
});
|
|
63
|
+
```
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
sidebar_position: 5
|
|
3
3
|
---
|
|
4
4
|
|
|
5
|
-
#
|
|
5
|
+
# testing
|
|
6
6
|
|
|
7
7
|
This chapter describes the test-related configuration
|
|
8
8
|
|
|
@@ -12,10 +12,10 @@ You need to enable the unit testing feature with `pnpm run new` first.
|
|
|
12
12
|
|
|
13
13
|
## jest
|
|
14
14
|
|
|
15
|
-
- Type: `
|
|
15
|
+
- Type: `object | Function`
|
|
16
16
|
- Default: `{}`
|
|
17
17
|
|
|
18
|
-
The configuration corresponding to [Jest](https://jestjs.io/docs/configuration), when of type `
|
|
18
|
+
The configuration corresponding to [Jest](https://jestjs.io/docs/configuration), when of type `object`, can be configured with all the underlying configurations supported by Jest .
|
|
19
19
|
|
|
20
20
|
```js modern.config.ts
|
|
21
21
|
import { defineConfig } from '@modern-js/module-tools';
|
|
@@ -22,7 +22,7 @@ export default defineConfig({
|
|
|
22
22
|
|
|
23
23
|
## Third-party dependency handling for umd products
|
|
24
24
|
|
|
25
|
-
In the [
|
|
25
|
+
In the ["How to handle third-party dependencies"](/en/guide/advance/external-dependency) chapter, we know that we can control whether or not the project packages third-party dependencies via the [`autoExternals`](/en/api/config/build-config#autoexternal) and [`externals`](/en/api/config/build-config#externals) APIs.
|
|
26
26
|
So when building umd products, we can also use it like this:
|
|
27
27
|
|
|
28
28
|
<CH.Spotlight>
|
|
@@ -6,13 +6,17 @@ sidebar_position: 3
|
|
|
6
6
|
|
|
7
7
|
## Default output products
|
|
8
8
|
|
|
9
|
-
When the `modern build` command
|
|
9
|
+
When you use the `modern build` command in an initialized project, Module Tools will generate corresponding build products based on the current configuration.
|
|
10
|
+
|
|
11
|
+
The default configuration is as follows:
|
|
10
12
|
|
|
11
13
|
```ts title="modern.config.ts"
|
|
12
14
|
import { moduleTools, defineConfig } from '@modern-js/module-tools';
|
|
13
15
|
|
|
14
16
|
export default defineConfig({
|
|
17
|
+
// Register the CLI tool of Module Tools
|
|
15
18
|
plugins: [moduleTools()],
|
|
19
|
+
// Specify the build preset configuration
|
|
16
20
|
buildPreset: 'npm-library',
|
|
17
21
|
});
|
|
18
22
|
```
|
|
@@ -70,11 +74,19 @@ export default defineConfig({
|
|
|
70
74
|
});
|
|
71
75
|
```
|
|
72
76
|
|
|
73
|
-
In the above code implementation, `preset.NPM_LIBRARY` corresponds to the preset string `"npm-library"`,
|
|
77
|
+
In the above code implementation, `preset.NPM_LIBRARY` corresponds to the preset string `"npm-library"`, representing multiple build-related configurations equivalent to `"npm-library"`.
|
|
78
|
+
|
|
79
|
+
We use the `map` method to iterate over the `NPM_LIBRARY` array, which contains multiple `buildConfig` objects. We perform a shallow copy of the original `buildConfig` object and modify the value of the `target` property in the shallow copy to be `es5`.
|
|
74
80
|
|
|
81
|
+
If you want to know the specific contents included in `preset.NPM_LIBRARY`, you can refer to the [BuildPreset API](/api/config/build-preset).
|
|
82
|
+
|
|
83
|
+
In addition, under the `preset` object, it not only includes `NPM_LIBRARY`, but also other similar constants.
|
|
75
84
|
|
|
76
85
|
> NPM_LIBRARY`, you can check it with [BuildPreset API](/api/config/build-preset). The`preset`object contains not only`NPM_LIBRARY`, but also other similar constants.
|
|
77
|
-
|
|
86
|
+
|
|
87
|
+
:::tip
|
|
88
|
+
We can not only use `preset.NPM_LIBRARY`to get the build configuration corresponding to`"npm-library"`, but also `preset['npm-library']` in this way.
|
|
89
|
+
:::
|
|
78
90
|
|
|
79
91
|
So what is the `buildConfig` object here? What is the basis for the build product feature mentioned before?
|
|
80
92
|
|
|
@@ -82,7 +94,7 @@ Let's explain next.
|
|
|
82
94
|
|
|
83
95
|
## Build configuration (object)
|
|
84
96
|
|
|
85
|
-
**`buildConfig` is a configuration
|
|
97
|
+
**`buildConfig` is a configuration option that describes how to compile and generate build products**. What was mentioned at the beginning about "_features of build products_" are actually properties supported by `buildConfig`. The currently supported properties cover the needs of most module type projects when building products. `buildConfig` not only contains some properties that products have, but also contains some features needed to build products. The following is a brief list from a classification point of view.
|
|
86
98
|
|
|
87
99
|
**The basic attributes of a build product include:**
|
|
88
100
|
|