@modern-js/module-tools-docs 2.19.0 → 2.20.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.md +87 -87
- package/docs/en/api/config/build-preset.mdx +2 -2
- package/docs/en/api/config/design-system.md +2 -2
- package/docs/en/api/config/plugins.md +2 -2
- package/docs/en/api/config/testing.md +3 -3
- package/docs/en/api/plugin-api/plugin-hooks.md +1 -1
- package/docs/en/guide/advance/in-depth-about-build.md +4 -7
- package/docs/en/guide/basic/before-getting-started.md +1 -1
- package/docs/en/guide/basic/command-preview.md +3 -3
- package/docs/en/guide/basic/modify-output-product.md +1 -2
- package/docs/en/guide/basic/using-storybook.mdx +4 -4
- package/docs/en/guide/best-practices/components.mdx +5 -5
- package/docs/en/guide/intro/getting-started.md +32 -25
- package/docs/en/index.md +2 -2
- package/docs/en/plugins/guide/getting-started.mdx +1 -1
- package/docs/en/plugins/guide/plugin-object.mdx +2 -2
- package/docs/en/plugins/guide/setup-function.mdx +1 -1
- package/docs/zh/api/config/build-config.md +4 -4
- package/docs/zh/api/config/build-preset.mdx +2 -2
- package/docs/zh/api/config/design-system.md +2 -2
- package/docs/zh/api/config/plugins.md +2 -2
- package/docs/zh/api/plugin-api/plugin-hooks.md +2 -2
- package/docs/zh/guide/advance/in-depth-about-build.md +4 -7
- package/docs/zh/guide/advance/theme-config.mdx +1 -1
- package/docs/zh/guide/basic/before-getting-started.md +1 -1
- package/docs/zh/guide/basic/command-preview.md +2 -2
- package/docs/zh/guide/basic/using-storybook.mdx +5 -5
- package/docs/zh/guide/best-practices/components.mdx +4 -4
- package/docs/zh/guide/intro/getting-started.md +35 -29
- package/docs/zh/guide/intro/welcome.md +1 -1
- package/docs/zh/index.md +2 -2
- package/docs/zh/plugins/guide/getting-started.mdx +1 -1
- package/docs/zh/plugins/guide/setup-function.mdx +1 -1
- package/modern.config.ts +1 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @modern-js/module-tools-docs
|
|
2
2
|
|
|
3
|
+
## 2.20.0
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies [6b9d90a]
|
|
8
|
+
- @modern-js/doc-tools@2.20.0
|
|
9
|
+
- @modern-js/doc-plugin-auto-sidebar@2.20.0
|
|
10
|
+
|
|
11
|
+
## 2.19.1
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- @modern-js/doc-tools@2.19.1
|
|
16
|
+
- @modern-js/doc-plugin-auto-sidebar@2.19.1
|
|
17
|
+
|
|
3
18
|
## 2.19.0
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -8,8 +8,8 @@ This section describes all the configuration of Module Tools for building
|
|
|
8
8
|
|
|
9
9
|
## alias
|
|
10
10
|
|
|
11
|
-
-
|
|
12
|
-
-
|
|
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
|
-
-
|
|
63
|
-
-
|
|
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
|
-
-
|
|
70
|
-
-
|
|
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
|
-
-
|
|
77
|
-
-
|
|
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
|
-
-
|
|
96
|
-
-
|
|
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
|
-
-
|
|
132
|
-
-
|
|
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
|
-
-
|
|
139
|
-
-
|
|
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
|
-
-
|
|
146
|
-
-
|
|
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
|
-
-
|
|
177
|
-
-
|
|
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
|
-
-
|
|
184
|
-
-
|
|
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
|
-
-
|
|
191
|
-
-
|
|
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
|
-
-
|
|
198
|
-
-
|
|
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
|
-
-
|
|
215
|
-
-
|
|
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
|
|
|
@@ -236,7 +236,7 @@ To prevent excessive global replacement substitution, it is recommended that the
|
|
|
236
236
|
|
|
237
237
|
<!-- ## disableSwcTransform
|
|
238
238
|
|
|
239
|
-
Starting with version 2.16.0, SWC Transform is enabled by default for code transformation. If you want to disable this feature, you can use this configuration. Only
|
|
239
|
+
Starting with version 2.16.0, SWC Transform is enabled by default for code transformation. If you want to disable this feature, you can use this configuration. Only esbuild Transform is used in this case.
|
|
240
240
|
|
|
241
241
|
The use of SWC Transform can reduce the impact of auxiliary functions on the volume of the constructed product.
|
|
242
242
|
|
|
@@ -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
|
-
-
|
|
251
|
-
-
|
|
250
|
+
- Type: `false | Object`
|
|
251
|
+
- Default:
|
|
252
252
|
|
|
253
253
|
```js
|
|
254
254
|
{
|
|
@@ -267,29 +267,29 @@ 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
|
-
-
|
|
271
|
-
-
|
|
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
|
-
-
|
|
278
|
-
-
|
|
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
|
-
-
|
|
285
|
-
-
|
|
284
|
+
- Type: `boolean`
|
|
285
|
+
- Default: `false`
|
|
286
286
|
|
|
287
287
|
### tsconfigPath
|
|
288
288
|
|
|
289
289
|
Path to the tsconfig file
|
|
290
290
|
|
|
291
|
-
-
|
|
292
|
-
-
|
|
291
|
+
- Type: `string`
|
|
292
|
+
- Default: `. /tsconfig.json`
|
|
293
293
|
|
|
294
294
|
## esbuildOptions
|
|
295
295
|
|
|
@@ -370,22 +370,22 @@ export var yourCode = function() {
|
|
|
370
370
|
|
|
371
371
|
Configure external dependencies that will not be packaged into the final bundle
|
|
372
372
|
|
|
373
|
-
-
|
|
374
|
-
-
|
|
373
|
+
- Type: `(string | RegExp)[]`
|
|
374
|
+
- Default: `[]`
|
|
375
375
|
|
|
376
376
|
## format
|
|
377
377
|
|
|
378
378
|
The format of the js product output, where `iife` and `umd` can only take effect when `buildType` is `bundle`
|
|
379
379
|
|
|
380
|
-
-
|
|
381
|
-
-
|
|
380
|
+
- Type: `'esm' | 'cjs' | 'iife' | 'umd'`
|
|
381
|
+
- Default: `cjs`
|
|
382
382
|
|
|
383
383
|
## input
|
|
384
384
|
|
|
385
385
|
Specify the entry file for the build, in the form of an array that can specify the directory
|
|
386
386
|
|
|
387
|
-
-
|
|
388
|
-
-
|
|
387
|
+
- Type: `string[] | Record<string, string>`
|
|
388
|
+
- Default: `['src/index.ts']` in `bundle` mode, `['src']` in `bundleless` mode
|
|
389
389
|
|
|
390
390
|
```js modern.config.ts
|
|
391
391
|
export default {
|
|
@@ -399,22 +399,22 @@ export default {
|
|
|
399
399
|
|
|
400
400
|
Specify the compilation method of jsx, default support React17, automatically inject jsx runtime code
|
|
401
401
|
|
|
402
|
-
-
|
|
403
|
-
-
|
|
402
|
+
- Type: `automatic | classic`
|
|
403
|
+
- Default: `automatic`
|
|
404
404
|
|
|
405
405
|
## metafile
|
|
406
406
|
|
|
407
407
|
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
408
|
|
|
409
|
-
-
|
|
410
|
-
-
|
|
409
|
+
- Type: `boolean`
|
|
410
|
+
- Default: `false`
|
|
411
411
|
|
|
412
412
|
## minify
|
|
413
413
|
|
|
414
414
|
Use esbuild or terser to compress code, also pass [terserOptions](https://github.com/terser/terser#minify-options)
|
|
415
415
|
|
|
416
|
-
-
|
|
417
|
-
-
|
|
416
|
+
- Type: `'terser' | 'esbuild' | false | Object`
|
|
417
|
+
- Default: `false`
|
|
418
418
|
|
|
419
419
|
```js modern.config.ts
|
|
420
420
|
export default {
|
|
@@ -432,15 +432,15 @@ export default {
|
|
|
432
432
|
|
|
433
433
|
Specifies the output directory of the build
|
|
434
434
|
|
|
435
|
-
-
|
|
436
|
-
-
|
|
435
|
+
- Type: `string`
|
|
436
|
+
- Default: `dist`
|
|
437
437
|
|
|
438
438
|
## platform
|
|
439
439
|
|
|
440
440
|
Generates code for the node environment by default, you can also specify `browser` which will generate code for the browser environment
|
|
441
441
|
|
|
442
|
-
-
|
|
443
|
-
-
|
|
442
|
+
- Type: `'browser' | 'node'`
|
|
443
|
+
- Default: `node`
|
|
444
444
|
|
|
445
445
|
## redirect
|
|
446
446
|
|
|
@@ -468,7 +468,7 @@ export default {
|
|
|
468
468
|
Module sideEffects
|
|
469
469
|
|
|
470
470
|
- Type: `RegExg[] | (filePath: string, isExternal: boolean) => boolean | boolean`
|
|
471
|
-
- Default
|
|
471
|
+
- Default: `undefined`
|
|
472
472
|
|
|
473
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 three-party package is unreliable.Such as when we reference a three-party package style file
|
|
474
474
|
|
|
@@ -511,15 +511,15 @@ After adding this configuration, the sideEffects field in package.json will no l
|
|
|
511
511
|
|
|
512
512
|
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
513
|
|
|
514
|
-
-
|
|
515
|
-
-
|
|
514
|
+
- Type: `string`
|
|
515
|
+
- Default: `src`
|
|
516
516
|
|
|
517
517
|
## sourceMap
|
|
518
518
|
|
|
519
519
|
Whether to generate sourceMap or not
|
|
520
520
|
|
|
521
|
-
-
|
|
522
|
-
-
|
|
521
|
+
- Type: `boolean | 'inline' | 'external'`
|
|
522
|
+
- Default: `false`
|
|
523
523
|
|
|
524
524
|
<!-- ## sourceType
|
|
525
525
|
|
|
@@ -532,8 +532,8 @@ Sets the format of the source code. By default, the source code will be treated
|
|
|
532
532
|
|
|
533
533
|
Whether to enable code splitting
|
|
534
534
|
|
|
535
|
-
-
|
|
536
|
-
-
|
|
535
|
+
- Type: `boolean`
|
|
536
|
+
- Default: `false`
|
|
537
537
|
|
|
538
538
|
## style
|
|
539
539
|
|
|
@@ -547,15 +547,15 @@ less-related configuration
|
|
|
547
547
|
|
|
548
548
|
Refer to [less](https://less.bootcss.com/usage/#less-options) for detailed configuration
|
|
549
549
|
|
|
550
|
-
-
|
|
551
|
-
-
|
|
550
|
+
- Type: `Object`
|
|
551
|
+
- Default: `{ javascriptEnabled: true }`
|
|
552
552
|
|
|
553
553
|
#### additionalData
|
|
554
554
|
|
|
555
555
|
Add `Less` code to the beginning of the entry file.
|
|
556
556
|
|
|
557
|
-
-
|
|
558
|
-
-
|
|
557
|
+
- Type: `string`
|
|
558
|
+
- Default: `undefined`
|
|
559
559
|
|
|
560
560
|
```js modern.config.ts
|
|
561
561
|
export default {
|
|
@@ -573,8 +573,8 @@ export default {
|
|
|
573
573
|
|
|
574
574
|
Configure the implementation library used by `Less`, if not specified, the built-in version used is `4.1.3`
|
|
575
575
|
|
|
576
|
-
-
|
|
577
|
-
-
|
|
576
|
+
- Type: `string | Object`
|
|
577
|
+
- Default: `undefined`
|
|
578
578
|
|
|
579
579
|
Specify the implementation library for `Less` when the `Object` type is specified
|
|
580
580
|
|
|
@@ -612,15 +612,15 @@ sass-related configuration
|
|
|
612
612
|
|
|
613
613
|
Refer to [node-sass](https://github.com/sass/node-sass#options) for detailed configuration
|
|
614
614
|
|
|
615
|
-
-
|
|
616
|
-
-
|
|
615
|
+
- Type: `Object`
|
|
616
|
+
- Default: `{}`
|
|
617
617
|
|
|
618
618
|
#### additionalData
|
|
619
619
|
|
|
620
620
|
Add `Sass` code to the beginning of the entry file.
|
|
621
621
|
|
|
622
|
-
-
|
|
623
|
-
-
|
|
622
|
+
- Type: `string | Function`
|
|
623
|
+
- Default: `undefined`
|
|
624
624
|
|
|
625
625
|
```js modern.config.ts
|
|
626
626
|
export default {
|
|
@@ -639,8 +639,8 @@ export default {
|
|
|
639
639
|
|
|
640
640
|
Configure the implementation library used by `Sass`, the built-in version used is `1.5.4` if not specified
|
|
641
641
|
|
|
642
|
-
-
|
|
643
|
-
-
|
|
642
|
+
- Type: `string | Object`
|
|
643
|
+
- Default: `undefined`
|
|
644
644
|
|
|
645
645
|
Specify the implementation library for `Sass` when the `Object` type is specified
|
|
646
646
|
|
|
@@ -681,8 +681,8 @@ See [postcss](https://github.com/postcss/postcss#options) for detailed configura
|
|
|
681
681
|
|
|
682
682
|
Configure whether to insert style into js in packaged mode
|
|
683
683
|
|
|
684
|
-
-
|
|
685
|
-
-
|
|
684
|
+
- Type: `boolean`
|
|
685
|
+
- Default: `false`
|
|
686
686
|
|
|
687
687
|
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
688
|
|
|
@@ -698,7 +698,7 @@ var css_248z = '.body {\n color: black;\n}';
|
|
|
698
698
|
style_inject_es_default(css_248z);
|
|
699
699
|
```
|
|
700
700
|
|
|
701
|
-
:::tip
|
|
701
|
+
:::tip
|
|
702
702
|
|
|
703
703
|
With `inject` turned on, you need to pay attention to the following points.
|
|
704
704
|
|
|
@@ -717,8 +717,8 @@ This can be fixed by configuring [sideEffects](#sideeffects) in this case.
|
|
|
717
717
|
|
|
718
718
|
Enable CSS Modules automatically based on the filename.
|
|
719
719
|
|
|
720
|
-
-
|
|
721
|
-
-
|
|
720
|
+
- Type: `boolean | RegExp`
|
|
721
|
+
- Default: `true`
|
|
722
722
|
|
|
723
723
|
`true` : Enables CSS Modules for style files ending with `.module.css` `.module.less` `.module.scss` `.module.sass` filenames
|
|
724
724
|
|
|
@@ -730,8 +730,8 @@ Enable CSS Modules automatically based on the filename.
|
|
|
730
730
|
|
|
731
731
|
CSS Modules configuration
|
|
732
732
|
|
|
733
|
-
-
|
|
734
|
-
-
|
|
733
|
+
- Type: `Object`
|
|
734
|
+
- Default: `{}`
|
|
735
735
|
|
|
736
736
|
A common configuration is `localsConvention`, which changes the class name generation rules for css modules
|
|
737
737
|
|
|
@@ -763,8 +763,8 @@ For detailed configuration see [postcss-modules](https://github.com/madyankin/po
|
|
|
763
763
|
|
|
764
764
|
tailwindcss related configuration
|
|
765
765
|
|
|
766
|
-
-
|
|
767
|
-
-
|
|
766
|
+
- Type: `Object | Function`
|
|
767
|
+
- Default: `see configuration details below`
|
|
768
768
|
|
|
769
769
|
<details>
|
|
770
770
|
<summary>Tailwind CSS configuration details</summary>
|
|
@@ -796,8 +796,8 @@ The rest of the usage is the same as Tailwind CSS: [Quick Portal](https://tailwi
|
|
|
796
796
|
|
|
797
797
|
Specify the target environment for the build
|
|
798
798
|
|
|
799
|
-
-
|
|
800
|
-
-
|
|
799
|
+
- Type: `'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' | 'es2020' | 'es2021' | 'es2022' | 'esnext'`
|
|
800
|
+
- Default: `'es6'`
|
|
801
801
|
|
|
802
802
|
<!-- ## transformImport
|
|
803
803
|
|
|
@@ -837,8 +837,8 @@ Reference the [Import Plugin - Notes](plugins/official-list/plugin-import.html#N
|
|
|
837
837
|
|
|
838
838
|
Specify global variables for external import of umd products
|
|
839
839
|
|
|
840
|
-
-
|
|
841
|
-
-
|
|
840
|
+
- Type: `Record<string, string>`
|
|
841
|
+
- Default: `{}`
|
|
842
842
|
|
|
843
843
|
```js modern.config.ts
|
|
844
844
|
export default {
|
|
@@ -857,8 +857,8 @@ At this point, `react` and `react-dom` will be seen as global variables imported
|
|
|
857
857
|
|
|
858
858
|
Specifies the module name of the umd product
|
|
859
859
|
|
|
860
|
-
-
|
|
861
|
-
-
|
|
860
|
+
- Type: `string` | `Function`
|
|
861
|
+
- Default: `name => name`
|
|
862
862
|
|
|
863
863
|
```js
|
|
864
864
|
export default {
|
|
@@ -10,8 +10,8 @@ This chapter describes the configuration related to designSystem
|
|
|
10
10
|
The Tailwind CSS feature needs to be enabled first via `pnpm run new`.
|
|
11
11
|
:::
|
|
12
12
|
|
|
13
|
-
-
|
|
14
|
-
-
|
|
13
|
+
- Type: `Object`
|
|
14
|
+
- Default: `see configuration details below`.
|
|
15
15
|
|
|
16
16
|
<details>
|
|
17
17
|
<summary>designSystem configuration details</summary>
|
|
@@ -4,9 +4,9 @@ sidebar_position: 4
|
|
|
4
4
|
|
|
5
5
|
# Plugins
|
|
6
6
|
|
|
7
|
-
This chapter describes the configuration of the registered
|
|
7
|
+
This chapter describes the configuration of the registered Module Tools plugin.
|
|
8
8
|
|
|
9
|
-
-
|
|
9
|
+
- Type: `Array<ModuleToolsPlugin>`
|
|
10
10
|
|
|
11
11
|
```js modern.config.ts
|
|
12
12
|
import { examplePlugin } from '. /plugins/example';
|
|
@@ -13,7 +13,7 @@ You need to enable the unit testing feature with `pnpm run new` first.
|
|
|
13
13
|
## jest
|
|
14
14
|
|
|
15
15
|
- Type: `Object | Function`
|
|
16
|
-
- Default
|
|
16
|
+
- Default: `{}`
|
|
17
17
|
|
|
18
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
|
|
|
@@ -48,8 +48,8 @@ export default defineConfig({
|
|
|
48
48
|
|
|
49
49
|
## transformer
|
|
50
50
|
|
|
51
|
-
-
|
|
52
|
-
- Default
|
|
51
|
+
- Type: `'babel-jest' | 'ts-jest'`
|
|
52
|
+
- Default: `'babel-jest'`
|
|
53
53
|
|
|
54
54
|
Configure the compilation tool for the source code when executing tests: [babel-jest](https://www.npmjs.com/package/babel-jest) or [ts-jest](https://github.com/kulshekhar/ts-jest). The default is `babel-jest`.
|
|
55
55
|
|
|
@@ -335,7 +335,7 @@ export interface DevToolData {
|
|
|
335
335
|
}
|
|
336
336
|
```
|
|
337
337
|
|
|
338
|
-
<!-- :::tip
|
|
338
|
+
<!-- :::tip About disableRunBuild configuration
|
|
339
339
|
When dev a project, it may be possible to set `disableRunBuild: true` to disable build tasks for source execution (in listening mode) if you only need to dev code functionality.
|
|
340
340
|
|
|
341
341
|
The currently supported Storybook dev supports using source code products as dev objects, so `disableRunBuild: false` in the Storybook plugin.
|
|
@@ -4,13 +4,10 @@ sidebar_position: 1
|
|
|
4
4
|
|
|
5
5
|
# In-depth understanding of build
|
|
6
6
|
|
|
7
|
-
In the
|
|
8
|
-
|
|
9
|
-
:::tip{title=notes}
|
|
10
|
-
If you are not sure what `buildConfig` is, it is recommended to take some time to understand it by following this link.
|
|
11
|
-
|
|
12
|
-
- [[modify-output-product](/en/guide/basic/modify-output-product)]
|
|
7
|
+
In the "Basic Usage" section, we already knew that you can modify the output product of a project through the `buildConfig` configuration. `buildConfig` not only describes some of the features of the product, but also provides some functionality for building the product.
|
|
13
8
|
|
|
9
|
+
:::tip
|
|
10
|
+
If you are not familiar with `buildConfig`, please read [modify-output-product](/en/guide/basic/modify-output-product).
|
|
14
11
|
:::
|
|
15
12
|
|
|
16
13
|
In this chapter we'll dive into the use of certain build configurations and understand what happens when the `modern build` command is executed.
|
|
@@ -43,7 +40,7 @@ In `buildConfig` you can specify whether the current build task is Bundle or Bun
|
|
|
43
40
|
- When `buildType: 'bundle'`, `input` defaults to `src/index.(j|t)sx?`
|
|
44
41
|
- When `buildType: 'bundleless'`, `input` defaults to `['src']`
|
|
45
42
|
|
|
46
|
-
:::warning
|
|
43
|
+
:::warning
|
|
47
44
|
It is recommended that you do not specify multiple source file directories during a Bundleless build, as unintended results may occur. Bundleless builds with multiple source directories are currently in an unstable stage.
|
|
48
45
|
:::
|
|
49
46
|
|
|
@@ -6,7 +6,7 @@ sidebar_position: 1
|
|
|
6
6
|
|
|
7
7
|
## Environment preparation
|
|
8
8
|
|
|
9
|
-
In order to use the Modern.js module engineering solution, you first need [NodeJS](https://nodejs.org/zh/) engine, we recommend the latest [LTS version](https://github.com/nodejs/Release), and make sure the Node version is **>=14.18.0**. because non-stable NodeJS releases frequently have bugs. You might consider installing via [nvm-windows](https://github.com/coreybutler/nvm-windows) and [nvm](https://github.com/nvm-sh/nvm) (Mac/
|
|
9
|
+
In order to use the Modern.js module engineering solution, you first need [NodeJS](https://nodejs.org/zh/) engine, we recommend the latest [LTS version](https://github.com/nodejs/Release), and make sure the Node version is **>=14.18.0**. because non-stable NodeJS releases frequently have bugs. You might consider installing via [nvm-windows](https://github.com/coreybutler/nvm-windows) and [nvm](https://github.com/nvm-sh/nvm) (Mac / Linux), so you can easily switch to different NodeJS versions that might be required for different projects that you work on.
|
|
10
10
|
|
|
11
11
|
## Getting Started with npm
|
|
12
12
|
|
|
@@ -32,7 +32,7 @@ When you want to start a project build, you can execute the `modern build` comma
|
|
|
32
32
|
|
|
33
33
|
In addition to the above, module projects also support `platform` build mode, which can be used to perform build tasks for other tools. For example, it is currently officially supported to start a Storybook build task to generate Storybook products by executing the `modern build --platform` or `modern build --platform storybook` commands after installing the `@modern-js/plugin-storybook` plugin.
|
|
34
34
|
|
|
35
|
-
:::tip
|
|
35
|
+
:::tip
|
|
36
36
|
When executing a Storybook build, if you need to read the build product of the project. Then **don't forget to execute the `modern build` command to ensure the existence of the project's build product before executing the `modern build --platform` command to start the Storybook build**.
|
|
37
37
|
:::
|
|
38
38
|
|
|
@@ -108,7 +108,7 @@ Run [ESLint](https://eslint.org/) to check the syntax of the code. Usually, we o
|
|
|
108
108
|
|
|
109
109
|
- The `-no-fix` argument turns off the ability to automatically fix lint error code.
|
|
110
110
|
|
|
111
|
-
##
|
|
111
|
+
## `modern change`
|
|
112
112
|
|
|
113
113
|
```bash
|
|
114
114
|
Usage: modern change [options]
|
|
@@ -185,7 +185,7 @@ Options:
|
|
|
185
185
|
|
|
186
186
|
Automatically generate [Release Note](https://en.wikipedia.org/wiki/Release_notes) based on the changeset information of the current repository.
|
|
187
187
|
|
|
188
|
-
:::tip
|
|
188
|
+
:::tip
|
|
189
189
|
needs to be executed before the `bump` command.
|
|
190
190
|
:::
|
|
191
191
|
|
|
@@ -17,9 +17,9 @@ First of all, if you haven't read the following, take a few minutes to understan
|
|
|
17
17
|
- Share how the UI actually works
|
|
18
18
|
- Automate UI workflows
|
|
19
19
|
|
|
20
|
-
So
|
|
20
|
+
So Storybook is a complex and powerful tool.
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
Module Tools is integrated with Storybook, so you can pretty much follow the official Storybook documentation. However, there are still a few things to keep in mind, which are explained below.
|
|
23
23
|
|
|
24
24
|
## Debugging code
|
|
25
25
|
|
|
@@ -164,10 +164,10 @@ export default {
|
|
|
164
164
|
};
|
|
165
165
|
```
|
|
166
166
|
|
|
167
|
-
:::tip
|
|
167
|
+
:::tip Why is the source code approach not recommended
|
|
168
168
|
Not only is it impossible to verify that the component product is correct using the component source code, **but also some of the configurations supported by the module project for building the product cannot be fully translated into Storybook internal configuration**. If some of the configurations cannot be converted to each other, there will be unintended results during Storybook debugging.
|
|
169
169
|
|
|
170
|
-
Module Tools is based on
|
|
170
|
+
Module Tools is based on esbuild, while Storybook is based on Webpack, and esbuild's configuration is not fully compatible with Webpack.
|
|
171
171
|
:::
|
|
172
172
|
|
|
173
173
|
## Configure Storybook
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
This chapter will describe how to develop component projects using the module engineering solution.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Initialize the project
|
|
6
6
|
|
|
7
7
|
<CH.Spotlight>
|
|
8
8
|
|
|
9
9
|
```bash Interactive questions
|
|
10
|
-
npx @modern-js/create components-project
|
|
10
|
+
npx @modern-js/create@latest components-project
|
|
11
11
|
|
|
12
12
|
? Please select the solution you want to create: Npm Module
|
|
13
13
|
? Package Name: components-demo
|
|
@@ -20,7 +20,7 @@ npx @modern-js/create components-project
|
|
|
20
20
|
It is recommended to use the `@modern-js/create` command to initialize an npm project.
|
|
21
21
|
|
|
22
22
|
```bash Interactive questions
|
|
23
|
-
npx @modern-js/create components-project
|
|
23
|
+
npx @modern-js/create@latest components-project
|
|
24
24
|
|
|
25
25
|
? Please select the solution you want to create: Npm Module
|
|
26
26
|
? Package Name: components-demo
|
|
@@ -271,7 +271,7 @@ e b {
|
|
|
271
271
|
|
|
272
272
|
Module projects support development styles using Less.
|
|
273
273
|
|
|
274
|
-
>
|
|
274
|
+
> The current built-in Less version is v4.1.3
|
|
275
275
|
|
|
276
276
|
<CH.Spotlight>
|
|
277
277
|
|
|
@@ -310,7 +310,7 @@ div {
|
|
|
310
310
|
|
|
311
311
|
Module projects support developing styles using Scss/Sass.
|
|
312
312
|
|
|
313
|
-
>
|
|
313
|
+
> The current built-in Sass version is v1.54.4
|
|
314
314
|
|
|
315
315
|
<CH.Spotlight>
|
|
316
316
|
|
|
@@ -8,6 +8,36 @@ sidebar_position: 3
|
|
|
8
8
|
|
|
9
9
|
Want to experience Module Tools in action? The only prerequisite you need is [Node.js LTS](https://github.com/nodejs/Release) and make sure your Node version is **>= 14.18.0**.We recommend using the LTS version of Node.js 16.
|
|
10
10
|
|
|
11
|
+
### Create new project
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
**If you want to create a complete module project, you can execute the following command:**
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
npx @modern-js/create your-project-dir-name
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
:::info
|
|
21
|
+
Execute `npx @modern-js/create -h` for more command line arguments
|
|
22
|
+
:::
|
|
23
|
+
|
|
24
|
+
Next, in the issue interaction, follow the options below.
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
? Please select the type of project you want to create: Npm Module
|
|
28
|
+
? Please fill in the project name: library
|
|
29
|
+
? Please select the development language: TS
|
|
30
|
+
? Please select the package manager: pnpm
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
> The project name is the value of the `"name"` field in `package.json`.
|
|
34
|
+
|
|
35
|
+
Then the process of initializing the project will start. After the project directory and files are generated and the dependencies are installed, a complete module project is created.
|
|
36
|
+
|
|
37
|
+
We can start the project build directly with the `pnpm build` command, and start the build in watching mode with the `pnpm build --watch` command.
|
|
38
|
+
|
|
39
|
+
### Add to an existing project
|
|
40
|
+
|
|
11
41
|
From your shell, install the following dependencies in your project.
|
|
12
42
|
|
|
13
43
|
- `@modern-js/module-tools`
|
|
@@ -43,6 +73,8 @@ Finally, add the command `"build": "modern build"` to the project's `package.jso
|
|
|
43
73
|
|
|
44
74
|
If your project has a `src/index.(js|jsx)` file or both `src/index.(ts|tsx)` and `tsconfig.json` files, then congratulations you can run the `npm run build` command directly to build your project with Module Tools.
|
|
45
75
|
|
|
76
|
+
### View official example
|
|
77
|
+
|
|
46
78
|
**If you want to see the complete project using the modular engineering scheme, you can execute the following command**.
|
|
47
79
|
|
|
48
80
|
```bash
|
|
@@ -62,31 +94,6 @@ pnpm dev storybook
|
|
|
62
94
|
pnpm test
|
|
63
95
|
```
|
|
64
96
|
|
|
65
|
-
**If you want to create a complete module project, you can execute the following command:**
|
|
66
|
-
|
|
67
|
-
```bash
|
|
68
|
-
npx @modern-js/create your-project-dir-name
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
:::info
|
|
72
|
-
Execute `npx @modern-js/create -h` for more command line arguments
|
|
73
|
-
:::
|
|
74
|
-
|
|
75
|
-
Next, in the issue interaction, follow the options below.
|
|
76
|
-
|
|
77
|
-
```bash
|
|
78
|
-
? Please select the type of project you want to create: Npm Module
|
|
79
|
-
? Please fill in the project name: library
|
|
80
|
-
? Please select the development language: TS
|
|
81
|
-
? Please select the package manager: pnpm
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
> The project name is the value of the `"name"` field in `package.json`.
|
|
85
|
-
|
|
86
|
-
Then the process of initializing the project will start. After the project directory and files are generated and the dependencies are installed, a complete module project is created.
|
|
87
|
-
|
|
88
|
-
We can start the project build directly with the `pnpm build` command, and start the build in watching mode with the `pnpm build --watch` command.
|
|
89
|
-
|
|
90
97
|
## Let's get started
|
|
91
98
|
|
|
92
99
|
Choose your tutorial scenario...
|
package/docs/en/index.md
CHANGED
|
@@ -14,8 +14,8 @@ hero:
|
|
|
14
14
|
link: /en/guide/intro/getting-started
|
|
15
15
|
|
|
16
16
|
features:
|
|
17
|
-
- title: '
|
|
18
|
-
details: Built on
|
|
17
|
+
- title: 'esbuild: The High Performance JS Bundler'
|
|
18
|
+
details: Built on esbuild, the build is extremely fast and gives you the ultimate development experience.
|
|
19
19
|
icon: 🚀
|
|
20
20
|
- title: 'Two build modes'
|
|
21
21
|
details: Both bundle and bundleless build modes are supported.
|
|
@@ -6,7 +6,7 @@ sidebar_position: 1
|
|
|
6
6
|
|
|
7
7
|
Module engineering solution not only provides a rich set of features, but also supports extending the capabilities of the current project by way of plugins.
|
|
8
8
|
|
|
9
|
-
We can quickly see how to write a
|
|
9
|
+
We can quickly see how to write a Module Tools plugin by using the following example.
|
|
10
10
|
|
|
11
11
|
<CH.Spotlight>
|
|
12
12
|
|
|
@@ -4,10 +4,10 @@ sidebar_position: 2
|
|
|
4
4
|
|
|
5
5
|
# Plugin Object
|
|
6
6
|
|
|
7
|
-
The
|
|
7
|
+
The Module Tools plugin is an object, and the object contains the following properties.
|
|
8
8
|
|
|
9
9
|
- `name`: The name of the plugin, a unique identifier.
|
|
10
|
-
- `setup`: plugin initialization function, which will be executed only once. setup function can return a [Hooks object](), and
|
|
10
|
+
- `setup`: plugin initialization function, which will be executed only once. setup function can return a [Hooks object](), and Module Tools will execute the function corresponding to the Hook defined on the Hooks object at a specific time.
|
|
11
11
|
|
|
12
12
|
For example, in the following plugin code example, the `beforeBuild` function is triggered before the project starts the build task and the `build start` log is printed.
|
|
13
13
|
|
|
@@ -106,7 +106,7 @@ export default (): CliPlugin<ModuleTools> => ({
|
|
|
106
106
|
|
|
107
107
|
## Life cycle hooks
|
|
108
108
|
|
|
109
|
-
We know that the `setup` function returns a Hooks object, which can also be understood as an object with
|
|
109
|
+
We know that the `setup` function returns a Hooks object, which can also be understood as an object with Module Tools lifecycle hooks.
|
|
110
110
|
|
|
111
111
|
Currently there are two main types of hooks.
|
|
112
112
|
|
|
@@ -277,7 +277,7 @@ export default defineConfig({
|
|
|
277
277
|
|
|
278
278
|
<!-- ## disableSwcTransform
|
|
279
279
|
|
|
280
|
-
从 2.16.0 版本开始,默认开启 SWC Transform 进行代码转换。如果想要关闭该功能,可以使用该配置。此时仅使用
|
|
280
|
+
从 2.16.0 版本开始,默认开启 SWC Transform 进行代码转换。如果想要关闭该功能,可以使用该配置。此时仅使用 esbuild Transform。
|
|
281
281
|
|
|
282
282
|
使用 SWC Transform 可以减小辅助函数对构建产物体积的影响。
|
|
283
283
|
|
|
@@ -451,8 +451,8 @@ export default defineConfig({
|
|
|
451
451
|
|
|
452
452
|
esbuild 以 JSON 格式生成有关构建的一些元数据,可以通过例如 [bundle-buddy](https://bundle-buddy.com/esbuild) 的工具可视化
|
|
453
453
|
|
|
454
|
-
-
|
|
455
|
-
-
|
|
454
|
+
- 类型:`boolean`
|
|
455
|
+
- 默认值:`false`
|
|
456
456
|
|
|
457
457
|
## minify
|
|
458
458
|
|
|
@@ -758,7 +758,7 @@ var css_248z = '.body {\n color: black;\n}';
|
|
|
758
758
|
style_inject_es_default(css_248z);
|
|
759
759
|
```
|
|
760
760
|
|
|
761
|
-
:::tip
|
|
761
|
+
:::tip
|
|
762
762
|
|
|
763
763
|
开启了 `inject` 后,你需要注意以下几点:
|
|
764
764
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# Plugin Hooks
|
|
2
2
|
|
|
3
|
-
本章介绍关于
|
|
3
|
+
本章介绍关于 Module Tools 支持的生命周期钩子。
|
|
4
4
|
|
|
5
5
|
目前主要包含两类生命周期钩子:
|
|
6
6
|
|
|
@@ -337,7 +337,7 @@ export interface DevToolData {
|
|
|
337
337
|
}
|
|
338
338
|
```
|
|
339
339
|
|
|
340
|
-
<!-- :::tip
|
|
340
|
+
<!-- :::tip 关于 disableRunBuild 配置
|
|
341
341
|
在调试项目的时候,如果仅需要对代码功能进行调试的话,也许可以设置 `disableRunBuild: true` 来关闭对于源码执行(监听模式下的)构建任务。
|
|
342
342
|
|
|
343
343
|
目前支持的 Storybook 调试支持将源码产物作为调试对象,因此在 Storybook 插件中 `disableRunBuild: false`。
|
|
@@ -4,13 +4,10 @@ sidebar_position: 1
|
|
|
4
4
|
|
|
5
5
|
# 深入理解构建
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
:::tip{title=注意}
|
|
10
|
-
如果你还不清楚 `buildConfig` 是什么,建议花一些时间通过下面的链接了解一下:
|
|
11
|
-
|
|
12
|
-
- 【[修改输出产物](/guide/basic/modify-output-product)】
|
|
7
|
+
在 "基础使用" 的部分,我们已经知道可以通过 `buildConfig` 配置对项目的输出产物进行修改。`buildConfig` 不仅描述了产物的一些特性,同时还为构建产物提供了一些功能。
|
|
13
8
|
|
|
9
|
+
:::tip
|
|
10
|
+
如果你还不了解 `buildConfig` 的作用,请先阅读 [修改输出产物](/guide/basic/modify-output-product)。
|
|
14
11
|
:::
|
|
15
12
|
|
|
16
13
|
而在本章里我们将要深入理解某些构建配置的使用以及了解执行 `modern build` 命令的时候发生了什么。
|
|
@@ -43,7 +40,7 @@ Bundleless 是单文件编译模式,因此对于类型的引用和导出你需
|
|
|
43
40
|
- 当 `buildType: 'bundle'` 的时候,`input` 默认值为 `src/index.(j|t)sx?`
|
|
44
41
|
- 当 `buildType: 'bundleless'` 的时候,`input` 默认值为 `['src']`
|
|
45
42
|
|
|
46
|
-
:::warning
|
|
43
|
+
:::warning
|
|
47
44
|
建议不要在 Bundleless 构建过程中指定多个源码文件目录,这可能会导致产物里的相对路径不正确。
|
|
48
45
|
:::
|
|
49
46
|
|
|
@@ -6,7 +6,7 @@ sidebar_position: 1
|
|
|
6
6
|
|
|
7
7
|
## 环境准备
|
|
8
8
|
|
|
9
|
-
为了使用 Modern.js 模块工程解决方案,首先需要 [NodeJS](https://nodejs.org/zh/),我们推荐最新的[长期维护版本](https://github.com/nodejs/Release),并确保 Node 版本大于等于 **14.18.0**。因为非稳定的 NodeJS 时常有一些 Bug,你可以使用 [nvm-windows](https://github.com/coreybutler/nvm-windows) 和 [nvm](https://github.com/nvm-sh/nvm)(Mac/
|
|
9
|
+
为了使用 Modern.js 模块工程解决方案,首先需要 [NodeJS](https://nodejs.org/zh/),我们推荐最新的[长期维护版本](https://github.com/nodejs/Release),并确保 Node 版本大于等于 **14.18.0**。因为非稳定的 NodeJS 时常有一些 Bug,你可以使用 [nvm-windows](https://github.com/coreybutler/nvm-windows) 和 [nvm](https://github.com/nvm-sh/nvm)(Mac / Linux)安装,这样你就可以方便地切换到不同的 NodeJS 版本,这些版本可能会用于不同的项目。
|
|
10
10
|
|
|
11
11
|
## 初识 npm
|
|
12
12
|
|
|
@@ -32,7 +32,7 @@ Options:
|
|
|
32
32
|
|
|
33
33
|
除了以上,模块工程还支持 `platform` 构建模式,可以用于执行其他工具的构建任务。例如,目前官方支持在安装了 `@modern-js/plugin-storybook` 插件后,可以通过执行 `modern build --platform` 或者 `modern build --platform storybook` 命令启动 Storybook 构建任务生成 Storybook 产物。
|
|
34
34
|
|
|
35
|
-
:::tip
|
|
35
|
+
:::tip
|
|
36
36
|
在执行 Storybook 构建的时候,如果需要读取项目的构建产物。那么**在执行 `modern build --platform` 命令启动 Storybook 构建之前,不要忘记先执行 `modern build` 命令确保项目构建产物的存在**。
|
|
37
37
|
:::
|
|
38
38
|
|
|
@@ -185,7 +185,7 @@ Options:
|
|
|
185
185
|
|
|
186
186
|
根据当前仓库的 changeset 信息自动生成 [Release Note](https://en.wikipedia.org/wiki/Release_notes)。
|
|
187
187
|
|
|
188
|
-
:::tip
|
|
188
|
+
:::tip
|
|
189
189
|
需要在 `bump` 命令之前执行。
|
|
190
190
|
:::
|
|
191
191
|
|
|
@@ -9,7 +9,7 @@ sidebar_position: 5
|
|
|
9
9
|
- [使用微生成器开启 Storybook 调试](/guide/basic/use-micro-generator#storybook-调试)
|
|
10
10
|
- [`modern dev`](/guide/basic/command-preview#modern-dev)
|
|
11
11
|
|
|
12
|
-
[Storybook](https://storybook.js.org/)
|
|
12
|
+
[Storybook](https://storybook.js.org/) 是一个专门用于组件调试的工具,它围绕着组件开发提供了:
|
|
13
13
|
|
|
14
14
|
- 丰富多样的调试能力
|
|
15
15
|
- 可与一些测试工具结合使用
|
|
@@ -17,9 +17,9 @@ sidebar_position: 5
|
|
|
17
17
|
- 可分享能力
|
|
18
18
|
- 工作流程自动化
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
因此 Storybook 是一个复杂且功能强大的工具。
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
Module Tools 集成了 Storybook,因此你几乎可以按照 Storybook 官方文档的内容进行使用。不过依然有一些地方需要注意,接下来讲解一下。
|
|
23
23
|
|
|
24
24
|
## 调试代码
|
|
25
25
|
|
|
@@ -169,11 +169,11 @@ export default {
|
|
|
169
169
|
```
|
|
170
170
|
|
|
171
171
|
|
|
172
|
-
:::tip
|
|
172
|
+
:::tip 为什么不推荐使用源码的方式?
|
|
173
173
|
不仅仅是因为使用组件源码无法验证组件产物是否正确,**同时模块工程对于构建产物支持的一些配置无法完全转换为 Storybook
|
|
174
174
|
内部的配置**。如果某些配置无法进行相互转换的话,就会在 Storybook 调试过程中出现不符合预期的结果。
|
|
175
175
|
|
|
176
|
-
Module Tools 是基于
|
|
176
|
+
Module Tools 是基于 esbuild 实现的,而 Storybook 是基于 Webpack 实现的。esbuild 的配置无法与 Webpack 完全兼容。
|
|
177
177
|
:::
|
|
178
178
|
|
|
179
179
|
## 配置 Storybook
|
|
@@ -11,7 +11,7 @@ sidebar_position: 1
|
|
|
11
11
|
<CH.Spotlight>
|
|
12
12
|
|
|
13
13
|
```bash 交互式问题
|
|
14
|
-
npx @modern-js/create components-project
|
|
14
|
+
npx @modern-js/create@latest components-project
|
|
15
15
|
|
|
16
16
|
? 请选择你想创建的工程类型:Npm 模块
|
|
17
17
|
? 请填写项目名称:components-demo
|
|
@@ -24,7 +24,7 @@ npx @modern-js/create components-project
|
|
|
24
24
|
推荐使用 `@modern-js/create` 命令来初始化一个 npm 项目。
|
|
25
25
|
|
|
26
26
|
```bash 交互式问题
|
|
27
|
-
npx @modern-js/create components-project
|
|
27
|
+
npx @modern-js/create@latest components-project
|
|
28
28
|
|
|
29
29
|
? 请选择你想创建的工程类型:Npm 模块
|
|
30
30
|
? 请填写项目名称:components-demo
|
|
@@ -275,7 +275,7 @@ e b {
|
|
|
275
275
|
|
|
276
276
|
模块工程支持使用 Less 开发样式。
|
|
277
277
|
|
|
278
|
-
>
|
|
278
|
+
> 目前内置的 Less 版本为 v4.1.3
|
|
279
279
|
|
|
280
280
|
<CH.Spotlight>
|
|
281
281
|
|
|
@@ -314,7 +314,7 @@ div {
|
|
|
314
314
|
|
|
315
315
|
模块工程支持使用 Scss/Sass 开发样式。
|
|
316
316
|
|
|
317
|
-
>
|
|
317
|
+
> 目前内置的 Sass 版本为 v1.54.4
|
|
318
318
|
|
|
319
319
|
<CH.Spotlight>
|
|
320
320
|
|
|
@@ -8,7 +8,36 @@ sidebar_position: 3
|
|
|
8
8
|
|
|
9
9
|
想要实际体验 Module Tools?首先需要安装 [Node.js LTS](https://github.com/nodejs/Release),并确保 Node 版本大于等于 **14.18.0**。我们推荐使用 Node.js 16 的 LTS 版本。
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
### 创建新项目
|
|
12
|
+
|
|
13
|
+
**如果你想要创建一个完整的模块工程项目,可以执行以下命令:**
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
npx @modern-js/create your-project-dir-name
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
:::info
|
|
20
|
+
执行 `npx @modern-js/create -h` 查看更多命令行参数
|
|
21
|
+
:::
|
|
22
|
+
|
|
23
|
+
接着在问题交互中,按照如下选择:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
? 请选择你想创建的工程类型:Npm 模块
|
|
27
|
+
? 请填写项目名称:library
|
|
28
|
+
? 请选择开发语言:TS
|
|
29
|
+
? 请选择包管理工具:pnpm
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
> 项目名称为 `package.json` 中的 `"name"` 字段值。
|
|
33
|
+
|
|
34
|
+
接着就会开始初始化项目的流程。在项目目录和文件生成以及依赖安装完毕后,此时就创建了一个完整的模块工程项目。
|
|
35
|
+
|
|
36
|
+
我们可以直接执行 `pnpm build` 命令启动项目的构建,执行 `pnpm build --watch` 命令开启构建的观察模式。
|
|
37
|
+
|
|
38
|
+
### 接入已有项目
|
|
39
|
+
|
|
40
|
+
在你的项目里安装以下依赖:
|
|
12
41
|
|
|
13
42
|
- `"@modern-js/module-tools"`
|
|
14
43
|
- `"typescript"`(如果不是 TypeScript 项目,则省略)
|
|
@@ -21,12 +50,12 @@ npm install -D @modern-js/module-tools typescript
|
|
|
21
50
|
|
|
22
51
|
接着在项目的根目录下创建 `modern.config.(t|j)s` 文件:
|
|
23
52
|
|
|
24
|
-
```
|
|
53
|
+
```ts
|
|
25
54
|
import moduleTools, { defineConfig } from '@modern-js/module-tools';
|
|
26
55
|
|
|
27
56
|
export default defineConfig({
|
|
28
|
-
|
|
29
|
-
})
|
|
57
|
+
plugins: [moduleTools()],
|
|
58
|
+
});
|
|
30
59
|
```
|
|
31
60
|
|
|
32
61
|
最后在项目的 `package.json` 文件里增加命令 `"build": "modern build"`:
|
|
@@ -41,6 +70,8 @@ export default defineConfig({
|
|
|
41
70
|
|
|
42
71
|
如果你的项目存在 `src/index.(js|jsx)` 文件或者同时存在 `src/index.(ts|tsx)` 和 `tsconfig.json` 文件,那么恭喜你可以运行直接运行 `npm run build` 来使用 Module Tools 构建你的项目了。
|
|
43
72
|
|
|
73
|
+
### 查看官方示例
|
|
74
|
+
|
|
44
75
|
**如果你想要看看使用了模块工程方案的完整项目,可以执行以下命令**:
|
|
45
76
|
|
|
46
77
|
```bash
|
|
@@ -60,31 +91,6 @@ pnpm dev storybook
|
|
|
60
91
|
pnpm test
|
|
61
92
|
```
|
|
62
93
|
|
|
63
|
-
**如果你想要创建一个完整的模块工程项目,可以执行以下命令:**
|
|
64
|
-
|
|
65
|
-
```bash
|
|
66
|
-
npx @modern-js/create your-project-dir-name
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
:::info
|
|
70
|
-
执行 `npx @modern-js/create -h` 查看更多命令行参数
|
|
71
|
-
:::
|
|
72
|
-
|
|
73
|
-
接着在问题交互中,按照如下选择:
|
|
74
|
-
|
|
75
|
-
```bash
|
|
76
|
-
? 请选择你想创建的工程类型:Npm 模块
|
|
77
|
-
? 请填写项目名称:library
|
|
78
|
-
? 请选择开发语言:TS
|
|
79
|
-
? 请选择包管理工具:pnpm
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
> 项目名称为 `package.json` 中的 `"name"` 字段值。
|
|
83
|
-
|
|
84
|
-
接着就会开始初始化项目的流程。在项目目录和文件生成以及依赖安装完毕后,此时就创建了一个完整的模块工程项目。
|
|
85
|
-
|
|
86
|
-
我们可以直接执行 `pnpm build` 命令启动项目的构建,执行 `pnpm build --watch` 命令开启构建的观察模式。
|
|
87
|
-
|
|
88
94
|
## 让我们开始吧
|
|
89
95
|
|
|
90
96
|
选择适合你的教程:
|
|
@@ -15,4 +15,4 @@ Module Tools 是 Modern.js 的模块工程解决方案,同时也是核心依
|
|
|
15
15
|
- **集成 Jest 的测试能力**:在需要对模块测试的时候,可以使用 Module Tools 的 `modern test` 命令。Module Tools 不仅集成了 [Jest](https://jestjs.io/),同时也提供了配置 [Jest](https://jestjs.io/docs/configuration) 的 API。
|
|
16
16
|
- **基于 Changesets 实现的版本管理**:当需要对项目记录变更内容的时候,可以使用 `modern change` 命令生成包含变更内容的 Markdown 文件;当需要对项目进行版本升级的时候,可以使用 `modern bump` 命令通过 Markdown 文件分析并升级版本;当需要发布项目的时候,可以使用 `modern release` 命令对项目进行发布。Module Tools 基于 [Changesets](https://github.com/changesets/changesets) 实现了这些命令。
|
|
17
17
|
- **可扩展性的插件机制**:想要为项目集成其他的调试工具?又或者是想要在构建过程中做一些额外处理?Module Tools 提供了插件机制和插件钩子,插件钩子覆盖了 `dev` 命令和 `build` 命令两个流程。你可以通过它们为项目进行能力的扩展。
|
|
18
|
-
- **还有更多**:Module Tools
|
|
18
|
+
- **还有更多**:Module Tools 在未来还会不断地在构建、调试功能上进行优化。如果在模块项目构建上存在需要解决的重要问题,又或者是某个主流的模块项目调试工具、模式出现的时候,那么它们很可能成为 Module Tools 将要支持功能。
|
package/docs/zh/index.md
CHANGED
|
@@ -14,8 +14,8 @@ hero:
|
|
|
14
14
|
link: /guide/intro/getting-started
|
|
15
15
|
|
|
16
16
|
features:
|
|
17
|
-
- title: '
|
|
18
|
-
details: 基于
|
|
17
|
+
- title: 'esbuild: 高性能的 JS Bundler'
|
|
18
|
+
details: 基于 esbuild 构建,构建速度极快,带给你极致的开发体验。
|
|
19
19
|
icon: 🚀
|
|
20
20
|
- title: '双构建模式'
|
|
21
21
|
details: 支持 Bundle 和 Bundleless 两种构建模式。
|
package/modern.config.ts
CHANGED
|
@@ -42,7 +42,7 @@ function getNavbar(lang: 'zh' | 'en'): NavItem[] {
|
|
|
42
42
|
},
|
|
43
43
|
{
|
|
44
44
|
text: getText('贡献指南', 'Contributing'),
|
|
45
|
-
link: 'https://
|
|
45
|
+
link: 'https://modernjs.dev/en/community/contributing-guide.html',
|
|
46
46
|
},
|
|
47
47
|
],
|
|
48
48
|
},
|
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.20.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.20.0",
|
|
20
|
+
"@modern-js/doc-tools": "2.20.0"
|
|
21
21
|
},
|
|
22
22
|
"scripts": {
|
|
23
23
|
"dev": "modern dev",
|