@modern-js/module-tools-docs 2.30.0 → 2.31.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (53) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/docs/en/api/config/build-config.mdx +49 -49
  3. package/docs/en/api/config/build-preset.mdx +15 -33
  4. package/docs/en/api/config/design-system.md +42 -34
  5. package/docs/en/api/config/plugins.md +3 -3
  6. package/docs/en/api/config/testing.md +2 -2
  7. package/docs/en/api/plugin-api/plugin-hooks.md +24 -24
  8. package/docs/en/components/register-esbuild-plugin.mdx +2 -2
  9. package/docs/en/guide/advance/asset.mdx +8 -27
  10. package/docs/en/guide/advance/build-umd.mdx +18 -66
  11. package/docs/en/guide/advance/external-dependency.mdx +7 -27
  12. package/docs/en/guide/advance/in-depth-about-build.md +4 -4
  13. package/docs/en/guide/advance/in-depth-about-dev-command.md +2 -2
  14. package/docs/en/guide/advance/theme-config.mdx +4 -8
  15. package/docs/en/guide/basic/before-getting-started.md +1 -1
  16. package/docs/en/guide/basic/publish-your-project.md +8 -7
  17. package/docs/en/guide/basic/test-your-project.mdx +10 -47
  18. package/docs/en/guide/basic/use-micro-generator.md +4 -4
  19. package/docs/en/guide/basic/using-storybook.mdx +12 -44
  20. package/docs/en/guide/best-practices/components.mdx +44 -402
  21. package/docs/en/guide/faq/build.mdx +16 -0
  22. package/docs/en/guide/intro/getting-started.md +2 -2
  23. package/docs/en/plugins/guide/getting-started.mdx +8 -24
  24. package/docs/en/plugins/guide/plugin-object.mdx +2 -8
  25. package/docs/en/plugins/official-list/plugin-import.mdx +9 -52
  26. package/docs/en/plugins/official-list/plugin-node-polyfill.md +2 -2
  27. package/docs/zh/api/config/build-config.mdx +52 -52
  28. package/docs/zh/api/config/build-preset.mdx +12 -30
  29. package/docs/zh/api/config/design-system.md +6 -6
  30. package/docs/zh/api/config/plugins.md +3 -3
  31. package/docs/zh/api/config/testing.md +2 -2
  32. package/docs/zh/components/register-esbuild-plugin.mdx +2 -2
  33. package/docs/zh/guide/advance/asset.mdx +9 -30
  34. package/docs/zh/guide/advance/build-umd.mdx +19 -67
  35. package/docs/zh/guide/advance/external-dependency.mdx +8 -28
  36. package/docs/zh/guide/advance/in-depth-about-build.md +4 -4
  37. package/docs/zh/guide/advance/in-depth-about-dev-command.md +2 -2
  38. package/docs/zh/guide/advance/theme-config.mdx +4 -8
  39. package/docs/zh/guide/basic/publish-your-project.md +2 -2
  40. package/docs/zh/guide/basic/test-your-project.mdx +11 -49
  41. package/docs/zh/guide/basic/use-micro-generator.md +4 -4
  42. package/docs/zh/guide/basic/using-storybook.mdx +13 -45
  43. package/docs/zh/guide/best-practices/components.mdx +50 -410
  44. package/docs/zh/guide/faq/build.mdx +16 -0
  45. package/docs/zh/guide/intro/getting-started.md +1 -1
  46. package/docs/zh/plugins/guide/getting-started.mdx +8 -24
  47. package/docs/zh/plugins/guide/plugin-object.mdx +2 -8
  48. package/docs/zh/plugins/official-list/plugin-import.mdx +10 -55
  49. package/docs/zh/plugins/official-list/plugin-node-polyfill.md +2 -2
  50. package/modern.config.ts +1 -12
  51. package/package.json +3 -5
  52. package/theme/index.ts +0 -2
  53. package/theme/index.css +0 -9
package/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  # @modern-js/module-tools-docs
2
2
 
3
+ ## 2.31.0
4
+
5
+ ### Patch Changes
6
+
7
+ - @modern-js/doc-tools@2.31.0
8
+ - @modern-js/doc-plugin-auto-sidebar@2.31.0
9
+
3
10
  ## 2.30.0
4
11
 
5
12
  ### Patch Changes
@@ -26,7 +26,7 @@ Before start using `buildConfig`, please read the following documentation to und
26
26
  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.
27
27
  :::
28
28
 
29
- ```js modern.config.ts
29
+ ```js title="modern.config.ts"
30
30
  export default {
31
31
  buildConfig: {
32
32
  alias: {
@@ -40,7 +40,7 @@ After the above configuration is done, if `@common/Foo.tsx` is referenced in the
40
40
 
41
41
  When the value of `alias` is defined as a function, you can accept the pre-defined alias object and modify it.
42
42
 
43
- ```js modern.config.ts
43
+ ```js title="modern.config.ts"
44
44
  export default {
45
45
  buildConfig: {
46
46
  alias: alias => {
@@ -52,7 +52,7 @@ export default {
52
52
 
53
53
  It is also possible to return a new object as the final result in the function, which will override the pre-defined alias object.
54
54
 
55
- ```js modern.config.ts
55
+ ```js title="modern.config.ts"
56
56
  export default {
57
57
  buildConfig: {
58
58
  alias: alias => {
@@ -88,7 +88,7 @@ You can adjust this threshold by modifying the `limit` config.
88
88
 
89
89
  For example, set `limit` to `0` to avoid assets inlining:
90
90
 
91
- ```js modern.config.ts
91
+ ```js title="modern.config.ts"
92
92
  export default defineConfig({
93
93
  buildConfig: {
94
94
  asset: {
@@ -105,7 +105,7 @@ The CDN prefix given to unlinked resources when packaging
105
105
  - **Type**: `string`
106
106
  - **Default**: `undefined`
107
107
 
108
- ```js modern.config.ts
108
+ ```js title="modern.config.ts"
109
109
  export default {
110
110
  buildConfig: {
111
111
  asset: {
@@ -126,7 +126,7 @@ Packaged to handle svg as a React component, options reference [svgr](https://re
126
126
 
127
127
  When svgr feature is enabled, you can use svg as a component using the default export.
128
128
 
129
- ```js index.ts
129
+ ```js title="index.ts"
130
130
  // true
131
131
  import Logo from './logo.svg';
132
132
 
@@ -136,7 +136,7 @@ export default () => <Logo />;
136
136
  :::warning
137
137
  The following usage is not currently supported:
138
138
 
139
- ```js index.ts
139
+ ```js title="index.ts"
140
140
  import { ReactComponent } from './logo.svg';
141
141
  ```
142
142
 
@@ -144,7 +144,7 @@ import { ReactComponent } from './logo.svg';
144
144
 
145
145
  When enabled, the type of svg used can be modified by adding a type definition to the `modern-app-env.d.ts` file:
146
146
 
147
- ```ts modern-app-env.d.ts focus=1:3
147
+ ```ts title="modern-app-env.d.ts"
148
148
  declare module '*.svg' {
149
149
  const src: React.FunctionComponent<React.SVGProps<SVGSVGElement>>;
150
150
  export default src;
@@ -176,7 +176,7 @@ Automatically externalize project dependencies and peerDependencies and not pack
176
176
 
177
177
  When we want to turn off the default handling behavior for third-party dependencies, we can do so by:
178
178
 
179
- ```js modern.config.ts
179
+ ```js title="modern.config.ts"
180
180
  export default defineConfig({
181
181
  buildConfig: {
182
182
  autoExternal: false,
@@ -187,7 +187,7 @@ export default defineConfig({
187
187
  This way the dependencies under `"dependencies"` and `"peerDependencies"` will be bundled. If you want to turn off the processing of only one of these dependencies, you can use the
188
188
  `buildConfig.autoExternal` in the form of an object.
189
189
 
190
- ```js modern.config.ts
190
+ ```js title="modern.config.ts"
191
191
  export default defineConfig({
192
192
  buildConfig: {
193
193
  autoExternal: {
@@ -275,7 +275,7 @@ Define global variables that will be injected into the code
275
275
 
276
276
  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.
277
277
 
278
- ```js modern.config.ts
278
+ ```js title="modern.config.ts"
279
279
  export default {
280
280
  buildConfig: {
281
281
  define: {
@@ -327,7 +327,7 @@ Whether to allow the build to succeed if a type error occurs.
327
327
 
328
328
  **By default, type errors will cause the build to fail**. When `abortOnError` is set to `false`, the build will still succeed even if there are type issues in the code:
329
329
 
330
- ```js modern.config.ts
330
+ ```js title="modern.config.ts"
331
331
  export default defineConfig({
332
332
  buildConfig: {
333
333
  dts: {
@@ -350,7 +350,7 @@ The output path of the dts file, based on [outDir](/api/config/build-config#outD
350
350
 
351
351
  For example, output to the `types` directory under the `outDir`:
352
352
 
353
- ```js modern.config.ts
353
+ ```js title="modern.config.ts"
354
354
  export default defineConfig({
355
355
  buildConfig: {
356
356
  dts: {
@@ -367,7 +367,7 @@ Whether to generate only type files during the build process without generating
367
367
  - **Type**: `boolean`
368
368
  - **Default**: `false`
369
369
 
370
- ```js modern.config.ts
370
+ ```js title="modern.config.ts"
371
371
  export default defineConfig({
372
372
  buildConfig: {
373
373
  dts: {
@@ -387,7 +387,7 @@ So we can avoid it with this configuration.
387
387
  - **Type**: `boolean`
388
388
  - **Default**: `true`
389
389
 
390
- ```js modern.config.ts
390
+ ```js title="modern.config.ts"
391
391
  export default defineConfig({
392
392
  buildConfig: {
393
393
  dts: {
@@ -404,7 +404,7 @@ Path to the tsconfig file
404
404
  - **Type**: `string`
405
405
  - **Default**: `. /tsconfig.json`
406
406
 
407
- ```js modern.config.ts
407
+ ```js title="modern.config.ts"
408
408
  export default defineConfig({
409
409
  buildConfig: {
410
410
  dts: {
@@ -424,7 +424,7 @@ Used to modify the [esbuild configuration](https://esbuild.github.io/api/).
424
424
 
425
425
  For example, if we need to modify the file extension of the generated files:
426
426
 
427
- ```ts modern.config.ts
427
+ ```ts title="modern.config.ts"
428
428
  export default defineConfig({
429
429
  buildConfig: {
430
430
  esbuildOptions: options => {
@@ -462,7 +462,7 @@ Below is a comparison of the output file changes before and after using this con
462
462
 
463
463
  Before enable:
464
464
 
465
- ```js ./dist/index.js
465
+ ```js title="./dist/index.js"
466
466
  // helper function
467
467
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) {
468
468
  // ...
@@ -483,7 +483,7 @@ export var yourCode = function () {
483
483
 
484
484
  After enabled:
485
485
 
486
- ```js ./dist/index.js
486
+ ```js title="./dist/index.js"
487
487
  // helper functions imported from @swc/helpers
488
488
  import { _ as _async_to_generator } from '@swc/helpers/_/_async_to_generator';
489
489
 
@@ -507,7 +507,7 @@ type External = (string | RegExp)[];
507
507
  - **Build Type**: `Only supported for buildType: 'bundle'`
508
508
  - **Example**:
509
509
 
510
- ```js modern.config.ts
510
+ ```js title="modern.config.ts"
511
511
  export default defineConfig({
512
512
  buildConfig: {
513
513
  // do not bundle React
@@ -529,7 +529,7 @@ Used to set the output format of JavaScript files. The options `iife` and `umd`
529
529
 
530
530
  - **Example**:
531
531
 
532
- ```js modern.config.ts
532
+ ```js title="modern.config.ts"
533
533
  export default defineConfig({
534
534
  buildConfig: {
535
535
  format: 'esm',
@@ -543,7 +543,7 @@ export default defineConfig({
543
543
 
544
544
  - **Example**:
545
545
 
546
- ```js modern.config.ts
546
+ ```js title="modern.config.ts"
547
547
  export default defineConfig({
548
548
  buildConfig: {
549
549
  format: 'cjs',
@@ -557,7 +557,7 @@ export default defineConfig({
557
557
 
558
558
  - **Example**:
559
559
 
560
- ```js modern.config.ts
560
+ ```js title="modern.config.ts"
561
561
  export default defineConfig({
562
562
  buildConfig: {
563
563
  format: 'iife',
@@ -571,7 +571,7 @@ export default defineConfig({
571
571
 
572
572
  - **Example**:
573
573
 
574
- ```js modern.config.ts
574
+ ```js title="modern.config.ts"
575
575
  export default defineConfig({
576
576
  buildConfig: {
577
577
  format: 'umd',
@@ -597,7 +597,7 @@ type Input =
597
597
 
598
598
  **Array usage:**
599
599
 
600
- ```js modern.config.ts
600
+ ```js title="modern.config.ts"
601
601
  export default {
602
602
  buildConfig: {
603
603
  input: ['src/index.ts', 'src/index2.ts'],
@@ -611,7 +611,7 @@ When you need to modify the output file name in bundle mode, you can use an obje
611
611
 
612
612
  **The key of the object is the file name of the output, and the value is the file path of the source code.**
613
613
 
614
- ```js modern.config.ts
614
+ ```js title="modern.config.ts"
615
615
  export default defineConfig({
616
616
  buildConfig: {
617
617
  format: 'esm',
@@ -631,7 +631,7 @@ Specify the compilation method for JSX, which by default supports React 17 and h
631
631
 
632
632
  If you need to support React 16, you can set `jsx` to `transform`:
633
633
 
634
- ```js modern.config.ts
634
+ ```js title="modern.config.ts"
635
635
  export default defineConfig({
636
636
  buildConfig: {
637
637
  jsx: 'transform',
@@ -656,7 +656,7 @@ This option is used for build analysis. When enabled, esbuild will generate meta
656
656
 
657
657
  To enable `metafile` generation:
658
658
 
659
- ```js modern.config.ts
659
+ ```js title="modern.config.ts"
660
660
  export default defineConfig({
661
661
  buildConfig: {
662
662
  buildType: 'bundle',
@@ -674,7 +674,7 @@ Use esbuild or terser to compress code, also pass [terserOptions](https://github
674
674
  - **Type**: `'terser' | 'esbuild' | false | object`
675
675
  - **Default**: `false`
676
676
 
677
- ```js modern.config.ts
677
+ ```js title="modern.config.ts"
678
678
  export default {
679
679
  buildConfig: {
680
680
  minify: {
@@ -693,7 +693,7 @@ Specifies the output directory of the build.
693
693
  - **Type**: `string`
694
694
  - **Default**: `./dist`
695
695
 
696
- ```js modern.config.ts
696
+ ```js title="modern.config.ts"
697
697
  export default defineConfig({
698
698
  buildConfig: {
699
699
  outDir: './dist/esm',
@@ -708,7 +708,7 @@ Generates code for the node environment by default, you can also specify `browse
708
708
  - **Type**: `'browser' | 'node'`
709
709
  - **Default**: `'node'`
710
710
 
711
- ```js modern.config.ts
711
+ ```js title="modern.config.ts"
712
712
  export default defineConfig({
713
713
  buildConfig: {
714
714
  platform: 'browser',
@@ -725,7 +725,7 @@ In `buildType: 'bundleless'` build mode, the reference path is redirected to ens
725
725
 
726
726
  In some scenarios, you may not need these functions, then you can turn it off with this configuration, and its reference path will not be changed after turning it off.
727
727
 
728
- ```js modern.config.ts
728
+ ```js title="modern.config.ts"
729
729
  export default {
730
730
  buildConfig: {
731
731
  redirect: {
@@ -752,7 +752,7 @@ import 'other-package/dist/index.css';
752
752
 
753
753
  But the package.json of this third-party package does not have the style file configured in the sideEffects
754
754
 
755
- ```json other-package/package.json
755
+ ```json title="other-package/package.json"
756
756
  {
757
757
  "sideEffects": ["dist/index.js"]
758
758
  }
@@ -766,7 +766,7 @@ At the same time you set [style.inject](#styleinject) to `true` and you will see
766
766
 
767
767
  At this point, you can use this configuration option to manually configure the module's `"sideEffects"` to support regular and functional forms.
768
768
 
769
- ```js modern.config.ts
769
+ ```js title="modern.config.ts"
770
770
  export default defineConfig({
771
771
  buildConfig: {
772
772
  sideEffects: [/\.css$/],
@@ -830,7 +830,7 @@ Add `Less` code to the beginning of the entry file.
830
830
  - **Type**: `string`
831
831
  - **Default**: `undefined`
832
832
 
833
- ```js modern.config.ts
833
+ ```js title="modern.config.ts"
834
834
  export default {
835
835
  buildConfig: {
836
836
  style: {
@@ -851,7 +851,7 @@ Configure the implementation library used by `Less`, if not specified, the built
851
851
 
852
852
  Specify the implementation library for `Less` when the `object` type is specified.
853
853
 
854
- ```js modern.config.ts
854
+ ```js title="modern.config.ts"
855
855
  export default {
856
856
  buildConfig: {
857
857
  style: {
@@ -865,7 +865,7 @@ export default {
865
865
 
866
866
  For the `string` type, specify the path to the implementation library for `Less`
867
867
 
868
- ```js modern.config.ts
868
+ ```js title="modern.config.ts"
869
869
  export default {
870
870
  buildConfig: {
871
871
  style: {
@@ -895,7 +895,7 @@ Add `Sass` code to the beginning of the entry file.
895
895
  - **Type**: `string | Function`
896
896
  - **Default**: `undefined`
897
897
 
898
- ```js modern.config.ts
898
+ ```js title="modern.config.ts"
899
899
  export default {
900
900
  buildConfig: {
901
901
  style: {
@@ -917,7 +917,7 @@ Configure the implementation library used by `Sass`, the built-in version used i
917
917
 
918
918
  Specify the implementation library for `Sass` when the `object` type is specified.
919
919
 
920
- ```js modern.config.ts
920
+ ```js title="modern.config.ts"
921
921
  export default {
922
922
  buildConfig: {
923
923
  style: {
@@ -931,7 +931,7 @@ export default {
931
931
 
932
932
  For the `string` type, specify the path to the `Sass` implementation library
933
933
 
934
- ```js modern.config.ts
934
+ ```js title="modern.config.ts"
935
935
  export default {
936
936
  buildConfig: {
937
937
  style: {
@@ -978,7 +978,7 @@ const defaultConfig = {
978
978
 
979
979
  - **Example**:
980
980
 
981
- ```js modern.config.ts
981
+ ```js title="modern.config.ts"
982
982
  export default defineConfig({
983
983
  buildConfig: {
984
984
  style: {
@@ -999,7 +999,7 @@ Configure whether to insert CSS styles into JavaScript code in bundle mode.
999
999
 
1000
1000
  Set `inject` to `true` to enable this feature:
1001
1001
 
1002
- ```js modern.config.ts
1002
+ ```js title="modern.config.ts"
1003
1003
  export default defineConfig({
1004
1004
  buildConfig: {
1005
1005
  inject: true,
@@ -1011,7 +1011,7 @@ Once enabled, you will see the CSS code referenced in the source code included i
1011
1011
 
1012
1012
  For example, if you write `import './index.scss'` in the source code, you will see the following code in the output:
1013
1013
 
1014
- ```js dist/index.js
1014
+ ```js title="dist/index.js"
1015
1015
  // node_modules/style-inject/dist/style-inject.es.js
1016
1016
  function styleInject(css, ref) {
1017
1017
  // ...
@@ -1058,7 +1058,7 @@ CSS Modules configuration
1058
1058
 
1059
1059
  A common configuration is `localsConvention`, which changes the class name generation rules for css modules
1060
1060
 
1061
- ```js modern.config.ts
1061
+ ```js title="modern.config.ts"
1062
1062
  export default {
1063
1063
  buildConfig: {
1064
1064
  style: {
@@ -1092,7 +1092,7 @@ tailwindcss related configuration
1092
1092
  <details>
1093
1093
  <summary>Tailwind CSS configuration details</summary>
1094
1094
 
1095
- ```js modern.config.ts
1095
+ ```js title="modern.config.ts"
1096
1096
  const tailwind = {
1097
1097
  content: [
1098
1098
  './config/html/**/*.html',
@@ -1142,7 +1142,7 @@ type Target =
1142
1142
 
1143
1143
  For example, compile the code to `es5` syntax:
1144
1144
 
1145
- ```js modern.config.ts
1145
+ ```js title="modern.config.ts"
1146
1146
  export default defineConfig({
1147
1147
  buildConfig: {
1148
1148
  target: 'es5',
@@ -1161,7 +1161,7 @@ The elements of the array are configuration objects for `babel-plugin-import`, w
1161
1161
 
1162
1162
  **Example:**
1163
1163
 
1164
- ```ts modern.config.ts
1164
+ ```ts title="modern.config.ts"
1165
1165
  export default defineConfig({
1166
1166
  buildConfig: {
1167
1167
  transformImport: [
@@ -1186,7 +1186,7 @@ Specify global variables for external import of umd artifacts
1186
1186
  - **Type**: `Record<string, string>`
1187
1187
  - **Default**: `{}`
1188
1188
 
1189
- ```js modern.config.ts
1189
+ ```js title="modern.config.ts"
1190
1190
  export default {
1191
1191
  buildConfig: {
1192
1192
  umdGlobals: {
@@ -1226,7 +1226,7 @@ At this point the umd artifact will go to mount on `global.myLib`
1226
1226
 
1227
1227
  Also the function form can take one parameter, which is the output path of the current package file
1228
1228
 
1229
- ```js modern.config.ts
1229
+ ```js title="modern.config.ts"
1230
1230
  export default {
1231
1231
  buildConfig: {
1232
1232
  format: 'umd',
@@ -13,7 +13,7 @@ A build preset string or preset function. Provides out-of-the-box build configur
13
13
 
14
14
  The string form allows you to use the built-in presets directly
15
15
 
16
- ```js modern.config.ts
16
+ ```js title="modern.config.ts"
17
17
  import { defineConfig } from '@modern-js/module-tools';
18
18
 
19
19
  export default defineConfig({
@@ -34,7 +34,7 @@ About the class [NPM](https://www.npmjs.com/) Package Manager
34
34
 
35
35
  :::
36
36
 
37
- ```json package.json
37
+ ```json title="package.json"
38
38
  {
39
39
  "main": ". /dist/lib/index.js",
40
40
  "module": ". /dist/es/index.js",
@@ -72,7 +72,7 @@ export const buildConfig = [
72
72
 
73
73
  Used under class [NPM](https://www.npmjs.com/) package manager, and Library supports a similar pattern to [unpkg](https://unpkg.com/). Additional `umd` artifacts are provided on top of the pre-defined `npm-library`.
74
74
 
75
- ```json package.json
75
+ ```json title="package.json"
76
76
  {
77
77
  "main": ". /dist/lib/index.js",
78
78
  "module": ". /dist/es/index.js",
@@ -120,7 +120,7 @@ A generic pattern for components (libraries) used under the class [NPM](https://
120
120
 
121
121
  For style files included in the source code, the artifacts provide the compiled files of the style and the source file of the style.
122
122
 
123
- ```json package.json
123
+ ```json title="package.json"
124
124
  {
125
125
  "main": ". /dist/lib/index.js", // bundleless type
126
126
  "module": ". /dist/es/index.js", // bundleless type
@@ -158,7 +158,7 @@ export const buildConfig = [
158
158
 
159
159
  Component (library) used under class [NPM](https://www.npmjs.com/) package manager, with support for class [unpkg](https://unpkg.com/) schema. Additional `umd` artifacts are provided on top of the pre-defined `npm-component`.
160
160
 
161
- ```json package.json
161
+ ```json title="package.json"
162
162
  {
163
163
  "main": ". /dist/lib/index.js", // bundleless type
164
164
  "module": ". /dist/es/index.js", // bundleless type
@@ -202,9 +202,9 @@ export const buildConfig = [
202
202
 
203
203
  When you want to use a `buildPreset` preset that supports other ECMAScript versions, you can directly add the supported versions to the `'npm-library'`, `'npm-library-with-umd'`, `'npm-component'`, `'npm-component-with-umd'` presets.
204
204
 
205
- For example, if you want the `'npm-library'` preset to support `'es2017'`, you can configure it as follows.
205
+ For example, if you want the `'npm-library'` preset to support `'es2017'`, you can configure it as follows.
206
206
 
207
- ```js modern.config.ts
207
+ ```js title="modern.config.ts"
208
208
  import { defineConfig } from '@modern-js/module-tools';
209
209
 
210
210
  export default defineConfig({
@@ -218,7 +218,7 @@ The way the function is configured, you can get the preset value from the `prese
218
218
 
219
219
  The following is an example of how a function can be configured to compress a build product.
220
220
 
221
- ```js modern.config.ts
221
+ ```js title="modern.config.ts"
222
222
  import { defineConfig } from '@modern-js/module-tools';
223
223
 
224
224
  export default defineConfig({
@@ -240,8 +240,8 @@ export default defineConfig({
240
240
 
241
241
  The function form of `buildPreset` contains a function parameter in the form of an object. The object contains the following fields.
242
242
 
243
- * `preset`
244
- * `extendPreset`
243
+ - `preset`
244
+ - `extendPreset`
245
245
 
246
246
  #### `preset`
247
247
 
@@ -249,9 +249,9 @@ Type: **Object**
249
249
 
250
250
  Contains the build configurations corresponding to all available build presets. Build configurations can be used by means of the strings supported by `buildPreset` or by means of underscore commands for those strings. The following are examples of the use of both approaches.
251
251
 
252
- <CH.Spotlight>
252
+ - Use the strings supported by `buildPreset`.
253
253
 
254
- ```ts modern.config.ts
254
+ ```ts title="modern.config.ts"
255
255
  import { defineConfig } from '@modern-js/module-tools';
256
256
 
257
257
  export default defineConfig({
@@ -260,25 +260,10 @@ export default defineConfig({
260
260
  },
261
261
  });
262
262
  ```
263
- ---
264
263
 
265
- Use the strings supported by `buildPreset`.
264
+ - Use the underscore naming convention for strings supported by `buildPreset`.
266
265
 
267
- ```ts modern.config.ts
268
- import { defineConfig } from '@modern-js/module-tools';
269
-
270
- export default defineConfig({
271
- buildPreset({ preset }) {
272
- return preset['npm-library'];
273
- },
274
- });
275
- ```
276
-
277
- ---
278
-
279
- Use the underscore naming convention for strings supported by `buildPreset`.
280
-
281
- ```ts modern.config.ts
266
+ ```ts title="modern.config.ts"
282
267
  import { defineConfig } from '@modern-js/module-tools';
283
268
 
284
269
  export default defineConfig({
@@ -288,8 +273,6 @@ export default defineConfig({
288
273
  });
289
274
  ```
290
275
 
291
- </CH.Spotlight>
292
-
293
276
  #### `extendPreset`
294
277
 
295
278
  Type: `Function`
@@ -300,7 +283,7 @@ Tool function for extending a `buildPreset` to modify the build configuration co
300
283
 
301
284
  For example, adding the `define` configuration to the `'npm-library'` build preset.
302
285
 
303
- ```ts modern.config.ts
286
+ ```ts title="modern.config.ts"
304
287
  import { defineConfig } from '@modern-js/module-tools';
305
288
 
306
289
  export default defineConfig({
@@ -313,4 +296,3 @@ export default defineConfig({
313
296
  },
314
297
  });
315
298
  ```
316
-