@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
@@ -815,25 +815,24 @@ The `raw` option may be particularly useful if you need to apply different style
815
815
 
816
816
  All that needs to be done is to add a `print` under `designSystem.extend.screens`.
817
817
 
818
- ``js
818
+ ```js
819
819
  const designSystem = {
820
- extend: {
821
- screens: {
822
- print: { raw: 'print' },
823
- // => @media print { ... }
824
- },
825
- },
820
+ extend: {
821
+ screens: {
822
+ print: { raw: 'print' },
823
+ // => @media print { ... }
824
+ },
825
+ },
826
826
  };
827
+ ```
827
828
 
828
- ````
829
-
830
- Then, a class such as ``print:text-black`` can be used to specify a style that is applied only when someone tries to print a page: ``
829
+ Then, a class such as `print:text-black` can be used to specify a style that is applied only when someone tries to print a page: ``
831
830
 
832
831
  ```html
833
832
  <div class="text-gray-700 print:text-black">
834
833
  <! -- ... -->
835
834
  </div>
836
- ````
835
+ ```
837
836
 
838
837
  ### Dark Mode
839
838
 
@@ -925,29 +924,38 @@ The rest of the theme section is used to configure the values available for each
925
924
 
926
925
  For example, the `borderRadius` property allows you to customize the ``utilities` that will generate the rounded corners.
927
926
 
928
- ``js
927
+ ```js
929
928
  const designSystem = {
930
- borderRadius: {
931
- none: '0',
932
- sm: '.125rem',
933
- default: '.25rem',
934
- lg: '.5rem',
935
- full: '9999px',
936
- },
929
+ borderRadius: {
930
+ none: '0',
931
+ sm: '.125rem',
932
+ default: '.25rem',
933
+ lg: '.5rem',
934
+ full: '9999px',
935
+ },
937
936
  };
938
-
939
- ````
937
+ ```
940
938
 
941
939
  ** The attribute name determines the suffix of the generated class, and the value determines the value of the actual CSS declaration. **
942
- The example ``borderRadius`` configuration above will generate the following CSS classes.
940
+ The example `borderRadius` configuration above will generate the following CSS classes.
943
941
 
944
942
  ```css
945
- .rounded-none { border-radius: 0 }
946
- .rounded-sm { border-radius: .125rem }
947
- .rounded { border-radius: .25rem }
948
- .rounded-lg { border-radius: .5rem }
949
- .rounded-full { border-radius: 9999px }
950
- ````
943
+ .rounded-none {
944
+ border-radius: 0;
945
+ }
946
+ .rounded-sm {
947
+ border-radius: 0.125rem;
948
+ }
949
+ .rounded {
950
+ border-radius: 0.25rem;
951
+ }
952
+ .rounded-lg {
953
+ border-radius: 0.5rem;
954
+ }
955
+ .rounded-full {
956
+ border-radius: 9999px;
957
+ }
958
+ ```
951
959
 
952
960
  You will notice that the `rounded` class is created without the suffix in the theme configuration using the `default` attribute. This is a common convention in Tailwind CSS supported by many (though not all) of the core plugins.
953
961
 
@@ -961,7 +969,7 @@ Out of the box, your project will automatically inherit values from the default
961
969
 
962
970
  To override the options in the default configuration, add the properties to be overridden to `designSystem` at
963
971
 
964
- ```js modern.config.ts
972
+ ```js title="modern.config.ts"
965
973
  import { defineConfig } from '@modern-js/module-tools';
966
974
 
967
975
  const designSystem = {
@@ -991,7 +999,7 @@ If you want to keep the default values of the theme options but add new values,
991
999
 
992
1000
  For example, if you want to add an additional breakpoint but keep the existing one, you can extend the `screens` property with.
993
1001
 
994
- ```js modern.config.ts
1002
+ ```js title="modern.config.ts"
995
1003
  import { defineConfig } from '@modern-js/module-tools';
996
1004
 
997
1005
  const designSystem = {
@@ -1010,7 +1018,7 @@ export default defineConfig({
1010
1018
 
1011
1019
  You can certainly override some parts of the default theme and extend other parts of the default theme in the same configuration: the
1012
1020
 
1013
- ```js modern.config.ts
1021
+ ```js title="modern.config.ts"
1014
1022
  import { defineConfig } from '@modern-js/module-tools';
1015
1023
 
1016
1024
  const designSystem = {
@@ -1040,7 +1048,7 @@ If you need to reference another value in the configuration, you can do so by pr
1040
1048
 
1041
1049
  For example, you can generate `fill` utilities for each color in the palette by referring to `theme('colors')` on the `fill` configuration.
1042
1050
 
1043
- ```js modern.config.ts
1051
+ ```js title="modern.config.ts"
1044
1052
  import { defineConfig } from '@modern-js/module-tools';
1045
1053
 
1046
1054
  const designSystem = {
@@ -1061,7 +1069,7 @@ The `theme()` function tries to find the value you are looking for from an alrea
1061
1069
 
1062
1070
  If for any reason you want to reference a value in the default configuration, you can import it from `tailwindcss/defaultTheme`. A useful example would be to add one of the fonts provided by the default configuration to.
1063
1071
 
1064
- ```js modern.config.ts
1072
+ ```js title="modern.config.ts"
1065
1073
  import { defineConfig } from '@modern-js/module-tools';
1066
1074
 
1067
1075
  const defaultTheme = require('tailwindcss/defaultTheme');
@@ -1126,7 +1134,7 @@ const designSystem = {
1126
1134
 
1127
1135
  Another example is to add a new property to a custom plugin for referencing. For example, if you write a gradient plugin for your project, you can add a gradient property to the theme object referenced by that plugin.
1128
1136
 
1129
- ```js modern.config.ts
1137
+ ```js title="modern.config.ts"
1130
1138
  import { defineConfig } from '@modern-js/module-tools';
1131
1139
 
1132
1140
  const designSystem = {
@@ -25,7 +25,7 @@ To learn how to write plugins, please refer to the [Plugin Writing Guide](/plugi
25
25
 
26
26
  To use plugins from npm, you need to install them using a package manager and import them in your configuration file.
27
27
 
28
- ```js modern.config.ts
28
+ ```js title="modern.config.ts"
29
29
  import { myPlugin } from 'my-plugin';
30
30
 
31
31
  export default defineConfig({
@@ -37,7 +37,7 @@ export default defineConfig({
37
37
 
38
38
  To use plugins from a local code repository, you can directly import them using a relative path.
39
39
 
40
- ```js modern.config.ts
40
+ ```js title="modern.config.ts"
41
41
  import { myPlugin } from './plugins/myPlugin';
42
42
 
43
43
  export default defineConfig({
@@ -49,7 +49,7 @@ export default defineConfig({
49
49
 
50
50
  If a plugin provides custom configuration options, you can pass the configuration through the plugin function's parameters.
51
51
 
52
- ```js modern.config.ts
52
+ ```js title="modern.config.ts"
53
53
  import { myPlugin } from 'my-plugin';
54
54
 
55
55
  export default defineConfig({
@@ -17,7 +17,7 @@ You need to enable the unit testing feature with `pnpm run new` first.
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
 
20
- ```js modern.config.ts
20
+ ```js title="modern.config.ts"
21
21
  import { defineConfig } from '@modern-js/module-tools';
22
22
 
23
23
  export default defineConfig({
@@ -31,7 +31,7 @@ export default defineConfig({
31
31
 
32
32
  When the value is of type `Function`, the default configuration is passed as the first parameter and a new Jest configuration object needs to be returned.
33
33
 
34
- ```js modern.config.ts
34
+ ```js title="modern.config.ts"
35
35
  import { defineConfig } from '@modern-js/module-tools';
36
36
 
37
37
  export default defineConfig({
@@ -21,7 +21,7 @@ The following Hooks are triggered in order when the `build` command is executed.
21
21
 
22
22
  Triggered before the execution of the overall build process.
23
23
 
24
- ``` ts
24
+ ```ts
25
25
  export const myPlugin = (): CliPlugin<ModuleTools> => ({
26
26
  name: 'my-plugin',
27
27
 
@@ -37,7 +37,7 @@ export const myPlugin = (): CliPlugin<ModuleTools> => ({
37
37
 
38
38
  Parameters and return value types.
39
39
 
40
- ``` ts
40
+ ```ts
41
41
  type Options = { options: { config: BuildConfig; cliOptions: BuildCommandOptions } }
42
42
 
43
43
  export interface BuildCommandOptions {
@@ -58,7 +58,7 @@ type Return = BuildConfig;
58
58
 
59
59
  Based on the build configuration, Module Tools will split the overall build into multiple sub-build tasks. The Hook will be triggered before each build subtask.
60
60
 
61
- ``` ts
61
+ ```ts
62
62
  export const myPlugin = (): CliPlugin<ModuleTools> => ({
63
63
  name: 'my-plugin',
64
64
 
@@ -80,7 +80,7 @@ Parameters and return value types.
80
80
 
81
81
  Triggered after the end of each build subtask.
82
82
 
83
- ``` ts
83
+ ```ts
84
84
  export const myPlugin = (): CliPlugin<ModuleTools> => ({
85
85
  name: 'my-plugin',
86
86
 
@@ -96,7 +96,7 @@ export const myPlugin = (): CliPlugin<ModuleTools> => ({
96
96
 
97
97
  Parameters and return value types.
98
98
 
99
- ``` ts
99
+ ```ts
100
100
  export interface BuildTaskResult {
101
101
  status: 'success' | 'fail';
102
102
  message?: string;
@@ -108,7 +108,7 @@ export interface BuildTaskResult {
108
108
 
109
109
  Triggered after the end of the overall build process.
110
110
 
111
- ``` ts
111
+ ```ts
112
112
  export const myPlugin = (): CliPlugin<ModuleTools> => ({
113
113
  name: 'my-plugin',
114
114
 
@@ -124,7 +124,7 @@ export const myPlugin = (): CliPlugin<ModuleTools> => ({
124
124
 
125
125
  Parameters and return value types.
126
126
 
127
- ``` ts
127
+ ```ts
128
128
  export interface BuildResult {
129
129
  status: 'success' | 'fail';
130
130
  message?: string;
@@ -151,7 +151,7 @@ Hooks are triggered in the following order after executing `build --platform`.
151
151
 
152
152
  Gets information about the tasks that need to be run when executing the `build --platform` command.
153
153
 
154
- ``` ts
154
+ ```ts
155
155
  export const myPlugin = (): CliPlugin<ModuleTools> => ({
156
156
  name: 'my-plugin',
157
157
 
@@ -173,7 +173,7 @@ export const myPlugin = (): CliPlugin<ModuleTools> => ({
173
173
 
174
174
  Types of parameters entered and returned.
175
175
 
176
- ``` ts
176
+ ```ts
177
177
  export interface RegisterBuildPlatformResult {
178
178
  platform: string | string[];
179
179
  build: (
@@ -187,7 +187,7 @@ export interface RegisterBuildPlatformResult {
187
187
 
188
188
  Triggers all registered build tasks when the `build --platform` command is executed. `beforeBuildPlatform` will be triggered before the execution of the overall build task.
189
189
 
190
- ``` ts
190
+ ```ts
191
191
  export const myPlugin = (): CliPlugin<ModuleTools> => ({
192
192
  name: 'my-plugin',
193
193
 
@@ -203,7 +203,7 @@ export const myPlugin = (): CliPlugin<ModuleTools> => ({
203
203
 
204
204
  Types of parameters entered and returned.
205
205
 
206
- ``` ts
206
+ ```ts
207
207
  export interface RegisterBuildPlatformResult {
208
208
  platform: string | string[];
209
209
  build: (
@@ -217,7 +217,7 @@ export interface RegisterBuildPlatformResult {
217
217
 
218
218
  When the `build --platform` command is executed, all registered build tasks will be triggered. `buildPlatform` will be triggered before each build task is executed.
219
219
 
220
- ``` ts
220
+ ```ts
221
221
  export const myPlugin = (): CliPlugin<ModuleTools> => ({
222
222
  name: 'my-plugin',
223
223
 
@@ -233,7 +233,7 @@ export const myPlugin = (): CliPlugin<ModuleTools> => ({
233
233
 
234
234
  Types of parameters entered and returned.
235
235
 
236
- ``` ts
236
+ ```ts
237
237
  export interface Options {
238
238
  platform: string;
239
239
  }
@@ -243,7 +243,7 @@ export interface Options {
243
243
 
244
244
  When the `build --platform` command is executed, all registered build tasks will be triggered. `afterBuildPlatform` will be triggered after the overall platform build task is finished.
245
245
 
246
- ``` ts
246
+ ```ts
247
247
  export const myPlugin = (): CliPlugin<ModuleTools> => ({
248
248
  name: 'my-plugin',
249
249
 
@@ -291,7 +291,7 @@ Register dev tool related data. Mainly contains.
291
291
  * Whether to execute the source code build before running the dev task
292
292
  * The function to execute the dev task.
293
293
 
294
- ``` ts
294
+ ```ts
295
295
  export const myPlugin = (): CliPlugin<ModuleTools> => ({
296
296
  name: 'my-plugin',
297
297
 
@@ -320,7 +320,7 @@ export const myPlugin = (): CliPlugin<ModuleTools> => ({
320
320
 
321
321
  Types of parameters entered and returned.
322
322
 
323
- ``` ts
323
+ ```ts
324
324
  export interface DevToolData {
325
325
  name: string;
326
326
  subCommands?: string[];
@@ -345,7 +345,7 @@ The currently supported Storybook dev supports using source code products as dev
345
345
 
346
346
  Triggered before the dev task is executed after all dev tool metadata has been collected.
347
347
 
348
- ``` ts
348
+ ```ts
349
349
  export const myPlugin = (): CliPlugin<ModuleTools> => ({
350
350
  name: 'my-plugin',
351
351
 
@@ -361,7 +361,7 @@ export const myPlugin = (): CliPlugin<ModuleTools> => ({
361
361
 
362
362
  Types of parameters entered and returned.
363
363
 
364
- ``` ts
364
+ ```ts
365
365
  export interface DevToolData {
366
366
  name: string;
367
367
  subCommands?: string[];
@@ -380,7 +380,7 @@ export interface DevToolData {
380
380
 
381
381
  `beforeDevMenu` is triggered before the dev list/menu appears. Receives [inquirer question](https://github.com/SBoudrias/Inquirer.js#question) as argument. Default value is.
382
382
 
383
- ``` ts
383
+ ```ts
384
384
  const question = [
385
385
  {
386
386
  name: 'choiceDevTool',
@@ -394,7 +394,7 @@ const question = [
394
394
 
395
395
  `afterDevMenu` Triggered after selecting dev list/menu options.
396
396
 
397
- ``` ts
397
+ ```ts
398
398
  export const myPlugin = (): CliPlugin<ModuleTools> => ({
399
399
  name: 'my-plugin',
400
400
 
@@ -414,7 +414,7 @@ export const myPlugin = (): CliPlugin<ModuleTools> => ({
414
414
 
415
415
  Types of parameters entered and returned.
416
416
 
417
- ``` ts
417
+ ```ts
418
418
  export type { QuestionCollection } from 'inquirer';
419
419
 
420
420
  export interface Options {
@@ -441,7 +441,7 @@ export interface DevToolData {
441
441
 
442
442
  Triggered before the dev task is executed.
443
443
 
444
- ``` ts
444
+ ```ts
445
445
  export const myPlugin = (): CliPlugin<ModuleTools> => ({
446
446
  name: 'my-plugin',
447
447
 
@@ -457,7 +457,7 @@ export const myPlugin = (): CliPlugin<ModuleTools> => ({
457
457
 
458
458
  Types of parameters entered and returned.
459
459
 
460
- ``` ts
460
+ ```ts
461
461
  export interface DevToolData {
462
462
  name: string;
463
463
  subCommands?: string[];
@@ -476,7 +476,7 @@ export interface DevToolData {
476
476
 
477
477
  Triggered when the dev task process is interrupted.
478
478
 
479
- ``` ts
479
+ ```ts
480
480
  export const myPlugin = (): CliPlugin<ModuleTools> => ({
481
481
  name: 'my-plugin',
482
482
 
@@ -1,11 +1,11 @@
1
- ```js modern.config.ts
1
+ ```js title="modern.config.ts"
2
2
  import { myEsbuildPlugin } from './myEsbuildPlugin';
3
3
 
4
4
  export default defineConfig({
5
5
  buildConfig: {
6
6
  esbuildOptions: options => {
7
7
  options.plugins = [myEsbuildPlugin, ...options.plugins];
8
- return option;
8
+ return options;
9
9
  },
10
10
  },
11
11
  });
@@ -19,43 +19,30 @@ For the handling of static files, the module project currently supports the foll
19
19
  - Set the static resource path to `. /assets`.
20
20
  - Files less than **10kb** will be inlined into the code.
21
21
 
22
+ ### Example
23
+
22
24
  Let us look at the following example:
23
25
 
24
- <CH.Spotlight>
26
+ - Project source code:
25
27
 
26
- ```ts ./src/asset.ts
28
+ ```ts title="./src/asset.ts"
27
29
  import img from './bg.png';
28
30
  //...
29
31
  ```
30
32
 
31
- ---
32
-
33
- Project source code.
34
-
35
-
36
- ---
37
-
38
- If the size of `bg.png` is less than 10 kb, then the output directory structure and file content are.
39
-
40
- <CH.Code>
33
+ - If the size of `bg.png` is less than 10 kb, then the output directory structure and file content are.
41
34
 
42
35
  ```bash
43
36
  ./dist
44
37
  └── asset.js
45
38
  ```
46
39
 
47
- ---
48
-
49
- ```js ./dist/asset.js
40
+ ```js title="./dist/asset.js"
50
41
  var bg_default = 'data:image/png;base64,';
51
42
  console.info(bg_default);
52
43
  ```
53
44
 
54
- </CH.Code>
55
-
56
- If the size of `bg.png` is larger than 10 kb, then the output directory structure and file content are.
57
-
58
- <CH.Code>
45
+ - If the size of `bg.png` is larger than 10 kb, then the output directory structure and file content are.
59
46
 
60
47
  ```bash
61
48
  ./dist
@@ -64,17 +51,11 @@ If the size of `bg.png` is larger than 10 kb, then the output directory structur
64
51
  └── bg.13e2aba2.png
65
52
  ```
66
53
 
67
- ---
68
-
69
- ```js ./dist/asset.js
54
+ ```js title="./dist/asset.js"
70
55
  import img from './assets/bg.13e2aba2.png';
71
56
  console.info(img);
72
57
  ```
73
58
 
74
- </CH.Code>
75
-
76
- </CH.Spotlight>
77
-
78
59
  When wanting to modify the default behavior, the following API can be used:
79
60
 
80
61
  - `asset.path`: modify the output path of the static resource file.
@@ -25,33 +25,19 @@ export default defineConfig({
25
25
  In the ["How to handle third-party dependencies"](/en/guide/advance/external-dependency) chapter, we know that we can control whether or not the project packages third-party dependencies via the [`autoExternals`](/en/api/config/build-config#autoexternal) and [`externals`](/en/api/config/build-config#externals) APIs.
26
26
  So when building umd artifacts, we can also use it like this:
27
27
 
28
- <CH.Spotlight>
28
+ ### Example
29
29
 
30
- ```json package.json
31
- {
32
- "dependencies": {
33
- "react": "^17"
34
- //...other dependencies
35
- }
36
- }
37
- ```
38
-
39
- ---
30
+ - If the project depends on `react`:
40
31
 
41
- If the project depends on `react`.
42
-
43
- ```json package.json
32
+ ```json title="package.json"
44
33
  {
45
34
  "dependencies": {
46
35
  "react": "^17"
47
- //...other dependencies
48
36
  }
49
37
  }
50
38
  ```
51
39
 
52
- ---
53
-
54
- `modern.config.ts`.
40
+ - `modern.config.ts`:
55
41
 
56
42
  ```ts
57
43
  export default defineConfig({
@@ -63,20 +49,16 @@ export default defineConfig({
63
49
  });
64
50
  ```
65
51
 
66
- ---
67
-
68
- When a `react` dependency is used in the source code.
52
+ - When a `react` dependency is used in the source code:
69
53
 
70
- ```tsx src/index.ts
54
+ ```tsx title="src/index.ts"
71
55
  import React from 'react';
72
56
  console.info(React);
73
57
  ```
74
58
 
75
- ---
76
-
77
- The `react` code is not bundled into the artifact at this point.
59
+ - The `react` code is not bundled into the artifact at this point:
78
60
 
79
- ```js dist/index.js focus=1:7
61
+ ```js title="dist/index.js"
80
62
  (function (global, factory) {
81
63
  if (typeof module === 'object' && typeof module.exports === 'object')
82
64
  factory(exports, require('react'));
@@ -103,42 +85,18 @@ The `react` code is not bundled into the artifact at this point.
103
85
  });
104
86
  ```
105
87
 
106
- </CH.Spotlight>
107
-
108
88
  We know from the above example that when using the `autoExternal` and `externals` APIs.
109
89
 
110
90
  - In a Node.js environment, you can get the react dependency with `require('react')`.
111
91
  - In a browser environment, you can get the react dependency via `global.react`.
112
92
 
93
+ ### Global variable names of third-party dependencies
94
+
113
95
  However, in the browser environment, when getting third-party dependencies, **global variable names are not necessarily identical to the dependency names**, so you have to use the [`buildConfig.umdGlobals`](/en/api/config/build-config#umdglobals) API.
114
96
 
115
97
  Again using the previous example, when the `react` dependency exists in the browser environment as a `windows.React` or `global.React` global variable, then:
116
98
 
117
- <CH.Spotlight>
118
-
119
- ```json package.json
120
- {
121
- "devDependencies": {
122
- "react": "^17"
123
- }
124
- }
125
- ```
126
-
127
- ---
128
-
129
- If the project depends on `react`.
130
-
131
- ```json package.json
132
- {
133
- "devDependencies": {
134
- "react": "^17"
135
- }
136
- }
137
- ```
138
-
139
- ---
140
-
141
- `modern.config.ts` config file。
99
+ - `modern.config.ts` config file:
142
100
 
143
101
  ```ts
144
102
  export default defineConfig({
@@ -151,20 +109,16 @@ export default defineConfig({
151
109
  });
152
110
  ```
153
111
 
154
- ---
155
-
156
- When a `react` dependency is used in the source code.
112
+ When a `react` dependency is used in the source code:
157
113
 
158
- ```tsx src/index.ts
114
+ ```tsx title="src/index.ts"
159
115
  import React from 'react';
160
116
  console.info(React);
161
117
  ```
162
118
 
163
- ---
119
+ At this point we will see the output code like this:
164
120
 
165
- At this point we will see the output code like this.
166
-
167
- ```js dist/index.js focus=12:18
121
+ ```js title="dist/index.js"
168
122
  (function (global, factory) {
169
123
  if (typeof module === 'object' && typeof module.exports === 'object')
170
124
  factory();
@@ -187,15 +141,13 @@ At this point we will see the output code like this.
187
141
  });
188
142
  ```
189
143
 
190
- </CH.Spotlight>
191
-
192
144
  The project can then run in the browser and use the `React` variables that exist on the global object.
193
145
 
194
146
  ## Changing the name of a global variable in a project
195
147
 
196
148
  When we package the following code into an umd artifact and run it in the browser, we can use the module via `window.index`.
197
149
 
198
- ```ts ./src/index.ts
150
+ ```ts title="./src/index.ts"
199
151
  export default () => {
200
152
  console.info('hello world');
201
153
  };
@@ -203,7 +155,7 @@ export default () => {
203
155
 
204
156
  ** By default, the name of the source file is used as the name of the module's global variable in the browser. **For the above example, the artifact would read as follows:
205
157
 
206
- ```js ./dist/index.js focus=9:9
158
+ ```js title="./dist/index.js"
207
159
  (function (global, factory) {
208
160
  if (typeof module === 'object' && typeof module.exports === 'object')
209
161
  factory(exports);
@@ -233,7 +185,7 @@ export default defineConfig({
233
185
 
234
186
  The build artifact at this point are:
235
187
 
236
- ```js ./dist/index.js focus=9:9
188
+ ```js title="./dist/index.js"
237
189
  (function (global, factory) {
238
190
  if (typeof module === 'object' && typeof module.exports === 'object')
239
191
  factory(exports);