@modern-js/module-tools-docs 2.22.0 → 2.23.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 +18 -0
- package/docs/en/api/config/build-config.md +104 -94
- package/docs/en/guide/best-practices/components.mdx +1 -1
- package/docs/en/plugins/official-list/overview.md +1 -1
- package/docs/en/plugins/official-list/plugin-polyfill.md +1 -1
- package/docs/zh/api/config/build-config.md +14 -8
- package/docs/zh/guide/best-practices/components.mdx +1 -1
- package/docs/zh/plugins/official-list/overview.md +1 -1
- package/docs/zh/plugins/official-list/plugin-babel.md +1 -1
- package/docs/zh/plugins/official-list/plugin-polyfill.md +2 -2
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @modern-js/module-tools-docs
|
|
2
2
|
|
|
3
|
+
## 2.23.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [7e6fb5f]
|
|
8
|
+
- @modern-js/doc-plugin-auto-sidebar@2.23.0
|
|
9
|
+
- @modern-js/doc-tools@2.23.0
|
|
10
|
+
|
|
11
|
+
## 2.22.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [30a8d8d]
|
|
16
|
+
- Updated dependencies [f6b2b3a]
|
|
17
|
+
- Updated dependencies [5a5f164]
|
|
18
|
+
- @modern-js/doc-tools@2.22.1
|
|
19
|
+
- @modern-js/doc-plugin-auto-sidebar@2.22.1
|
|
20
|
+
|
|
3
21
|
## 2.22.0
|
|
4
22
|
|
|
5
23
|
### Minor Changes
|
|
@@ -8,8 +8,8 @@ This section describes all the configuration of Module Tools for building
|
|
|
8
8
|
|
|
9
9
|
## alias
|
|
10
10
|
|
|
11
|
-
- Type
|
|
12
|
-
- Default
|
|
11
|
+
- **Type**: `Record<string, string> | Function`
|
|
12
|
+
- **Default**: `{'@': 'src',}`
|
|
13
13
|
|
|
14
14
|
:::tip
|
|
15
15
|
For TypeScript projects, you only need to configure [compilerOptions.paths](https://www.typescriptlang.org/tsconfig#paths) in `tsconfig.json`, Module Tools will automatically recognize the alias in `tsconfig.json`, so there is no need to configure the `alias` field additionally.
|
|
@@ -59,22 +59,22 @@ export default {
|
|
|
59
59
|
|
|
60
60
|
Static resource output path, will be based on [outDir](/api/config/build-config#outDir)
|
|
61
61
|
|
|
62
|
-
- Type
|
|
63
|
-
- Default
|
|
62
|
+
- **Type**: `string`
|
|
63
|
+
- **Default**: `assets`
|
|
64
64
|
|
|
65
65
|
### limit
|
|
66
66
|
|
|
67
67
|
Threshold for automatically inlining static resources when building, resources less than 10 KB will be automatically inlined into the bundle product
|
|
68
68
|
|
|
69
|
-
- Type
|
|
70
|
-
- Default
|
|
69
|
+
- **Type**: `number`
|
|
70
|
+
- **Default**: `10 * 1024`
|
|
71
71
|
|
|
72
72
|
### publicPath
|
|
73
73
|
|
|
74
74
|
The CDN prefix given to unlinked resources when packaging
|
|
75
75
|
|
|
76
|
-
- Type
|
|
77
|
-
- Default
|
|
76
|
+
- **Type**: `string`
|
|
77
|
+
- **Default**: `undefined`
|
|
78
78
|
|
|
79
79
|
```js modern.config.ts
|
|
80
80
|
export default {
|
|
@@ -92,8 +92,8 @@ At this point, all static resources will be prefixed with `https://xxx/`
|
|
|
92
92
|
|
|
93
93
|
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
|
|
94
94
|
|
|
95
|
-
- Type
|
|
96
|
-
- Default
|
|
95
|
+
- **Type**: `boolean | Object`
|
|
96
|
+
- **Default**: `false`
|
|
97
97
|
|
|
98
98
|
When svgr feature is enabled, you can use svg as a component using the default export.
|
|
99
99
|
|
|
@@ -128,22 +128,22 @@ declare module '*.svg' {
|
|
|
128
128
|
|
|
129
129
|
Set the matching svg file
|
|
130
130
|
|
|
131
|
-
- Type
|
|
132
|
-
- Default
|
|
131
|
+
- **Type**: `string | RegExp | (string | RegExp)[]`
|
|
132
|
+
- **Default**: `/\.svg$/`
|
|
133
133
|
|
|
134
134
|
#### exclude
|
|
135
135
|
|
|
136
136
|
Set unmatched svg files
|
|
137
137
|
|
|
138
|
-
- Type
|
|
139
|
-
- Default
|
|
138
|
+
- **Type**: `string | RegExp | (string | RegExp)[]`
|
|
139
|
+
- **Default**: `undefined`
|
|
140
140
|
|
|
141
141
|
## autoExternal
|
|
142
142
|
|
|
143
143
|
Automatically externalize project dependencies and peerDependencies and not package them into the final bundle
|
|
144
144
|
|
|
145
|
-
- Type
|
|
146
|
-
- Default
|
|
145
|
+
- **Type**: `boolean | Object`
|
|
146
|
+
- **Default**: `true`
|
|
147
147
|
|
|
148
148
|
When we want to turn off the default handling behavior for third-party dependencies, we can do so by:
|
|
149
149
|
|
|
@@ -173,29 +173,29 @@ export default defineConfig({
|
|
|
173
173
|
|
|
174
174
|
Whether or not the dep dependencies of the external project are needed
|
|
175
175
|
|
|
176
|
-
- Type
|
|
177
|
-
- Default
|
|
176
|
+
- **Type**: `boolean`
|
|
177
|
+
- **Default**: `true`
|
|
178
178
|
|
|
179
179
|
### peerDependencies
|
|
180
180
|
|
|
181
181
|
Whether to require peerDep dependencies for external projects
|
|
182
182
|
|
|
183
|
-
- Type
|
|
184
|
-
- Default
|
|
183
|
+
- **Type**: `boolean`
|
|
184
|
+
- **Default**: `true`
|
|
185
185
|
|
|
186
186
|
## buildType
|
|
187
187
|
|
|
188
188
|
The build type, `bundle` will package your code, `bundleless` will only do the code conversion
|
|
189
189
|
|
|
190
|
-
- Type
|
|
191
|
-
- Default
|
|
190
|
+
- **Type**: `'bundle' | 'bundleless'`
|
|
191
|
+
- **Default**: `bundle`
|
|
192
192
|
|
|
193
193
|
## copy
|
|
194
194
|
|
|
195
195
|
Copies the specified file or directory into the build output directory
|
|
196
196
|
|
|
197
|
-
- Type
|
|
198
|
-
- Default
|
|
197
|
+
- **Type**: `Array`
|
|
198
|
+
- **Default**: `[]`
|
|
199
199
|
|
|
200
200
|
```js
|
|
201
201
|
export default {
|
|
@@ -211,8 +211,8 @@ Reference for array settings: [copy-webpack-plugin patterns](https://github.com/
|
|
|
211
211
|
|
|
212
212
|
Define global variables that will be injected into the code
|
|
213
213
|
|
|
214
|
-
- Type
|
|
215
|
-
- Default
|
|
214
|
+
- **Type**: `Record<string, string>`
|
|
215
|
+
- **Default**: `{}`
|
|
216
216
|
|
|
217
217
|
Since the `define` function is implemented by global text replacement, you need to ensure that the global variable values are strings. A safer approach is to convert the value of each global variable to a string, using `JSON.stringify`, as follows.
|
|
218
218
|
|
|
@@ -247,8 +247,8 @@ The use of SWC Transform can reduce the impact of auxiliary functions on the vol
|
|
|
247
247
|
|
|
248
248
|
The dts file generates the relevant configuration, by default it generates.
|
|
249
249
|
|
|
250
|
-
- Type
|
|
251
|
-
- Default
|
|
250
|
+
- **Type**: `false | Object`
|
|
251
|
+
- **Default**:
|
|
252
252
|
|
|
253
253
|
```js
|
|
254
254
|
{
|
|
@@ -267,36 +267,46 @@ Whether to allow the build to succeed in case of a type error. By default, this
|
|
|
267
267
|
When this configuration is turned on, there is no guarantee that the type files will be generated properly and accurately. In `buildType: 'bundle'` or Bundle build mode, the type file must not be generated.
|
|
268
268
|
:::
|
|
269
269
|
|
|
270
|
-
- Type
|
|
271
|
-
- Default
|
|
270
|
+
- **Type**: `boolean`
|
|
271
|
+
- **Default**: `true`
|
|
272
272
|
|
|
273
273
|
### distPath
|
|
274
274
|
|
|
275
275
|
The output path of the dts file, based on [outDir](/api/config/build-config#outDir)
|
|
276
276
|
|
|
277
|
-
- Type
|
|
278
|
-
- Default
|
|
277
|
+
- **Type**: `string`
|
|
278
|
+
- **Default**: `. /types`
|
|
279
279
|
|
|
280
280
|
### only
|
|
281
281
|
|
|
282
282
|
Generate only dts files, not js files
|
|
283
283
|
|
|
284
|
-
- Type
|
|
285
|
-
- Default
|
|
284
|
+
- **Type**: `boolean`
|
|
285
|
+
- **Default**: `false`
|
|
286
|
+
|
|
287
|
+
### respectExternal
|
|
288
|
+
|
|
289
|
+
When set to `false`, the type of third-party packages will be excluded from the bundle, when set to `true`, it will determine whether third-party types need to be bundled based on [externals](#externals).
|
|
290
|
+
|
|
291
|
+
When bundle d.ts, export is not analyzed, so any third-party package type you use may break your build, which is obviously uncontrollable.
|
|
292
|
+
So we can avoid it with this configuration.
|
|
293
|
+
|
|
294
|
+
- **Type**: `boolean`
|
|
295
|
+
- Default value: `true`
|
|
286
296
|
|
|
287
297
|
### tsconfigPath
|
|
288
298
|
|
|
289
299
|
Path to the tsconfig file
|
|
290
300
|
|
|
291
|
-
- Type
|
|
292
|
-
- Default
|
|
301
|
+
- **Type**: `string`
|
|
302
|
+
- **Default**: `. /tsconfig.json`
|
|
293
303
|
|
|
294
304
|
## esbuildOptions
|
|
295
305
|
|
|
296
306
|
Directly modify [esbuild configuration](https://esbuild.github.io/api/)
|
|
297
307
|
|
|
298
|
-
- Type
|
|
299
|
-
- Default
|
|
308
|
+
- **Type**: `Function`
|
|
309
|
+
- **Default**: `c => c`
|
|
300
310
|
|
|
301
311
|
For example, if we need to modify the file extension of the generated files:
|
|
302
312
|
|
|
@@ -328,8 +338,8 @@ By default, the output JS code may depend on helper functions to support the tar
|
|
|
328
338
|
|
|
329
339
|
When using SWC Transform for code transformation, you can enable the `externalHelpers` configuration to convert inline helper functions to import them from the external module `@swc/helpers`.
|
|
330
340
|
|
|
331
|
-
|
|
332
|
-
|
|
341
|
+
- **Type**: `boolean`
|
|
342
|
+
- **Default**: `false`
|
|
333
343
|
|
|
334
344
|
Below is a comparison of the product changes before and after using this configuration.
|
|
335
345
|
|
|
@@ -370,22 +380,22 @@ export var yourCode = function() {
|
|
|
370
380
|
|
|
371
381
|
Configure external dependencies that will not be packaged into the final bundle
|
|
372
382
|
|
|
373
|
-
- Type
|
|
374
|
-
- Default
|
|
383
|
+
- **Type**: `(string | RegExp)[]`
|
|
384
|
+
- **Default**: `[]`
|
|
375
385
|
|
|
376
386
|
## format
|
|
377
387
|
|
|
378
388
|
The format of the js product output, where `iife` and `umd` can only take effect when `buildType` is `bundle`
|
|
379
389
|
|
|
380
|
-
- Type
|
|
381
|
-
- Default
|
|
390
|
+
- **Type**: `'esm' | 'cjs' | 'iife' | 'umd'`
|
|
391
|
+
- **Default**: `cjs`
|
|
382
392
|
|
|
383
393
|
## input
|
|
384
394
|
|
|
385
395
|
Specify the entry file for the build, in the form of an array that can specify the directory
|
|
386
396
|
|
|
387
|
-
- Type
|
|
388
|
-
- Default
|
|
397
|
+
- **Type**: `string[] | Record<string, string>`
|
|
398
|
+
- **Default**: `['src/index.ts']` in `bundle` mode, `['src']` in `bundleless` mode
|
|
389
399
|
|
|
390
400
|
```js modern.config.ts
|
|
391
401
|
export default {
|
|
@@ -399,22 +409,22 @@ export default {
|
|
|
399
409
|
|
|
400
410
|
Specify the compilation method of jsx, default support React17, automatically inject jsx runtime code
|
|
401
411
|
|
|
402
|
-
- Type
|
|
403
|
-
- Default
|
|
412
|
+
- **Type**: `automatic | classic`
|
|
413
|
+
- **Default**: `automatic`
|
|
404
414
|
|
|
405
415
|
## metafile
|
|
406
416
|
|
|
407
417
|
esbuild to produce some metadata about the build in JSON format, which can be visualized by tools such as [bundle-buddy](https://bundle-buddy.com/esbuild)
|
|
408
418
|
|
|
409
|
-
- Type
|
|
410
|
-
- Default
|
|
419
|
+
- **Type**: `boolean`
|
|
420
|
+
- **Default**: `false`
|
|
411
421
|
|
|
412
422
|
## minify
|
|
413
423
|
|
|
414
424
|
Use esbuild or terser to compress code, also pass [terserOptions](https://github.com/terser/terser#minify-options)
|
|
415
425
|
|
|
416
|
-
- Type
|
|
417
|
-
- Default
|
|
426
|
+
- **Type**: `'terser' | 'esbuild' | false | Object`
|
|
427
|
+
- **Default**: `false`
|
|
418
428
|
|
|
419
429
|
```js modern.config.ts
|
|
420
430
|
export default {
|
|
@@ -432,15 +442,15 @@ export default {
|
|
|
432
442
|
|
|
433
443
|
Specifies the output directory of the build
|
|
434
444
|
|
|
435
|
-
- Type
|
|
436
|
-
- Default
|
|
445
|
+
- **Type**: `string`
|
|
446
|
+
- **Default**: `dist`
|
|
437
447
|
|
|
438
448
|
## platform
|
|
439
449
|
|
|
440
450
|
Generates code for the node environment by default, you can also specify `browser` which will generate code for the browser environment
|
|
441
451
|
|
|
442
|
-
- Type
|
|
443
|
-
- Default
|
|
452
|
+
- **Type**: `'browser' | 'node'`
|
|
453
|
+
- **Default**: `node`
|
|
444
454
|
|
|
445
455
|
## redirect
|
|
446
456
|
|
|
@@ -467,16 +477,16 @@ export default {
|
|
|
467
477
|
|
|
468
478
|
Module sideEffects
|
|
469
479
|
|
|
470
|
-
- Type
|
|
471
|
-
- Default
|
|
480
|
+
- **Type**: `RegExg[] | (filePath: string, isExternal: boolean) => boolean | boolean`
|
|
481
|
+
- **Default**: `undefined`
|
|
472
482
|
|
|
473
|
-
Normally, we configure the module's side effects via the sideEffects field in package.json, but in some cases, The package.json of a
|
|
483
|
+
Normally, we configure the module's side effects via the sideEffects field in package.json, but in some cases, The package.json of a third-party package is unreliable.Such as when we reference a third-party package style file
|
|
474
484
|
|
|
475
485
|
```js
|
|
476
486
|
import 'other-package/dist/index.css';
|
|
477
487
|
```
|
|
478
488
|
|
|
479
|
-
But the package.json of this
|
|
489
|
+
But the package.json of this third-party package does not have the style file configured in the sideEffects
|
|
480
490
|
|
|
481
491
|
```json other-package/package.json
|
|
482
492
|
{
|
|
@@ -511,15 +521,15 @@ After adding this configuration, the sideEffects field in package.json will no l
|
|
|
511
521
|
|
|
512
522
|
Specify the source directory of the build, default is `src`, which is used to generate the corresponding product directory based on the source directory structure when building `bundleless`.
|
|
513
523
|
|
|
514
|
-
- Type
|
|
515
|
-
- Default
|
|
524
|
+
- **Type**: `string`
|
|
525
|
+
- **Default**: `src`
|
|
516
526
|
|
|
517
527
|
## sourceMap
|
|
518
528
|
|
|
519
529
|
Whether to generate sourceMap or not
|
|
520
530
|
|
|
521
|
-
- Type
|
|
522
|
-
- Default
|
|
531
|
+
- **Type**: `boolean | 'inline' | 'external'`
|
|
532
|
+
- **Default**: `false`
|
|
523
533
|
|
|
524
534
|
## sourceType
|
|
525
535
|
|
|
@@ -532,8 +542,8 @@ Sets the format of the source code. By default, the source code will be treated
|
|
|
532
542
|
|
|
533
543
|
Whether to enable code splitting
|
|
534
544
|
|
|
535
|
-
- Type
|
|
536
|
-
- Default
|
|
545
|
+
- **Type**: `boolean`
|
|
546
|
+
- **Default**: `false`
|
|
537
547
|
|
|
538
548
|
## style
|
|
539
549
|
|
|
@@ -547,15 +557,15 @@ less-related configuration
|
|
|
547
557
|
|
|
548
558
|
Refer to [less](https://less.bootcss.com/usage/#less-options) for detailed configuration
|
|
549
559
|
|
|
550
|
-
- Type
|
|
551
|
-
- Default
|
|
560
|
+
- **Type**: `Object`
|
|
561
|
+
- **Default**: `{ javascriptEnabled: true }`
|
|
552
562
|
|
|
553
563
|
#### additionalData
|
|
554
564
|
|
|
555
565
|
Add `Less` code to the beginning of the entry file.
|
|
556
566
|
|
|
557
|
-
- Type
|
|
558
|
-
- Default
|
|
567
|
+
- **Type**: `string`
|
|
568
|
+
- **Default**: `undefined`
|
|
559
569
|
|
|
560
570
|
```js modern.config.ts
|
|
561
571
|
export default {
|
|
@@ -573,8 +583,8 @@ export default {
|
|
|
573
583
|
|
|
574
584
|
Configure the implementation library used by `Less`, if not specified, the built-in version used is `4.1.3`
|
|
575
585
|
|
|
576
|
-
- Type
|
|
577
|
-
- Default
|
|
586
|
+
- **Type**: `string | Object`
|
|
587
|
+
- **Default**: `undefined`
|
|
578
588
|
|
|
579
589
|
Specify the implementation library for `Less` when the `Object` type is specified
|
|
580
590
|
|
|
@@ -612,15 +622,15 @@ sass-related configuration
|
|
|
612
622
|
|
|
613
623
|
Refer to [node-sass](https://github.com/sass/node-sass#options) for detailed configuration
|
|
614
624
|
|
|
615
|
-
- Type
|
|
616
|
-
- Default
|
|
625
|
+
- **Type**: `Object`
|
|
626
|
+
- **Default**: `{}`
|
|
617
627
|
|
|
618
628
|
#### additionalData
|
|
619
629
|
|
|
620
630
|
Add `Sass` code to the beginning of the entry file.
|
|
621
631
|
|
|
622
|
-
- Type
|
|
623
|
-
- Default
|
|
632
|
+
- **Type**: `string | Function`
|
|
633
|
+
- **Default**: `undefined`
|
|
624
634
|
|
|
625
635
|
```js modern.config.ts
|
|
626
636
|
export default {
|
|
@@ -639,8 +649,8 @@ export default {
|
|
|
639
649
|
|
|
640
650
|
Configure the implementation library used by `Sass`, the built-in version used is `1.5.4` if not specified
|
|
641
651
|
|
|
642
|
-
- Type
|
|
643
|
-
- Default
|
|
652
|
+
- **Type**: `string | Object`
|
|
653
|
+
- **Default**: `undefined`
|
|
644
654
|
|
|
645
655
|
Specify the implementation library for `Sass` when the `Object` type is specified
|
|
646
656
|
|
|
@@ -675,14 +685,14 @@ export default {
|
|
|
675
685
|
- plugins
|
|
676
686
|
- processOptions
|
|
677
687
|
|
|
678
|
-
See [
|
|
688
|
+
See [PostCSS](https://github.com/postcss/postcss#options) for detailed configuration
|
|
679
689
|
|
|
680
690
|
### inject
|
|
681
691
|
|
|
682
692
|
Configure whether to insert style into js in packaged mode
|
|
683
693
|
|
|
684
|
-
- Type
|
|
685
|
-
- Default
|
|
694
|
+
- **Type**: `boolean`
|
|
695
|
+
- **Default**: `false`
|
|
686
696
|
|
|
687
697
|
After opening inject, you will see an extra piece of style code in the js file. For example, if you write `import '. /index.scss'`,you will see the following code.
|
|
688
698
|
|
|
@@ -703,7 +713,7 @@ style_inject_es_default(css_248z);
|
|
|
703
713
|
With `inject` turned on, you need to pay attention to the following points.
|
|
704
714
|
|
|
705
715
|
- `@import` in the css file will not be processed. So if you have `@import` in your css file, then you need to bring in the css file manually in js (less,scss files don't need it because they will be preprocessed).
|
|
706
|
-
- The impact of `sideEffects` needs to be considered, by default our builder will consider it as a side effect, if the `sideEffects` field set in your project or in the package.json of the
|
|
716
|
+
- The impact of `sideEffects` needs to be considered, by default our builder will consider it as a side effect, if the `sideEffects` field set in your project or in the package.json of the third-party package and it does not contain this css file, then you will get a warning
|
|
707
717
|
|
|
708
718
|
```
|
|
709
719
|
[LIBUILD:ESBUILD_WARN] Ignoring this import because "src/index.scss" was marked as having no side effects by plugin "libuild:adapter"
|
|
@@ -717,8 +727,8 @@ This can be fixed by configuring [sideEffects](#sideeffects) in this case.
|
|
|
717
727
|
|
|
718
728
|
Enable CSS Modules automatically based on the filename.
|
|
719
729
|
|
|
720
|
-
- Type
|
|
721
|
-
- Default
|
|
730
|
+
- **Type**: `boolean | RegExp`
|
|
731
|
+
- **Default**: `true`
|
|
722
732
|
|
|
723
733
|
`true` : Enables CSS Modules for style files ending with `.module.css` `.module.less` `.module.scss` `.module.sass` filenames
|
|
724
734
|
|
|
@@ -730,8 +740,8 @@ Enable CSS Modules automatically based on the filename.
|
|
|
730
740
|
|
|
731
741
|
CSS Modules configuration
|
|
732
742
|
|
|
733
|
-
- Type
|
|
734
|
-
- Default
|
|
743
|
+
- **Type**: `Object`
|
|
744
|
+
- **Default**: `{}`
|
|
735
745
|
|
|
736
746
|
A common configuration is `localsConvention`, which changes the class name generation rules for css modules
|
|
737
747
|
|
|
@@ -763,8 +773,8 @@ For detailed configuration see [postcss-modules](https://github.com/madyankin/po
|
|
|
763
773
|
|
|
764
774
|
tailwindcss related configuration
|
|
765
775
|
|
|
766
|
-
- Type
|
|
767
|
-
- Default
|
|
776
|
+
- **Type**: `Object | Function`
|
|
777
|
+
- **Default**: `see configuration details below`
|
|
768
778
|
|
|
769
779
|
<details>
|
|
770
780
|
<summary>Tailwind CSS configuration details</summary>
|
|
@@ -796,8 +806,8 @@ The rest of the usage is the same as Tailwind CSS: [Quick Portal](https://tailwi
|
|
|
796
806
|
|
|
797
807
|
Specify the target environment for the build
|
|
798
808
|
|
|
799
|
-
- Type
|
|
800
|
-
- Default
|
|
809
|
+
- **Type**: `'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'esnext'`
|
|
810
|
+
- **Default**: `'es6'`
|
|
801
811
|
|
|
802
812
|
<!-- ## transformImport
|
|
803
813
|
|
|
@@ -837,8 +847,8 @@ Reference the [Import Plugin - Notes](plugins/official-list/plugin-import.html#N
|
|
|
837
847
|
|
|
838
848
|
Specify global variables for external import of umd products
|
|
839
849
|
|
|
840
|
-
- Type
|
|
841
|
-
- Default
|
|
850
|
+
- **Type**: `Record<string, string>`
|
|
851
|
+
- **Default**: `{}`
|
|
842
852
|
|
|
843
853
|
```js modern.config.ts
|
|
844
854
|
export default {
|
|
@@ -857,8 +867,8 @@ At this point, `react` and `react-dom` will be seen as global variables imported
|
|
|
857
867
|
|
|
858
868
|
Specifies the module name of the umd product
|
|
859
869
|
|
|
860
|
-
- Type
|
|
861
|
-
- Default
|
|
870
|
+
- **Type**: `string` | `Function`
|
|
871
|
+
- **Default**: `name => name`
|
|
862
872
|
|
|
863
873
|
```js
|
|
864
874
|
export default {
|
|
@@ -204,7 +204,7 @@ The following capabilities are currently supported for developing styles.
|
|
|
204
204
|
|
|
205
205
|
### CSS/PostCSS
|
|
206
206
|
|
|
207
|
-
The module project supports PostCSS and has the following built-in
|
|
207
|
+
The module project supports PostCSS and has the following built-in PostCSS plugins.
|
|
208
208
|
|
|
209
209
|
- [flexbugs-fixes](https://github.com/luisrudge/postcss-flexbugs-fixes)
|
|
210
210
|
- [custom-properties](https://github.com/postcss/postcss-custom-properties)
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
* [@modern-js/plugin-module-banner](./plugin-banner.md):Add custom content, such as copyright information, to the top and bottom of each JS and CSS file.
|
|
7
7
|
* [@modern-js/plugin-module-node-polyfill](./plugin-node-polyfill.mdx): Inject Polyfills of Node core modules in the browser side.
|
|
8
8
|
* [@modern-js/plugin-module-polyfill](./plugin-polyfill.md):Inject polyfill for unsupported features used in your code.
|
|
9
|
-
* [@modern-js/plugin-module-babel](./plugin-babel.md):Use
|
|
9
|
+
* [@modern-js/plugin-module-babel](./plugin-babel.md):Use Babel to transform your code.
|
|
@@ -325,6 +325,15 @@ export default defineConfig({
|
|
|
325
325
|
- 类型: `boolean`
|
|
326
326
|
- 默认值: `false`
|
|
327
327
|
|
|
328
|
+
### respectExternal
|
|
329
|
+
|
|
330
|
+
当设为 `false` 时,不会打包任何三方包类型,设为 `true` 时,会根据[externals](#externals)来决定是否需要打包三方类型。
|
|
331
|
+
|
|
332
|
+
在对类型文件进行打包时,构建工具还未对 export 进行分析,因此当你引用的任何一个三方包出现类型错误时,都可能会中断当前的构建流程,这会导致构建流程不可控,因此我们可以通过这个配置来避免该问题。
|
|
333
|
+
|
|
334
|
+
- 类型: `boolean`
|
|
335
|
+
- 默认值: `true`
|
|
336
|
+
|
|
328
337
|
### tsconfigPath
|
|
329
338
|
|
|
330
339
|
TypeScript 配置文件的路径。
|
|
@@ -369,9 +378,8 @@ export default defineConfig({
|
|
|
369
378
|
|
|
370
379
|
当在使用 SWC Transform 进行代码转换的时候,可以启动 `externalHelpers` 配置,将内联的辅助函数转换为从外部模块 `@swc/helpers` 导入这些辅助函数。
|
|
371
380
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
381
|
+
- 类型:`boolean`
|
|
382
|
+
- 默认值:`false`
|
|
375
383
|
|
|
376
384
|
下面是使用该配置前后的产物变化比较。
|
|
377
385
|
|
|
@@ -408,7 +416,6 @@ export var yourCode = function() {
|
|
|
408
416
|
}
|
|
409
417
|
```
|
|
410
418
|
|
|
411
|
-
|
|
412
419
|
## externals
|
|
413
420
|
|
|
414
421
|
配置外部依赖,不会被打包到最终的 bundle 中。
|
|
@@ -735,7 +742,7 @@ export default defineConfig({
|
|
|
735
742
|
- plugins
|
|
736
743
|
- processOptions
|
|
737
744
|
|
|
738
|
-
详细配置查看 [
|
|
745
|
+
详细配置查看 [PostCSS](https://github.com/postcss/postcss#options)。
|
|
739
746
|
|
|
740
747
|
### inject
|
|
741
748
|
|
|
@@ -865,8 +872,8 @@ const tailwind = {
|
|
|
865
872
|
|
|
866
873
|
提供与 babel-plugin-import 等价的能力和配置,基于 SWC 实现。
|
|
867
874
|
|
|
868
|
-
|
|
869
|
-
|
|
875
|
+
- 类型:`Array`
|
|
876
|
+
- 默认值:`[]`
|
|
870
877
|
|
|
871
878
|
数组元素为一个 babel-plugin-import 的配置对象。配置对象可以参考 [options](https://github.com/umijs/babel-plugin-import#options)。
|
|
872
879
|
|
|
@@ -895,7 +902,6 @@ export default defineConfig({
|
|
|
895
902
|
|
|
896
903
|
参考[【Import 插件——注意事项】](plugins/official-list/plugin-import.html#注意事项)
|
|
897
904
|
|
|
898
|
-
|
|
899
905
|
## umdGlobals
|
|
900
906
|
|
|
901
907
|
指定 UMD 产物外部导入的全局变量。
|
|
@@ -208,7 +208,7 @@ export default {
|
|
|
208
208
|
|
|
209
209
|
### CSS/PostCSS
|
|
210
210
|
|
|
211
|
-
模块工程支持 PostCSS,并且内置了以下
|
|
211
|
+
模块工程支持 PostCSS,并且内置了以下 PostCSS 插件:
|
|
212
212
|
|
|
213
213
|
- [flexbugs-fixes](https://github.com/luisrudge/postcss-flexbugs-fixes)
|
|
214
214
|
- [custom-properties](https://github.com/postcss/postcss-custom-properties)
|
|
@@ -6,4 +6,4 @@
|
|
|
6
6
|
* [@modern-js/plugin-module-banner](./plugin-banner.md):为每个 JS 和 CSS 文件的顶部和底部添加自定义内容,例如版权信息。
|
|
7
7
|
* [@modern-js/plugin-module-node-polyfill](./plugin-node-polyfill.mdx):会自动注入 Node 核心模块在浏览器端的 polyfills。
|
|
8
8
|
* [@modern-js/plugin-module-polyfill](./plugin-polyfill.md):为你的代码中使用到的不支持的功能注入 polyfill。
|
|
9
|
-
* [@modern-js/plugin-module-babel](./plugin-babel.md):使用
|
|
9
|
+
* [@modern-js/plugin-module-babel](./plugin-babel.md):使用 Babel 转换你的代码。
|
|
@@ -50,9 +50,9 @@ type options = {
|
|
|
50
50
|
|
|
51
51
|
### targets
|
|
52
52
|
|
|
53
|
-
|
|
53
|
+
参考 [Babel target](https://babeljs.io/docs/options#targets).
|
|
54
54
|
|
|
55
|
-
|
|
55
|
+
下面是一个例子:
|
|
56
56
|
|
|
57
57
|
```ts
|
|
58
58
|
import moduleTools, { defineConfig } from '@modern-js/module-tools';
|
package/package.json
CHANGED
|
@@ -9,15 +9,15 @@
|
|
|
9
9
|
"directory": "packages/document/module-doc"
|
|
10
10
|
},
|
|
11
11
|
"license": "MIT",
|
|
12
|
-
"version": "2.
|
|
12
|
+
"version": "2.23.0",
|
|
13
13
|
"main": "index.js",
|
|
14
14
|
"dependencies": {
|
|
15
15
|
"@code-hike/mdx": "^0.7.4",
|
|
16
16
|
"react": "^18.2.0",
|
|
17
17
|
"react-dom": "^18.2.0",
|
|
18
18
|
"shiki": "^0.11.1",
|
|
19
|
-
"@modern-js/doc-plugin-auto-sidebar": "2.
|
|
20
|
-
"@modern-js/doc-tools": "2.
|
|
19
|
+
"@modern-js/doc-plugin-auto-sidebar": "2.23.0",
|
|
20
|
+
"@modern-js/doc-tools": "2.23.0"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"dev": "modern dev",
|