@modern-js/module-tools-docs 2.0.0-beta.4

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 (163) hide show
  1. package/LICENSE +144 -0
  2. package/docs/.island/config.ts +245 -0
  3. package/docs/.island/dist/404.html +41 -0
  4. package/docs/.island/dist/assets/before-getting-started.1b82b538.js +87 -0
  5. package/docs/.island/dist/assets/before-getting-started.582a31cc.js +87 -0
  6. package/docs/.island/dist/assets/build-config.72eb0918.js +804 -0
  7. package/docs/.island/dist/assets/build-config.d8bb1658.js +809 -0
  8. package/docs/.island/dist/assets/build-preset.96805d7d.js +256 -0
  9. package/docs/.island/dist/assets/build-preset.c20dcd40.js +256 -0
  10. package/docs/.island/dist/assets/build-your-ui.7f349247.js +2 -0
  11. package/docs/.island/dist/assets/build-your-ui.a8361604.js +2 -0
  12. package/docs/.island/dist/assets/command-preview.2d45fc82.js +264 -0
  13. package/docs/.island/dist/assets/command-preview.dc51b953.js +264 -0
  14. package/docs/.island/dist/assets/components.esm.03560353.js +9 -0
  15. package/docs/.island/dist/assets/design-system.86694ff5.js +1254 -0
  16. package/docs/.island/dist/assets/design-system.c4745cce.js +639 -0
  17. package/docs/.island/dist/assets/dev.1d326a37.js +37 -0
  18. package/docs/.island/dist/assets/dev.1fd06000.js +37 -0
  19. package/docs/.island/dist/assets/down.f35427d3.svg +1 -0
  20. package/docs/.island/dist/assets/extension.12299fd6.js +2 -0
  21. package/docs/.island/dist/assets/extension.96dc63a4.js +2 -0
  22. package/docs/.island/dist/assets/getting-started.40e9218d.js +117 -0
  23. package/docs/.island/dist/assets/getting-started.b1ed3f10.js +114 -0
  24. package/docs/.island/dist/assets/github.3bf8ccee.svg +1 -0
  25. package/docs/.island/dist/assets/index.2b2347ea.js +33 -0
  26. package/docs/.island/dist/assets/index.6cef6f5f.js +4 -0
  27. package/docs/.island/dist/assets/index.cb118238.js +36 -0
  28. package/docs/.island/dist/assets/index.ccb6ce27.js +4 -0
  29. package/docs/.island/dist/assets/island_inject.11a12ecc.js +1 -0
  30. package/docs/.island/dist/assets/island_inject.b13deaee.js +1 -0
  31. package/docs/.island/dist/assets/loading.8c9bb911.svg +1 -0
  32. package/docs/.island/dist/assets/modify-output-product.7f6bff35.js +100 -0
  33. package/docs/.island/dist/assets/modify-output-product.b91eff1f.js +100 -0
  34. package/docs/.island/dist/assets/moon.6b705924.svg +3 -0
  35. package/docs/.island/dist/assets/plugin.895932d8.js +42 -0
  36. package/docs/.island/dist/assets/plugin.d2fbc531.js +42 -0
  37. package/docs/.island/dist/assets/publish-your-project.21b8309f.js +164 -0
  38. package/docs/.island/dist/assets/publish-your-project.8d398b17.js +166 -0
  39. package/docs/.island/dist/assets/right.89674cd7.svg +1 -0
  40. package/docs/.island/dist/assets/search.0aea6901.svg +1 -0
  41. package/docs/.island/dist/assets/search.1c85d17c.js +3 -0
  42. package/docs/.island/dist/assets/search.484eca11.js +222 -0
  43. package/docs/.island/dist/assets/search.54fca8d0.js +3 -0
  44. package/docs/.island/dist/assets/style.09015a4b.css +1 -0
  45. package/docs/.island/dist/assets/style.2e5f7bc2.css +1970 -0
  46. package/docs/.island/dist/assets/sun.841dac10.svg +11 -0
  47. package/docs/.island/dist/assets/test-your-project.18bd4582.js +190 -0
  48. package/docs/.island/dist/assets/test-your-project.f53bebf7.js +190 -0
  49. package/docs/.island/dist/assets/test.0da1f99f.js +67 -0
  50. package/docs/.island/dist/assets/test.0e81f002.js +66 -0
  51. package/docs/.island/dist/assets/translator.b1077c44.svg +1 -0
  52. package/docs/.island/dist/assets/use-micro-generator.7d9e4016.js +60 -0
  53. package/docs/.island/dist/assets/use-micro-generator.db5520c1.js +60 -0
  54. package/docs/.island/dist/assets/using-storybook.57ea6b77.js +260 -0
  55. package/docs/.island/dist/assets/using-storybook.a2212f2e.js +260 -0
  56. package/docs/.island/dist/assets/welcome.0449a9c8.js +13 -0
  57. package/docs/.island/dist/assets/welcome.a8448931.js +13 -0
  58. package/docs/.island/dist/assets/why-module-engineering-solution.6ae8c0e3.js +26 -0
  59. package/docs/.island/dist/assets/why-module-engineering-solution.c9a45cbd.js +26 -0
  60. package/docs/.island/dist/chunk-COLCRJ2V.js +1 -0
  61. package/docs/.island/dist/chunk-K5FMOYDC.js +10 -0
  62. package/docs/.island/dist/chunk-WE42KMYS.js +26 -0
  63. package/docs/.island/dist/client-entry.js +3 -0
  64. package/docs/.island/dist/en/api/build-config.html +344 -0
  65. package/docs/.island/dist/en/api/build-preset.html +82 -0
  66. package/docs/.island/dist/en/api/design-system.html +155 -0
  67. package/docs/.island/dist/en/api/dev.html +45 -0
  68. package/docs/.island/dist/en/api/index.html +41 -0
  69. package/docs/.island/dist/en/api/plugin.html +48 -0
  70. package/docs/.island/dist/en/api/test.html +58 -0
  71. package/docs/.island/dist/en/guide/before-getting-started.html +127 -0
  72. package/docs/.island/dist/en/guide/build-your-ui.html +41 -0
  73. package/docs/.island/dist/en/guide/command-preview.html +100 -0
  74. package/docs/.island/dist/en/guide/extension.html +41 -0
  75. package/docs/.island/dist/en/guide/getting-started.html +76 -0
  76. package/docs/.island/dist/en/guide/modify-output-product.html +140 -0
  77. package/docs/.island/dist/en/guide/publish-your-project.html +91 -0
  78. package/docs/.island/dist/en/guide/test-your-project.html +72 -0
  79. package/docs/.island/dist/en/guide/use-micro-generator.html +65 -0
  80. package/docs/.island/dist/en/guide/using-storybook.html +113 -0
  81. package/docs/.island/dist/en/guide/welcome.html +53 -0
  82. package/docs/.island/dist/en/guide/why-module-engineering-solution.html +49 -0
  83. package/docs/.island/dist/en/index.html +42 -0
  84. package/docs/.island/dist/react-dom.js +1 -0
  85. package/docs/.island/dist/react-dom_client.js +1 -0
  86. package/docs/.island/dist/react.js +1 -0
  87. package/docs/.island/dist/react_jsx-runtime.js +10 -0
  88. package/docs/.island/dist/ssr-manifest.json +57 -0
  89. package/docs/.island/dist/test-result.png +0 -0
  90. package/docs/.island/dist/why-module-solution.png +0 -0
  91. package/docs/.island/dist/zh/api/build-config.html +347 -0
  92. package/docs/.island/dist/zh/api/build-preset.html +82 -0
  93. package/docs/.island/dist/zh/api/design-system.html +149 -0
  94. package/docs/.island/dist/zh/api/dev.html +46 -0
  95. package/docs/.island/dist/zh/api/index.html +41 -0
  96. package/docs/.island/dist/zh/api/plugin.html +48 -0
  97. package/docs/.island/dist/zh/api/test.html +59 -0
  98. package/docs/.island/dist/zh/guide/before-getting-started.html +127 -0
  99. package/docs/.island/dist/zh/guide/build-your-ui.html +41 -0
  100. package/docs/.island/dist/zh/guide/command-preview.html +100 -0
  101. package/docs/.island/dist/zh/guide/extension.html +41 -0
  102. package/docs/.island/dist/zh/guide/getting-started.html +79 -0
  103. package/docs/.island/dist/zh/guide/modify-output-product.html +140 -0
  104. package/docs/.island/dist/zh/guide/publish-your-project.html +92 -0
  105. package/docs/.island/dist/zh/guide/test-your-project.html +72 -0
  106. package/docs/.island/dist/zh/guide/use-micro-generator.html +65 -0
  107. package/docs/.island/dist/zh/guide/using-storybook.html +114 -0
  108. package/docs/.island/dist/zh/guide/welcome.html +53 -0
  109. package/docs/.island/dist/zh/guide/why-module-engineering-solution.html +49 -0
  110. package/docs/.island/dist/zh/index.html +42 -0
  111. package/docs/.island/index.html +39 -0
  112. package/docs/.island/styles/index.css +10 -0
  113. package/docs/en/api/build-config.md +501 -0
  114. package/docs/en/api/build-preset.md +214 -0
  115. package/docs/en/api/design-system.md +524 -0
  116. package/docs/en/api/dev.md +32 -0
  117. package/docs/en/api/index.md +3 -0
  118. package/docs/en/api/plugin.md +34 -0
  119. package/docs/en/api/test.md +48 -0
  120. package/docs/en/guide/advance/asset.mdx +132 -0
  121. package/docs/en/guide/advance/build-umd.mdx +241 -0
  122. package/docs/en/guide/advance/copy.md +235 -0
  123. package/docs/en/guide/advance/external-dependency.mdx +125 -0
  124. package/docs/en/guide/advance/in-depth-about-build.md +266 -0
  125. package/docs/en/guide/advance/in-depth-about-dev-command.md +22 -0
  126. package/docs/en/guide/basic/before-getting-started.md +187 -0
  127. package/docs/en/guide/basic/command-preview.md +204 -0
  128. package/docs/en/guide/basic/modify-output-product.md +145 -0
  129. package/docs/en/guide/basic/publish-your-project.md +115 -0
  130. package/docs/en/guide/basic/test-your-project.mdx +158 -0
  131. package/docs/en/guide/basic/use-micro-generator.md +35 -0
  132. package/docs/en/guide/basic/using-storybook.mdx +187 -0
  133. package/docs/en/guide/intro/getting-started.md +78 -0
  134. package/docs/en/guide/intro/welcome.md +14 -0
  135. package/docs/en/guide/intro/why-module-engineering-solution.md +17 -0
  136. package/docs/en/index.md +35 -0
  137. package/docs/public/test-result.png +0 -0
  138. package/docs/public/why-module-solution.png +0 -0
  139. package/docs/zh/api/build-config.md +570 -0
  140. package/docs/zh/api/build-preset.md +220 -0
  141. package/docs/zh/api/design-system.md +1147 -0
  142. package/docs/zh/api/dev.md +33 -0
  143. package/docs/zh/api/index.md +3 -0
  144. package/docs/zh/api/plugins.md +108 -0
  145. package/docs/zh/api/testing.md +52 -0
  146. package/docs/zh/guide/advance/asset.mdx +132 -0
  147. package/docs/zh/guide/advance/build-umd.mdx +232 -0
  148. package/docs/zh/guide/advance/copy.md +235 -0
  149. package/docs/zh/guide/advance/external-dependency.mdx +125 -0
  150. package/docs/zh/guide/advance/in-depth-about-build.md +267 -0
  151. package/docs/zh/guide/advance/in-depth-about-dev-command.md +26 -0
  152. package/docs/zh/guide/basic/before-getting-started.md +187 -0
  153. package/docs/zh/guide/basic/command-preview.md +204 -0
  154. package/docs/zh/guide/basic/modify-output-product.md +144 -0
  155. package/docs/zh/guide/basic/publish-your-project.md +112 -0
  156. package/docs/zh/guide/basic/test-your-project.mdx +158 -0
  157. package/docs/zh/guide/basic/use-micro-generator.md +35 -0
  158. package/docs/zh/guide/basic/using-storybook.mdx +186 -0
  159. package/docs/zh/guide/intro/getting-started.md +78 -0
  160. package/docs/zh/guide/intro/welcome.md +14 -0
  161. package/docs/zh/guide/intro/why-module-engineering-solution.md +17 -0
  162. package/docs/zh/index.md +29 -0
  163. package/package.json +19 -0
@@ -0,0 +1,204 @@
1
+ # Command Preview
2
+
3
+ Commands available for module engineering projects.
4
+
5
+ ## `modern build`
6
+
7
+ ``` bash
8
+ Usage: modern build [options]
9
+
10
+ Build module command
11
+
12
+ Options:
13
+ -w, --watch Build code in listening mode
14
+ --tsconfig [tsconfig] Specify the path to the tsconfig.json file (default:
15
+ ". /tsconfig.json")
16
+ --platform [platform] Build products for all or specified platforms
17
+ --no-dts disables DTS type file generation and type checking
18
+ --no-clear disables automatic clearing of product output directories
19
+ -h, --help Show information about the current command
20
+ ```
21
+
22
+ When you want to start a project build, you can execute the `modern build` command. When using this command, we can:
23
+
24
+ - When wanting to start a build in watch mode, use the `--watch` option.
25
+ - When you want to specify the path to the TypeScript configuration file read by the project build, use `-build --tsconfig . /path/config.json` option. This option overrides all [`buildConfig`](/zh/api/build-config) configurations in [`dts.tsconfigPath`](/zh/api/build-config).
26
+ - The `-no-dts` option can be used when the DTS type file generation and type checking behavior of the project needs to be turned off. **Note: The generation of type files depends on the results of type checking. If type checking is turned off, then type files will not be generated either**.
27
+ - The `--no-clear` option can be used when the automatic clearing of the product output directory needs to be turned off.
28
+
29
+ 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.
30
+
31
+ :::tip{title=Note}
32
+ When executing a Storybook build, it needs to read the project's build product. So **when running the `modern build --platform` command to start a Storybook build, run `modern build` once to ensure that the source build product exists**.
33
+ :::
34
+
35
+ ## `modern new`
36
+
37
+ ``` bash
38
+ Usage: modern new [options]
39
+
40
+ Execute the generator in a modular project scenario
41
+
42
+ Options:
43
+ -d, --debug Enable Debug mode, print debug log messages (default: false)
44
+ -c, --config <config> Generators run default configuration (JSON string)
45
+ --dist-tag <tag> Generator uses a special version of npm Tag
46
+ --registry customize npm Registry during generator runtime
47
+ -h, --help display help for command
48
+ ```
49
+
50
+ The `modern new` command is used to start the microgenerator functionality, which enables features for the project that are not provided by default.
51
+
52
+ The following features can currently be enabled.
53
+
54
+ - Storybook debugging
55
+ - Tailwind CSS support
56
+ - Modern.js Runtime API
57
+
58
+ You can learn more about these features in the [Using the micro generator](/zh/guide/use-micro-generator) section.
59
+
60
+ ## `modern dev`
61
+
62
+ ``` bash
63
+ Usage: modern dev [options]
64
+
65
+ Local development commands
66
+
67
+ Options:
68
+ -h, --help display help for command
69
+
70
+ Commands:
71
+ [dev-tools-subCommand]
72
+ ```
73
+
74
+ The module engineering solution provides the ability to use debugging tools, which can be started with the `modern dev` command. Note, however, that no debugging-related plugins are provided by default, so executing `modern dev` will prompt: *"No dev tools found available "*.
75
+
76
+ The officially supported debugging tool is [Storybook](https://storybook.js.org/), so you can run `modern dev` or `modern dev storybook` to execute it after you run `modern new` to enable it.
77
+
78
+ ## `modern test`
79
+
80
+ ``` bash
81
+ Usage: modern test [options]
82
+
83
+ Options:
84
+ -h, --help display help for command
85
+ ```
86
+ The `modern test` command will automatically run the `src/tests/*.test.(js|ts|jsx|tsx)` file as a test case.
87
+
88
+
89
+ ## `modern lint`
90
+
91
+ ``` bash
92
+ Usage: modern lint [options] [. .files]
93
+
94
+ lint and fix source files
95
+
96
+ Options:
97
+ --no-fix disable auto fix source file
98
+ -h, --help display help for command
99
+ ```
100
+
101
+ Run [ESLint](https://eslint.org/) to check the syntax of the code. Usually, we only need to check the part of the code that was changed in this commit with [lint-staged](https://github.com/okonet/lint-staged) during the `-git commit` phase.
102
+
103
+ - The `-no-fix` argument turns off the ability to automatically fix lint error code.
104
+
105
+ ## `-modern change`
106
+
107
+ ``` bash
108
+ Usage: modern change [options]
109
+
110
+ Create a changeset
111
+
112
+ Options:
113
+ --empty Create an empty changeset (default: false)
114
+ --open Open the created changeset in the editor (default: false)
115
+ -h, --help display help for command
116
+ ```
117
+
118
+ The `modern change` command is used to generate the required Markdown file for [changesets](https://github.com/changesets/changesets).
119
+
120
+ ## `modern pre`
121
+
122
+ ``` bash
123
+ Usage: modern pre [options] <enter|exit> [tag]
124
+
125
+ Entering and exiting pre-publishing mode
126
+
127
+ Options:
128
+ -h, --help display help for command
129
+ ```
130
+
131
+ You can use the `modern pre` command to [pre-release](https://github.com/atlassian/changesets/blob/main/docs/prereleases.md) a version before the official release.
132
+
133
+ ## `modern bump`
134
+
135
+ ``` bash
136
+ Usage: modern bump [options]
137
+
138
+ Use changesets to automatically update releases and changelogs
139
+
140
+ Options:
141
+ --canary Create a pre-release for testing (default: false)
142
+ --preid <tag> Specify an identifier when versioning a pre-release (default: "next")
143
+ --snapshot Create a special version for testing (default: false)
144
+ -h, --help display help for command
145
+ ```
146
+
147
+ Modify the version number in `package.json` according to the Markdown file of the changelog generated by [changesets](https://github.com/changesets/changesets), and generate the `CHANGELOG.md` file.
148
+
149
+ ## `modern release`
150
+
151
+ ``` bash
152
+ Usage: modern release [options]
153
+
154
+ Release npm packages
155
+
156
+ Options:
157
+ --tag <tag> Release npm packages with a specific tag (default: "")
158
+ --ignore-scripts release ignores the scripts command in package.json, only supported in pnpm monorepo
159
+ (default: "")
160
+ -h, --help display help for command
161
+ ```
162
+
163
+ The `-modern release` command releases the module to the [npm Registry](https://www.npmjs.com/).
164
+
165
+ - The `-tag` argument specifies the specific [dist tags](https://docs.npmjs.com/adding-dist-tags-to-packages) to be used for the release.
166
+
167
+ ## `modern gen-release-note`
168
+
169
+ ``` bash
170
+ Usage: modern gen-release-note [options]
171
+
172
+ Generate Release Note based on current repository changeset information
173
+
174
+ Options:
175
+ --repo <repo> The name of the repository to generate the Pull Request link, e.g.: modern-js-dev/modern.js
176
+ --custom <cumtom> Custom Release Note generation function
177
+ -h, --help display help for command
178
+ ```
179
+
180
+ Automatically generate [Release Note](https://en.wikipedia.org/wiki/Release_notes) based on the changeset information of the current repository.
181
+
182
+ :::tip{title=Note}
183
+ needs to be executed before the ``bump`` command.
184
+ :::
185
+
186
+ ## `modern upgrade`
187
+
188
+ ``` bash
189
+ Usage: modern upgrade [options]
190
+
191
+ Upgrade Modern.js to the latest version
192
+
193
+ Options:
194
+ --registry <registry> customize npm registry (default: "")
195
+ -d,--debug Enable Debug mode to print debug log messages (default: false)
196
+ --cwd <cwd> project path (default: "")
197
+ -h, --help display help for command
198
+ ```
199
+
200
+ The `modern upgrade` command is used to upgrade the project Modern.js related dependencies to the latest version.
201
+
202
+ Executing the command `npx modern upgrade` in the project root directory will update the Modern.js dependencies in `package.json` of the currently executing project to the latest version by default.
203
+
204
+ command is provided in `@modern-js/module-tools` version **>= 1.17.0**, previous versions can be upgraded using `npx @modern-js/upgrade`.
@@ -0,0 +1,145 @@
1
+ ## Modify output product
2
+
3
+ ## Default output products
4
+
5
+ When the `modern build` command is used in an initialized project, the products are generated according to the default configuration supported by Module Tools. The default supported configurations are as follows.
6
+
7
+ ``` typescript
8
+ import { defineConfig } from '@modern-js/module-tools';
9
+
10
+ export default defineConfig({
11
+ buildPreset: 'base-config',
12
+ });
13
+ ```
14
+
15
+ **The default generated product has the following characteristics**:
16
+
17
+ - The code format is [CommonJS](https://nodejs.org/api/modules.html#modules-commonjs-modules), or simply `cjs`.
18
+ - Code syntax is supported up to `ES6`.
19
+ - All code is packaged into a single file, i.e. **bundle** processing is performed.
20
+ - The output root directory is the `dist` directory under the project, and the output directory for type files is `dist/types`.
21
+
22
+ :::tip
23
+ 1. By "code syntax support up to ES6", we mean that the syntax supported by the product code will not exceed `ES6`. If the source code uses syntax above `ES6` (e.g. `ES2017`), it will be converted.
24
+ :::
25
+
26
+ You may have the following questions when you see this:
27
+
28
+ 1. what is `buildPreset`?
29
+ 2. what determines these characteristics of the output?
30
+
31
+ Then the next step is to first explain `buildPreset`.
32
+
33
+ ## buildPreset
34
+
35
+ `buildPreset` represents one or more sets of build-related configurations prepared in advance. By using the corresponding preset values of `buildPreset`, you can eliminate the troublesome and complicated configuration work and get the expected product.
36
+
37
+ ### String form of `buildPreset`
38
+
39
+ The value of a **build preset can be in the form of a string**, so a build preset of this form is called a preset string.
40
+
41
+ The module engineering solution provides generic build preset strings and corresponding variants, depending on the generic scenario in which the npm package is used. All currently supported preset strings can be viewed via the [BuildPreset API](/en/api/build-config). The relationship between **generic preset strings and variants** is explained here.
42
+
43
+ Among the generic preset strings, `"npm-library"` can be used in the scenario of developing npm packages of the library type, which is suitable for most common module type projects. When `"npm-library"` is set, the output product of the project will have the following characteristics:
44
+
45
+ - In the `dist/lib` directory you will get the product in the code format `cjs`, with syntax support up to `es6` and after packaging.
46
+ - In the `dist/es` directory, you get code in the format `esm`, with syntax support up to `es6` and packaged.
47
+ - In the `dist/types` directory, you get the type files. If it is not a TypeScript project, there is no such directory.
48
+
49
+ The default string `"npm-library"` is a variant of the original product with modified **code-syntax support** and a string naming change to `"npm-library-[es5 | es2016.... . es2020 | esnext]"`.
50
+
51
+ For example, if the output product is based on the preset string `"npm-library"` and the syntax supported by the product code is changed to `es2017`, then simply changing `"npm-library"` to `"npm-library-es2017"` would be sufficient.
52
+
53
+ ### Function form of `buildPreset`
54
+
55
+ **In addition to the string form, the value of a build preset can also be in the form of a function, where the specific configuration corresponding to a preset value can be printed or modified**.
56
+
57
+ For example, if the same effect as the preset string `"npm-library-es2017"` is achieved using the preset function form, it can be done as follows:
58
+
59
+ ``` typescript
60
+ import { defineConfig } from "@modern-js/module-tools";
61
+
62
+ export default defineConfig({
63
+ buildPreset({ preset }) {
64
+ return preset.NPM_LIBRARY.map(config => {
65
+ return { ... .config, target: 'es2017' }
66
+ });
67
+ },
68
+ });
69
+ ```
70
+
71
+ In the above code implementation, `preset.NPM_LIBRARY` corresponds to the preset string `"npm-library"`, which represents the `"npm-library"` equivalent of a multi-group build-related configuration. We traverse the `NPM_LIBRARY` array, which contains multiple `buildConfig` objects, with the `map` method. We make a shallow copy of the original `buildConfig` object and modify the shallow copy to get `buildConfig.target`, specifying it as `es2017`.
72
+ > The specific value of `preset.NPM_LIBRARY` can be viewed via the [BuildPreset API](/en/api/build-config). The `preset` object contains not only `NPM_LIBRARY`, but also other similar constants.
73
+
74
+ So what is the `buildConfig` object here? And what are the previously mentioned build product features based on?
75
+
76
+ We explain it next.
77
+
78
+ ## Build configuration (object)
79
+
80
+ **`buildConfig` is a configuration object that describes how to compile and generate build products**. What was mentioned at the beginning about "*features of build products*" are actually properties supported by `buildConfig`. The currently supported properties cover the needs of most module type projects when building products. `buildConfig` not only contains some of the properties that products have, but also some of the features needed to build products. The following is a brief list from a classification point of view:
81
+
82
+ **The basic attributes of a build product include:**
83
+
84
+ - Whether the product is packaged or not: the corresponding API is [`buildConfig.buildType`](/en/api/build-config#buildtype).
85
+ - Product support for syntax: the corresponding API is [`buildConfig.target`](/en/api/build-config#target).
86
+ - Output format: The corresponding API is [`buildConfig.format`](/en/api/build-config#format).
87
+ - How to handle the output type file: the corresponding API is [`buildConfig.dts`](/en/api/build-config#dts).
88
+ - How the sourceMap of the product is handled: the corresponding API is [`buildConfig.sourceMap`](/en/api/build-config#sourcemap).
89
+ - The input (or source file) corresponding to the output: the corresponding API is [`buildConfig.input`](/en/api/build-config#input).
90
+ - The directory of the output of the product: the corresponding API is [`buildConfig.outdir`](/en/api/build-config#outdir).
91
+ - The source directory of the build: the corresponding API is [`buildConfig.sourceDir`](/en/api/build-config#sourcedir).
92
+
93
+ **Common functions needed to build products include:**
94
+
95
+ - Alias: The corresponding API is [`buildConfig.alias`](/en/api/build-config#alias).
96
+ - Static resource handling: The corresponding API is [`buildConfig.asset`](/en/api/build-config#asset).
97
+ - Third-party dependency handling: The corresponding APIs are
98
+ * [`buildConfig.autoExternal`](/en/api/build-config#autoexternal).
99
+ * [`buildConfig.externals`](/en/api/build-config#externals).
100
+ - Copy: The corresponding API is [`buildConfig.copy`](/en/api/build-config#copy).
101
+ - Global variable substitution: the corresponding API is [`buildConfig.define`](/en/api/build-config#define).
102
+ - Specify [JSX](https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.html) compilation method, the corresponding API is [`buildConfig.jsx`](/en/api/build-config#jsx).
103
+
104
+ **Some advanced properties or less frequently used functions:**
105
+
106
+ - Product code compression: The corresponding API is [`buildConfig.minify`](/en/api/build-config#minify).
107
+ - Code splitting: [`buildConfig.splitting`](/en/api/build-config#splitting)
108
+ - Specify whether the build product is for the NodeJS environment or the browser environment: the corresponding API is [`buildConfig.platform`](/en/api/build-config#platform).
109
+ - umd product-related.
110
+ * Specifies the global variables imported externally to the umd product: the corresponding API is [`buildConfig.umdGlobals`](/en/api/build-config#umdglobals).
111
+ * Specify the module name of the umd product: the corresponding API is [`buildConfig.umdModuleName`](/en/api/build-config#umdmodulename).
112
+
113
+ In addition to the above categories, frequently asked questions and best practices about these APIs can be found at the following links.
114
+
115
+ * [What are `bundle` and `bundleless`?](/en/guide/advance/in-depth-about-build#bundle-and-bundleless)
116
+ * [The relationship between `input` and `sourceDir`](/en/guide/advance/in-depth-about-build#relationship-between-input-and-sourcedir)
117
+ * [The multiple ways of generating type files in products](/en/guide/advance/in-depth-about-build#declaration-type-files)
118
+ * [The use of `buildConfig.define` for different scenarios.](/en/guide/advance/in-depth-about-build#buildconfigdefine-usage-for-different-scenarios)
119
+ * [How to handle third-party dependencies?](/en/guide/advance/external-dependency)
120
+ * [How to use copy?](/en/guide/advance/copy)
121
+ * [How to build umd products?](/en/guide/advance/build-umd)
122
+ * [The capabilities currently supported by static resources.](/en/guide/advance/asset)
123
+
124
+ ## When to use `buildConfig`
125
+
126
+ `buildConfig` is one of the ways used to modify the product, **and only `buildConfig` will take effect when configured in conjunction with `buildPreset`**. So if configured as follows.
127
+
128
+ ``` typescript
129
+ import { defineConfig } from '@modern-js/module-tools';
130
+
131
+ export default defineConfig({
132
+ buildConfig: [{}],
133
+ buildPreset: 'base-config',
134
+ });
135
+ ```
136
+
137
+ Then at this point you will see the following prompt.
138
+
139
+ ``` bash
140
+ Since both 'buildConfig' and 'buildPreset' are present, only the 'buildConfig' configuration will take effect
141
+ ```
142
+
143
+ The set or sets of build-related configurations represented by `buildPreset` are composed of `buildConfig`, **which can be used to customize output products** when the current project needs cannot be met using `buildPreset`.
144
+
145
+ The process of using `buildConfig` is the process of thinking about "*what kind of build product to get*".
@@ -0,0 +1,115 @@
1
+ # Versioning and Publishing
2
+
3
+ An npm-type module project release process consists of two phases.
4
+
5
+ * The first phase is during development, where the developer needs to provide a change file to record changes that need to be released.
6
+ * The second phase is during release, where Module Tools can collect all the change files to update the version, update the release log, and release new packages to the [npm Registry](https://www.npmjs.com/).
7
+
8
+ ## Tracking changes
9
+
10
+ **Changes need to be logged when they happen to the project**. Changes that occur in a project are typically.
11
+
12
+ * New features
13
+ * Fixes to issues
14
+ * Configuration file changes
15
+ * ...
16
+
17
+ Once these changes have been made, the current changes need to be documented with the following command.
18
+
19
+ * [`modern change`](/zh/guide/command-preview#modern-change)
20
+
21
+ Executing the `modern change` command asks the developer several questions and generates a change log based on the developer's answers. The changelog file contains the type of change and its description, and is committed to the git repository.
22
+
23
+ ``` bash
24
+ $ npx modern change
25
+ 🦋 What kind of change is this for module-example? (current version is 0.1.0) - patch
26
+ 🦋 Please enter a summary for this change (this will be in the changelogs). Submit empty line to open external editor
27
+ 🦋 Summary - publish test
28
+ 🦋 === Releasing the following packages ===
29
+ 🦋 [Patch]
30
+ 🦋 module
31
+ 🦋 Is this your desired changeset? (Y/n) - true
32
+ 🦋 Changeset added! - you can now commit it
33
+ 🦋
34
+ 🦋 If you want to modify or expand on the changeset summary, you can find it here
35
+ 🦋 info /xxxxxx/module/.changeset/brave-dryers-agree.md
36
+ ```
37
+
38
+ When executed successfully, the resulting Markdown file containing the change log is saved in the project's `.changeset` directory. The contents will look like the following.
39
+
40
+ ``` markdown .changeset/brave-dryers-agree.md
41
+ ---
42
+ "``module-example'': patch
43
+ ---
44
+
45
+ publish test
46
+ ```
47
+
48
+ ## Version update
49
+
50
+ When the project version needs to be updated, execute the following command.
51
+
52
+ * [`modern bump`](/zh/guide/command-preview#modern-bump)
53
+
54
+ Executing `modern bump` will modify the version number in `package.json` based on the contents of the Markdown file in the `.changeset/` directory where the changes were recorded, and generate the `CHANGELOG.md` file. **These Markdown files are also deleted when the version update is complete, so they are "consumed "**.
55
+
56
+ ``` markdown CHANGELOG.md
57
+ # module
58
+
59
+ ## 0.1.1
60
+ ### Patch Changes
61
+
62
+ - publish test
63
+ ```
64
+
65
+ ## Publish
66
+
67
+ To publish a project, you can execute the following command.
68
+
69
+ * [`modern publish`](/zh/guide/command-preview#modern-release)
70
+
71
+ The `modern release` command publishes the project to the npm Registry.
72
+
73
+ The release is the `latest` version, which is also the official version. If you want to change the `dist-tag`, you can specify it with the `modern release --tag` command. For example.
74
+
75
+ ``` bash
76
+ modern release --tag beta
77
+ ```
78
+
79
+ However, if you want to change the version number of the current project to a pre-release as well, you need to use the `modern pre` command.
80
+
81
+ > `dist-tag` can be understood as: tagging the current release. Generally speaking, the `dist-tag` for the default release is `latest`, so you can consider `latest` as the `dist-tag` for the official release.
82
+
83
+ ## Pre-releases
84
+
85
+ When a pre-release is needed before the official release, the following command is executed.
86
+
87
+ * [`modern pre`](/zh/guide/command-preview#modern-pre)
88
+
89
+ First `modern pre enter <tag>` to enter pre-release mode, `<tag>` can be the same as the `tag` specified with the `modern release --tag` command when releasing the project.
90
+
91
+ ``` bash
92
+ $ npx modern pre enter next
93
+ 🦋 success Entered pre mode with tag next
94
+ 🦋 info Run `changeset version` to version packages with prerelease versions
95
+ ✨ Done in 5.30s.
96
+ Done in 5.30s. ```
97
+
98
+ Then you can update the specific version number with the `modern bump` command, **which doesn't actually "consume" the Markdown file that records the changes**: ``` bash
99
+
100
+ ``` bash
101
+ $ npx modern bump
102
+ 🦋 warn ===============================IMPORTANT!===============================
103
+ 🦋 warn You are in prerelease mode
104
+ 🦋 warn If you meant to do a normal release you should revert these changes and run `changeset pre exit`
105
+ 🦋 warn You can then run `changeset version` again to do a normal release
106
+ 🦋 warn ----------------------------------------------------------------------
107
+ 🦋 All files have been updated. review them and commit at your leisure
108
+ ```
109
+
110
+ Then you can see that the updated version number in `package.json` will look like this: `0.1.2-next.0`.
111
+
112
+ Finally, **if you don't need to do a pre-release anymore, be sure to run the `modern pre exit` command** to exit the pre-release state and to release the official version when you run the `modern bump` command again.
113
+
114
+
115
+ Translated with www.DeepL.com/Translator (free version)
@@ -0,0 +1,158 @@
1
+ # Testing Projects
2
+
3
+ This chapter will describe how to test modules.
4
+
5
+ ## Prerequisites and conventions
6
+
7
+ To use the testing functionality of the project, you need to make sure that the project contains the following dependencies:
8
+
9
+ * `"@modern-js/plugin-testing"`
10
+
11
+ In the module engineering scheme, the following conventions are in place for test cases, or files for writing tests:
12
+
13
+ * The `tests` directory in the project directory is the directory for test cases and test files, **no support for changing the directory for running test cases**.
14
+ * Files with the suffix `.test.[tj]sx?` are automatically recognized as test files by default.
15
+ * Other `. [tj]sx?` suffixes are recognized as normal files that can be used as test `utils` files or for other purposes.
16
+
17
+
18
+ ## Run the tests
19
+
20
+ Once the dependencies are prepared and we know where to write the test cases, we can execute the tests with the following command:
21
+
22
+ ``` bash
23
+ modern test
24
+
25
+ // Update snapshot
26
+ modern test --updateSnapshot
27
+ ```
28
+
29
+ After execution, you will see the results of the test:
30
+
31
+ ![test-result](/test-result.png)
32
+
33
+ ## Usage Configuration
34
+
35
+ The Module Engineering Program provides the following configurations for testing.
36
+
37
+ * [`testing`](/zh/api/config-test)
38
+
39
+ You can add it in `modern.config.(j|t)s`.
40
+
41
+ ## Test example
42
+
43
+ ### Common modules
44
+
45
+ For common modules, we can use the test function as follows:
46
+
47
+ <CH.Spotlight>
48
+
49
+ ``` typescript ./src/index.ts
50
+ export default function () {
51
+ return 'hello world';
52
+ }
53
+ ```
54
+
55
+ ---
56
+
57
+ First is the code of the module.
58
+
59
+ ``` typescript ./src/index.ts
60
+ export default function () {
61
+ return 'hello world';
62
+ }
63
+ ```
64
+
65
+ ---
66
+
67
+ Then in the test file, we can do this.
68
+
69
+ Where `@` points to the source directory, defined in `tests/tsconfig.json` in the initialization project.
70
+
71
+ ``` typescript ./tests/index.test.ts
72
+ import main from '@/index';
73
+
74
+ describe('default cases', () => {
75
+ test('Have returns', () => {
76
+ const drink = jest.fn(main);
77
+ drink();
78
+ expect(drink).toHaveReturned();
79
+ });
80
+ });
81
+ ```
82
+
83
+ ---
84
+
85
+ Finally we can execute `modern test`.
86
+
87
+ ``` bash
88
+ pnpm test
89
+ ## or
90
+ yarn test
91
+ ## or
92
+ npm run test
93
+ ```
94
+
95
+ </CH.Spotlight>
96
+
97
+ ### Components
98
+
99
+ For components, Modern.js's [Runtime API](xxx) provides functionality for testing UI components, which is provided by `@modern-js/runtime/testing`.
100
+
101
+ :::tip
102
+ If you need to use the Runtime API, then you can turn it on via [microgenerator](/zh/guide/command-preview).
103
+ :::
104
+
105
+ <CH.Spotlight>
106
+
107
+ ``` tsx ./src/index.tsx
108
+ export const default () {
109
+ return (
110
+ <div>This is a UI Component</div>
111
+ );
112
+ }
113
+ ```
114
+
115
+ ---
116
+
117
+ First is the code of the component.
118
+
119
+ ``` tsx ./src/index.tsx
120
+ export const default () {
121
+ return (
122
+ <div>This is a UI Component</div>
123
+ );
124
+ }
125
+ ```
126
+
127
+ ---
128
+
129
+ Then in the test file, we can do this.
130
+
131
+ Where `@` points to the source directory, defined in `tests/tsconfig.json` in the initialization project.
132
+
133
+ ``` tsx ./tests/index.test.tsx
134
+ import { render, screen } from '@modern-js/runtime/testing';
135
+
136
+ import Component from '@/index';
137
+
138
+ describe('default cases', () => {
139
+ test('Rendered', () => {
140
+ render(<Component />);
141
+ expect(screen.getByText('This is a UI Component')).toBeInTheDocument();
142
+ });
143
+ });
144
+ ```
145
+
146
+ ---
147
+
148
+ Finally we can execute `modern test`.
149
+
150
+ ``` bash
151
+ pnpm test
152
+ ## or
153
+ yarn test
154
+ ## or
155
+ npm run test
156
+ ```
157
+
158
+ </CH.Spotlight>
@@ -0,0 +1,35 @@
1
+ # Using the Microgenerator
2
+
3
+ The Module Engineering solution provides the Microgenerator tool, which allows for the current project to.
4
+
5
+ * add new directories and files
6
+ * Modify the contents of the `package.json` file
7
+ * Execute commands
8
+
9
+ Thus with these capabilities, **Microgenerator can enable additional feature functionality for the project**.
10
+
11
+ The microgenerator can be started via [`modern new`](/zh/guide/command-preview). The current Microgenerator features supported by the Module Engineering program are:
12
+
13
+ ## Storybook
14
+
15
+ The **Storybook feature** can be enabled when we want to debug a component or a common module. When this feature is enabled, **the `stories` directory and related files are created in the project directory, and a new `"@modern-js/plugin-storybook"` dependency is added to package.json**.
16
+
17
+ For more information on how to start Storybook and how to use it, check out the following link.
18
+
19
+ * [`modern dev`](/en/guide/command-preview#modern-dev)
20
+ * [using Storybook](xxx)
21
+
22
+ ## Tailwind CSS support
23
+
24
+ This can be enabled when we want to add [Tailwind CSS](https://v2.tailwindcss.com/) support to our project. Tailwind CSS is a CSS library that provides out-of-the-box styling.
25
+
26
+ For more information on how to use Tailwind CSS in your module projects, check out.
27
+
28
+ * [Using Tailwind CSS](xxx)
29
+
30
+
31
+ ## Modern.js Runtime API
32
+
33
+ **Modern.js provides [Runtime API](xxx) capabilities that can only be used in the Modern.js application project environment**. If you need to develop a component for use in a Modern.js application environment, then you can turn on this feature and the microgenerator will add the `"@modern-js/runtime"` dependency.
34
+
35
+ Also, the Storybook debugging tool will determine if the project needs to use the Runtime API by checking the project's dependencies and providing the same Runtime API runtime environment as the Modern.js application project.