@modern-js/module-tools-docs 2.2.0-beta.0 → 2.2.1-beta.1

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 (212) hide show
  1. package/doc_build/static/css/main.css +3 -3
  2. package/doc_build/static/css/main.css.map +1 -1
  3. package/doc_build/static/js/async/en_api_config_build-config.js +2 -2
  4. package/doc_build/static/js/async/en_api_config_build-preset.js +2 -2
  5. package/doc_build/static/js/async/en_api_config_design-system.js +2 -2
  6. package/doc_build/static/js/async/en_api_config_plugins.js +2 -2
  7. package/doc_build/static/js/async/en_api_config_testing.js +2 -2
  8. package/doc_build/static/js/async/en_api_plugin-api_plugin-hooks.js +2 -2
  9. package/doc_build/static/js/async/en_guide_advance_asset.js +2 -2
  10. package/doc_build/static/js/async/en_guide_advance_build-umd.js +4 -4
  11. package/doc_build/static/js/async/en_guide_advance_copy.js +3 -3
  12. package/doc_build/static/js/async/en_guide_advance_external-dependency.js +4 -4
  13. package/doc_build/static/js/async/en_guide_advance_in-depth-about-build.js +5 -5
  14. package/doc_build/static/js/async/en_guide_advance_in-depth-about-dev-command.js +2455 -75
  15. package/doc_build/static/js/async/en_guide_advance_in-depth-about-dev-command.js.map +1 -1
  16. package/doc_build/static/js/async/en_guide_advance_theme-config.js +3 -3
  17. package/doc_build/static/js/async/en_guide_basic_before-getting-started.js +14 -152
  18. package/doc_build/static/js/async/en_guide_basic_before-getting-started.js.map +1 -1
  19. package/doc_build/static/js/async/en_guide_basic_command-preview.js +8 -8
  20. package/doc_build/static/js/async/en_guide_basic_modify-output-product.js +126 -37
  21. package/doc_build/static/js/async/en_guide_basic_modify-output-product.js.map +1 -1
  22. package/doc_build/static/js/async/en_guide_basic_publish-your-project.js +2 -2
  23. package/doc_build/static/js/async/en_guide_basic_test-your-project.js +2 -2
  24. package/doc_build/static/js/async/en_guide_basic_use-micro-generator.js +2791 -4
  25. package/doc_build/static/js/async/en_guide_basic_use-micro-generator.js.map +1 -1
  26. package/doc_build/static/js/async/en_guide_basic_using-storybook.js +10 -10
  27. package/doc_build/static/js/async/en_guide_best-practices_components.js +3 -3
  28. package/doc_build/static/js/async/en_guide_intro_getting-started.js +2 -2
  29. package/doc_build/static/js/async/en_plugins_guide_getting-started.js +2 -2
  30. package/doc_build/static/js/async/en_plugins_guide_plugin-object.js +2 -2
  31. package/doc_build/static/js/async/en_plugins_guide_setup-function.js +2 -2
  32. package/doc_build/static/js/async/zh_api_config_build-config.js +2 -2
  33. package/doc_build/static/js/async/zh_api_config_build-preset.js +2 -2
  34. package/doc_build/static/js/async/zh_api_config_design-system.js +2 -2
  35. package/doc_build/static/js/async/zh_api_config_plugins.js +2 -2
  36. package/doc_build/static/js/async/zh_api_config_testing.js +2 -2
  37. package/doc_build/static/js/async/zh_api_plugin-api_plugin-hooks.js +2 -2
  38. package/doc_build/static/js/async/zh_guide_advance_asset.js +2 -2
  39. package/doc_build/static/js/async/zh_guide_advance_build-umd.js +2 -2
  40. package/doc_build/static/js/async/zh_guide_advance_copy.js +3 -3
  41. package/doc_build/static/js/async/zh_guide_advance_external-dependency.js +3 -3
  42. package/doc_build/static/js/async/zh_guide_advance_in-depth-about-build.js +5 -5
  43. package/doc_build/static/js/async/zh_guide_advance_in-depth-about-dev-command.js +2450 -74
  44. package/doc_build/static/js/async/zh_guide_advance_in-depth-about-dev-command.js.map +1 -1
  45. package/doc_build/static/js/async/zh_guide_advance_theme-config.js +3 -3
  46. package/doc_build/static/js/async/zh_guide_basic_before-getting-started.js +14 -152
  47. package/doc_build/static/js/async/zh_guide_basic_before-getting-started.js.map +1 -1
  48. package/doc_build/static/js/async/zh_guide_basic_command-preview.js +8 -8
  49. package/doc_build/static/js/async/zh_guide_basic_modify-output-product.js +87 -9
  50. package/doc_build/static/js/async/zh_guide_basic_modify-output-product.js.map +1 -1
  51. package/doc_build/static/js/async/zh_guide_basic_publish-your-project.js +7 -7
  52. package/doc_build/static/js/async/zh_guide_basic_test-your-project.js +410 -11
  53. package/doc_build/static/js/async/zh_guide_basic_test-your-project.js.map +1 -1
  54. package/doc_build/static/js/async/zh_guide_basic_use-micro-generator.js +2790 -3
  55. package/doc_build/static/js/async/zh_guide_basic_use-micro-generator.js.map +1 -1
  56. package/doc_build/static/js/async/zh_guide_basic_using-storybook.js +496 -405
  57. package/doc_build/static/js/async/zh_guide_basic_using-storybook.js.map +1 -1
  58. package/doc_build/static/js/async/zh_guide_best-practices_components.js +4 -4
  59. package/doc_build/static/js/async/zh_guide_intro_getting-started.js +2 -2
  60. package/doc_build/static/js/async/zh_plugins_guide_getting-started.js +2 -2
  61. package/doc_build/static/js/async/zh_plugins_guide_plugin-object.js +2 -2
  62. package/doc_build/static/js/async/zh_plugins_guide_setup-function.js +2 -2
  63. package/doc_build/static/js/builder-runtime.js +1 -1
  64. package/doc_build/static/js/builder-runtime.js.map +1 -1
  65. package/doc_build/static/js/main.js +211 -211
  66. package/doc_build/static/js/main.js.map +1 -1
  67. package/doc_build/static/js/vendors-node_modules_pnpm_remix-run_router_1_2_0_node_modules_remix-run_router_dist_router_js-9d5e9c.js +70 -70
  68. package/doc_build/static/js/vendors-node_modules_pnpm_remix-run_router_1_2_0_node_modules_remix-run_router_dist_router_js-9d5e9c.js.map +1 -1
  69. package/doc_build/static/search_index.json +1 -1
  70. package/docs/en/guide/advance/in-depth-about-dev-command.md +65 -12
  71. package/docs/en/guide/basic/before-getting-started.md +4 -14
  72. package/docs/en/guide/basic/command-preview.md +1 -1
  73. package/docs/en/guide/basic/modify-output-product.md +6 -2
  74. package/docs/en/guide/basic/use-micro-generator.md +62 -1
  75. package/docs/en/guide/basic/using-storybook.mdx +4 -4
  76. package/docs/zh/guide/advance/in-depth-about-dev-command.md +60 -13
  77. package/docs/zh/guide/basic/before-getting-started.md +4 -14
  78. package/docs/zh/guide/basic/command-preview.md +2 -2
  79. package/docs/zh/guide/basic/modify-output-product.md +5 -3
  80. package/docs/zh/guide/basic/publish-your-project.md +4 -4
  81. package/docs/zh/guide/basic/test-your-project.mdx +18 -5
  82. package/docs/zh/guide/basic/use-micro-generator.md +61 -1
  83. package/docs/zh/guide/basic/using-storybook.mdx +13 -10
  84. package/package.json +4 -4
  85. package/docs/.island/dist/404.html +0 -41
  86. package/docs/.island/dist/assets/asset.26aea654.js +0 -160
  87. package/docs/.island/dist/assets/asset.36e3d3c9.js +0 -160
  88. package/docs/.island/dist/assets/before-getting-started.0e863740.js +0 -87
  89. package/docs/.island/dist/assets/before-getting-started.2c6e6b8a.js +0 -87
  90. package/docs/.island/dist/assets/build-config.460d11d9.js +0 -804
  91. package/docs/.island/dist/assets/build-config.e155e534.js +0 -854
  92. package/docs/.island/dist/assets/build-preset.6c2c6c62.js +0 -256
  93. package/docs/.island/dist/assets/build-preset.d3da921d.js +0 -256
  94. package/docs/.island/dist/assets/build-umd.ba00f028.js +0 -264
  95. package/docs/.island/dist/assets/build-umd.edb9d163.js +0 -273
  96. package/docs/.island/dist/assets/command-preview.1dc93921.js +0 -264
  97. package/docs/.island/dist/assets/command-preview.ef7a9d01.js +0 -264
  98. package/docs/.island/dist/assets/components.esm.03560353.js +0 -9
  99. package/docs/.island/dist/assets/copy.28dc4d5f.js +0 -277
  100. package/docs/.island/dist/assets/copy.f4625565.js +0 -277
  101. package/docs/.island/dist/assets/design-system.8993234c.js +0 -1254
  102. package/docs/.island/dist/assets/design-system.b0ba163f.js +0 -639
  103. package/docs/.island/dist/assets/dev.b373b152.js +0 -37
  104. package/docs/.island/dist/assets/dev.b39fd42a.js +0 -37
  105. package/docs/.island/dist/assets/down.f35427d3.svg +0 -1
  106. package/docs/.island/dist/assets/extension.4bf3526b.js +0 -1
  107. package/docs/.island/dist/assets/extension.d64ed0b8.js +0 -469
  108. package/docs/.island/dist/assets/external-dependency.2ede7532.js +0 -156
  109. package/docs/.island/dist/assets/external-dependency.92ca89e0.js +0 -156
  110. package/docs/.island/dist/assets/getting-started.822cf0b2.js +0 -117
  111. package/docs/.island/dist/assets/getting-started.e2764829.js +0 -114
  112. package/docs/.island/dist/assets/github.3bf8ccee.svg +0 -1
  113. package/docs/.island/dist/assets/in-depth-about-build.94cc902d.js +0 -375
  114. package/docs/.island/dist/assets/in-depth-about-build.aa74de10.js +0 -374
  115. package/docs/.island/dist/assets/in-depth-about-dev-command.877bdb83.js +0 -33
  116. package/docs/.island/dist/assets/in-depth-about-dev-command.9736befd.js +0 -39
  117. package/docs/.island/dist/assets/index.01786ba7.js +0 -30
  118. package/docs/.island/dist/assets/index.6cef6f5f.js +0 -4
  119. package/docs/.island/dist/assets/index.cb118238.js +0 -36
  120. package/docs/.island/dist/assets/index.ccb6ce27.js +0 -4
  121. package/docs/.island/dist/assets/island_inject.69495876.js +0 -1
  122. package/docs/.island/dist/assets/island_inject.cdfb22d9.js +0 -1
  123. package/docs/.island/dist/assets/loading.8c9bb911.svg +0 -1
  124. package/docs/.island/dist/assets/modify-output-product.9e2394d7.js +0 -100
  125. package/docs/.island/dist/assets/modify-output-product.f363845a.js +0 -100
  126. package/docs/.island/dist/assets/moon.6b705924.svg +0 -3
  127. package/docs/.island/dist/assets/plugin.70a61997.js +0 -42
  128. package/docs/.island/dist/assets/plugin.80b12ee2.js +0 -42
  129. package/docs/.island/dist/assets/publish-your-project.7321c10e.js +0 -164
  130. package/docs/.island/dist/assets/publish-your-project.7326359f.js +0 -166
  131. package/docs/.island/dist/assets/right.89674cd7.svg +0 -1
  132. package/docs/.island/dist/assets/search.0aea6901.svg +0 -1
  133. package/docs/.island/dist/assets/search.11353245.js +0 -222
  134. package/docs/.island/dist/assets/search.a1b1cff3.js +0 -3
  135. package/docs/.island/dist/assets/search.f9025ced.js +0 -3
  136. package/docs/.island/dist/assets/style.09015a4b.css +0 -1
  137. package/docs/.island/dist/assets/style.2e5f7bc2.css +0 -1970
  138. package/docs/.island/dist/assets/sun.841dac10.svg +0 -11
  139. package/docs/.island/dist/assets/test-your-project.8ab2809e.js +0 -190
  140. package/docs/.island/dist/assets/test-your-project.9ae2a49e.js +0 -190
  141. package/docs/.island/dist/assets/test.2bfe276b.js +0 -66
  142. package/docs/.island/dist/assets/test.a2c00a3f.js +0 -67
  143. package/docs/.island/dist/assets/translator.b1077c44.svg +0 -1
  144. package/docs/.island/dist/assets/use-micro-generator.13c1a09f.js +0 -60
  145. package/docs/.island/dist/assets/use-micro-generator.dfe877f6.js +0 -60
  146. package/docs/.island/dist/assets/using-storybook.adb88cb8.js +0 -260
  147. package/docs/.island/dist/assets/using-storybook.b8e7dd04.js +0 -260
  148. package/docs/.island/dist/assets/welcome.94880043.js +0 -13
  149. package/docs/.island/dist/assets/welcome.b2140e7e.js +0 -13
  150. package/docs/.island/dist/assets/why-module-engineering-solution.bfe7981a.js +0 -26
  151. package/docs/.island/dist/assets/why-module-engineering-solution.e31cd19f.js +0 -26
  152. package/docs/.island/dist/chunk-COLCRJ2V.js +0 -1
  153. package/docs/.island/dist/chunk-K5FMOYDC.js +0 -10
  154. package/docs/.island/dist/chunk-WE42KMYS.js +0 -26
  155. package/docs/.island/dist/client-entry.js +0 -3
  156. package/docs/.island/dist/en/api/build-config.html +0 -344
  157. package/docs/.island/dist/en/api/build-preset.html +0 -82
  158. package/docs/.island/dist/en/api/design-system.html +0 -155
  159. package/docs/.island/dist/en/api/dev.html +0 -45
  160. package/docs/.island/dist/en/api/index.html +0 -41
  161. package/docs/.island/dist/en/api/plugin.html +0 -48
  162. package/docs/.island/dist/en/api/test.html +0 -58
  163. package/docs/.island/dist/en/guide/advance/asset.html +0 -68
  164. package/docs/.island/dist/en/guide/advance/build-umd.html +0 -72
  165. package/docs/.island/dist/en/guide/advance/copy.html +0 -82
  166. package/docs/.island/dist/en/guide/advance/extension.html +0 -41
  167. package/docs/.island/dist/en/guide/advance/external-dependency.html +0 -71
  168. package/docs/.island/dist/en/guide/advance/in-depth-about-build.html +0 -148
  169. package/docs/.island/dist/en/guide/advance/in-depth-about-dev-command.html +0 -51
  170. package/docs/.island/dist/en/guide/basic/before-getting-started.html +0 -127
  171. package/docs/.island/dist/en/guide/basic/command-preview.html +0 -100
  172. package/docs/.island/dist/en/guide/basic/modify-output-product.html +0 -140
  173. package/docs/.island/dist/en/guide/basic/publish-your-project.html +0 -91
  174. package/docs/.island/dist/en/guide/basic/test-your-project.html +0 -72
  175. package/docs/.island/dist/en/guide/basic/use-micro-generator.html +0 -65
  176. package/docs/.island/dist/en/guide/basic/using-storybook.html +0 -113
  177. package/docs/.island/dist/en/guide/intro/getting-started.html +0 -76
  178. package/docs/.island/dist/en/guide/intro/welcome.html +0 -53
  179. package/docs/.island/dist/en/guide/intro/why-module-engineering-solution.html +0 -49
  180. package/docs/.island/dist/en/index.html +0 -42
  181. package/docs/.island/dist/react-dom.js +0 -1
  182. package/docs/.island/dist/react-dom_client.js +0 -1
  183. package/docs/.island/dist/react.js +0 -1
  184. package/docs/.island/dist/react_jsx-runtime.js +0 -10
  185. package/docs/.island/dist/ssr-manifest.json +0 -57
  186. package/docs/.island/dist/test-result.png +0 -0
  187. package/docs/.island/dist/why-module-solution.png +0 -0
  188. package/docs/.island/dist/zh/api/build-config.html +0 -361
  189. package/docs/.island/dist/zh/api/build-preset.html +0 -82
  190. package/docs/.island/dist/zh/api/design-system.html +0 -149
  191. package/docs/.island/dist/zh/api/dev.html +0 -46
  192. package/docs/.island/dist/zh/api/index.html +0 -41
  193. package/docs/.island/dist/zh/api/plugin.html +0 -48
  194. package/docs/.island/dist/zh/api/test.html +0 -59
  195. package/docs/.island/dist/zh/guide/advance/asset.html +0 -68
  196. package/docs/.island/dist/zh/guide/advance/build-umd.html +0 -72
  197. package/docs/.island/dist/zh/guide/advance/copy.html +0 -82
  198. package/docs/.island/dist/zh/guide/advance/extension.html +0 -127
  199. package/docs/.island/dist/zh/guide/advance/external-dependency.html +0 -71
  200. package/docs/.island/dist/zh/guide/advance/in-depth-about-build.html +0 -148
  201. package/docs/.island/dist/zh/guide/advance/in-depth-about-dev-command.html +0 -53
  202. package/docs/.island/dist/zh/guide/basic/before-getting-started.html +0 -127
  203. package/docs/.island/dist/zh/guide/basic/command-preview.html +0 -100
  204. package/docs/.island/dist/zh/guide/basic/modify-output-product.html +0 -140
  205. package/docs/.island/dist/zh/guide/basic/publish-your-project.html +0 -92
  206. package/docs/.island/dist/zh/guide/basic/test-your-project.html +0 -72
  207. package/docs/.island/dist/zh/guide/basic/use-micro-generator.html +0 -65
  208. package/docs/.island/dist/zh/guide/basic/using-storybook.html +0 -114
  209. package/docs/.island/dist/zh/guide/intro/getting-started.html +0 -79
  210. package/docs/.island/dist/zh/guide/intro/welcome.html +0 -53
  211. package/docs/.island/dist/zh/guide/intro/why-module-engineering-solution.html +0 -49
  212. package/docs/.island/dist/zh/index.html +0 -42
@@ -2,25 +2,78 @@
2
2
  sidebar_position: 2
3
3
  ---
4
4
 
5
- # 深入理解 dev 命令
5
+ # In-depth understanding of the dev command
6
6
 
7
- 在【基础使用】的部分,我们已经知道可以通过 `buildConfig` 配置对项目的输出产物进行修改。`buildConfig` 不仅描述了产物的一些特性,同时还为构建产物提供了一些功能。
7
+ The `dev` command provided by the module project is mainly used for debugging the code.
8
8
 
9
- :::tip{title=注意}
10
- 如果你还不清楚 `buildConfig` 是什么,建议花一些时间通过下面的链接了解一下:
9
+ ## The overall flow of the command run
11
10
 
12
- - 【[修改输出产物](/guide/basic/modify-output-product)】
11
+ 1. When the `dev` command is executed, Module Tools starts looking for debugging tools or tasks that can be executed. A debugging tool or task is a Module Tools debugging tool plugin like Storybook.
12
+ 2. When a debugging tool is found, it is executed immediately.
13
+ 3. When multiple debugging tools are found, the debugging tools list menu is displayed. A debug tool can be started by selecting the name option corresponding to it.
14
+ 4. When no debug tool is found, the user is informed that no debug tool is available.
13
15
 
14
- :::
16
+ In addition to the `dev` command, you can also start a debugging tool or task directly by using the `dev [debug tool name]` option.
15
17
 
16
- 而在本章里我们将要深入理解某些构建配置的使用以及了解执行 `modern build` 命令的时候发生了什么。
18
+ When executing the `dev` command, the debugging tool can choose whether or not to perform a listening mode for code builds before starting, for example the Storybook debugging tool has this feature enabled.
17
19
 
18
- ## 深入理解 `buildConfig`
19
20
 
20
- 那么首先我们来理解 **bundle** 和 **bundleless** 的构建模式。
21
+ ## Storybook
21
22
 
22
- ### bundle 和 bundleless
23
23
 
24
- ### input sourceDir 的关系
24
+ Storybook is currently the official Module Tools debugging tool plugin provided by Module Works.
25
25
 
26
- ## 构建过程
26
+ As we mentioned above, Storybook performs the source build task in listening mode before it is started, so you will see log messages for both Storybook and the source build in the terminal. Changes to the build product are also triggered when the source code is updated, and Storybook hot updates are triggered when the build product changes.
27
+
28
+ ## Extending the dev command
29
+
30
+ If you need to extend the dev command, or rather provide your own Module Tools debugging tool plug-in, then you will need to know the following first.
31
+
32
+ * [Development of plugins](plugins/guide/getting-started)
33
+ * [Debugging Tools Plugin API](/api/plugin-api/plugin-hooks#调试钩子)
34
+
35
+ In general, the code to implement a debugging tool that does nothing and the associated configuration is as follows.
36
+
37
+ ``` ts do-nothing.ts
38
+ export default (): CliPlugin<ModuleTools> => ({
39
+ name: 'do-nothing',
40
+ setup() {
41
+ return {
42
+ registerDev() {
43
+ return {
44
+ // Debugging tool name
45
+ name: 'do-nothing',
46
+ // Menu display content
47
+ menuItem: {
48
+ name: 'DoNothing',
49
+ value: 'do-nothing',
50
+ },
51
+ // The defined dev subcommand
52
+ subCommands: ['donothing', 'dn'],
53
+ async action() {
54
+ // dev logic
55
+ console.info('Run build --watch, and do nothing.');
56
+ },
57
+ };
58
+ },
59
+ };
60
+ },
61
+ });
62
+ ```
63
+
64
+ If this debugging tool plugin is required, it needs to be added to the configuration file.
65
+
66
+ ``` ts
67
+ import doNothingPlugin from './plugins/do-nothing';
68
+
69
+ export default defineConfig({
70
+ plugins: [
71
+ //..
72
+ doNothingPlugin()
73
+ ],
74
+ });
75
+ ```
76
+
77
+ At this point we can execute it when we execute the `dev` or `dev do-nothing` command. After execution, it will first execute the source build task in listening mode and print the log messages immediately afterwards.
78
+
79
+ For currently officially supported debugging tools and third-party supported debugging tools, you can view them in [plugins list](plugins/official-list/overview).
@@ -176,8 +176,10 @@ export default defineConfig({
176
176
  });
177
177
  ```
178
178
 
179
- ```js
180
- // modern.config.js
179
+ **We recommend using the `defineConfig` function**, but it is not mandatory to use it. So you can also return an object directly in the config file: the
180
+
181
+ ``` ts
182
+ // modern.config.ts
181
183
  import moduleTools from '@modern-js/module-tools';
182
184
 
183
185
  export default {
@@ -185,15 +187,3 @@ export default {
185
187
  buildPreset: 'npm-library',
186
188
  };
187
189
  ```
188
-
189
- **We recommend using the `defineConfig` function**, but it is not mandatory to use it. So you can also return an object directly in the config file: the
190
-
191
- ```typescript
192
- // modern.config.ts
193
- export default {};
194
- ```
195
-
196
- ```js
197
- // modern.config.js
198
- export default {};
199
- ```
@@ -33,7 +33,7 @@ When you want to start a project build, you can execute the `modern build` comma
33
33
  In addition to the above, module projects also support `platform` build mode, which can be used to perform build tasks for other tools. For example, it is currently officially supported to start a Storybook build task to generate Storybook products by executing the `modern build --platform` or `modern build --platform storybook` commands after installing the `@modern-js/plugin-storybook` plugin.
34
34
 
35
35
  :::tip{title=Note}
36
- 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**.
36
+ When executing a Storybook build, it may need to read the project's build product. So **when the `modern build --platform` command is executed to start a Storybook build, the `modern build --watch` program is automatically executed first to ensure the existence of the source build product**.
37
37
  :::
38
38
 
39
39
  ## `modern new`
@@ -1,6 +1,7 @@
1
1
  ---
2
2
  sidebar_position: 3
3
3
  ---
4
+ # modify-output-product
4
5
 
5
6
  ## Modify the output product
6
7
 
@@ -58,9 +59,10 @@ For example, if the output product is based on the preset string `"npm-library"`
58
59
  For example, to achieve the same effect as the preset string ``npm-library-es5"` using the form of a preset function, you can do the following.
59
60
 
60
61
  ```typescript
61
- import { defineConfig } from '@modern-js/module-tools';
62
+ import moduleTools, { defineConfig } from '@modern-js/module-tools';
62
63
 
63
64
  export default defineConfig({
65
+ plugins: [moduleTools()],
64
66
  buildPreset({ preset }) {
65
67
  return preset.NPM_LIBRARY.map(config => {
66
68
  return { ... .config, target: 'es5' }
@@ -69,9 +71,11 @@ export default defineConfig({
69
71
  });
70
72
  ```
71
73
 
72
- 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 `es5`.
74
+ In the above code implementation, `preset.NPM_LIBRARY` corresponds to the preset string `"npm-library"`, which represents the equivalent of `"npm-library"` for multiple sets of build-related configurations. We traverse the `NPM_LIBRARY` array, which contains multiple `buildConfig` objects, using the `map` method. We made a shallow copy of the original `buildConfig` object and modified the value of the `target` after the shallow copy, specifying it as `es5`.
75
+
73
76
 
74
77
  > NPM_LIBRARY`, you can check it with [BuildPreset API](/api/config/build-preset). The`preset`object contains not only`NPM_LIBRARY`, but also other similar constants.
78
+ > We can not only use `preset.NPM_LIBRARY` to get the build configuration corresponding to `"npm-library"`, but also `preset['npm-library']` in this way.
75
79
 
76
80
  So what is the `buildConfig` object here? What is the basis for the build product feature mentioned before?
77
81
 
@@ -16,12 +16,43 @@ The microgenerator can be started via [`modern new`](/guide/basic/command-previe
16
16
 
17
17
  ## Test
18
18
 
19
- When we want to test some modules, we can enable the test test feature. When this feature is enabled, **a `tests` directory and related files will be created in the project directory, and a new `"@modern-js/plugin-testing"` dependency will be added to package.json**.
19
+ When we want to test some modules, we can enable the test feature. When this feature is enabled, **a `tests` directory and related files will be created in the project directory, and a new `"@modern-js/plugin-testing"` dependency will be added to package.json**.
20
+
21
+
22
+ :::tip
23
+ After successfully enabling it, you will be prompted to manually add a code similar to the one below to the configuration.
24
+ ``` ts
25
+ import moduleTools, { defineConfig } from '@modern-js/module-tools';
26
+ import testPlugin from '@modern-js/plugin-testing';
27
+
28
+ export default defineConfig({
29
+ plugins: [
30
+ moduleTools(),
31
+ testPlugin(),
32
+ ],
33
+ });
34
+ ```
35
+ :::
20
36
 
21
37
  ## Storybook
22
38
 
23
39
  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**.
24
40
 
41
+ :::tip
42
+ After successfully enabling it, you will be prompted to manually add a code similar to the one below to the configuration.
43
+ ``` ts
44
+ import moduleTools, { defineConfig } from '@modern-js/module-tools';
45
+ import storybookPlugin from '@modern-js/plugin-storybook';
46
+
47
+ export default defineConfig({
48
+ plugins: [
49
+ moduleTools(),
50
+ storybookPlugin(),
51
+ ],
52
+ });
53
+ ```
54
+ :::
55
+
25
56
  For more information on how to start Storybook and how to use it, check out the following link.
26
57
 
27
58
  - [`modern dev`](/en/guide/basic/command-preview#modern-dev)
@@ -37,6 +68,21 @@ For more information on how to use Tailwind CSS in your module projects, check o
37
68
 
38
69
  - Using Tailwind CSS
39
70
 
71
+ :::tip
72
+ After successfully enabling it, you will be prompted to manually add a code similar to the one below to the configuration.
73
+ ``` ts
74
+ import moduleTools, { defineConfig } from '@modern-js/module-tools';
75
+ import tailwindPlugin from '@modern-js/plugin-tailwindcss';
76
+
77
+ export default defineConfig({
78
+ plugins: [
79
+ moduleTools(),
80
+ tailwindPlugin(),
81
+ ],
82
+ });
83
+ ```
84
+ :::
85
+
40
86
  ## Modern.js Runtime API
41
87
 
42
88
  <!-- 链接待补充 -->
@@ -44,3 +90,18 @@ For more information on how to use Tailwind CSS in your module projects, check o
44
90
  **Modern.js provides Runtime API 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.
45
91
 
46
92
  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.
93
+
94
+ :::tip
95
+ After successfully enabling it, you will be prompted to manually add a code similar to the one below to the configuration.
96
+ ``` ts
97
+ import moduleTools, { defineConfig } from '@modern-js/module-tools';
98
+ import runtime from '@modern-js/runtime/cli';
99
+
100
+ export default defineConfig({
101
+ plugins: [
102
+ moduleTools(),
103
+ runtime(),
104
+ ],
105
+ });
106
+ ```
107
+ :::
@@ -23,12 +23,12 @@ The modular engineering solution is integrated with Storybook, so you can pretty
23
23
 
24
24
  ## Debugging code
25
25
 
26
- Component code needs to be introduced during debugging code, and currently component code can be introduced in two ways:
26
+ The project code needs to be introduced during the debugging process and can currently be introduced in two ways:
27
27
 
28
- - Referencing the component product
29
- - Referencing component source code
28
+ - Use of project products
29
+ - Using the project source code
30
30
 
31
- We recommend the first way of "**referencing component product**". Because it is almost close to the real usage scenario, not only can we debug the component functionality, but also verify the correctness of the build product.
31
+ We prefer to use the first "**use project product**" approach. This is because it is closer to a real-life usage scenario and not only allows you to debug the functionality of the component, but also to verify the correctness of the build product.
32
32
 
33
33
  Next, we will talk about how to use each of these two methods.
34
34
 
@@ -4,27 +4,74 @@ sidebar_position: 2
4
4
 
5
5
  # 深入理解 dev 命令
6
6
 
7
- 在【基础使用】的部分,我们已经知道可以通过 `buildConfig` 配置对项目的输出产物进行修改。`buildConfig` 不仅描述了产物的一些特性,同时还为构建产物提供了一些功能。
7
+ 模块工程提供的 `dev` 命令主要用于代码的调试。
8
8
 
9
- :::tip{title=注意}
10
- 如果你还不清楚 `buildConfig` 是什么,建议花一些时间通过下面的链接了解一下:
9
+ ## 命令运行的整体流程
11
10
 
12
- - 【[修改输出产物](/guide/basic/modify-output-product)】
11
+ 1. 当执行 `dev` 命令的时候,Module Tools 开始寻找是否存在可以执行的调试工具或者任务。调试工具或者任务就是类似 Storybook 这样的 Module Tools 调试工具插件。
12
+ 2. 当发现存在一个调试工具的时候,则会立即执行它。
13
+ 3. 当发现多个调试工具的时候,则显示调试工具列表菜单。可以通过选择某个调试工具对应的名称选项启动它。
14
+ 4. 当没有发现调试工具的时候,则告诉用户没有可用的调试工具。
13
15
 
14
- :::
16
+ 我们除了可以执行 `dev` 命令以外,也可以通过 `dev [调试工具名称]` 的方式来直接启动调试工具或者任务。
15
17
 
16
- 而在本章里我们将要深入理解某些构建配置的使用以及了解执行 `modern build` 命令的时候发生了什么。
18
+ 在执行 `dev` 命令的时候,调试工具可以选择是否在启动之前执行代码构建的监听模式,例如 Storybook 调试工具就开启了该功能。
17
19
 
18
- ## 深入理解 `buildConfig`
20
+ ## Storybook
19
21
 
20
- ### Bundle Bundleless
22
+ Storybook 是目前模块工程官方提供的 Module Tools 调试工具插件。
21
23
 
22
- 那么首先我们来理解一下 Bundle Bundleless。
24
+ 上面我们说到 Storybook 在启动之前会执行监听模式的源码构建任务,因此在终端里你会看到 Storybook 和源码构建的日志信息同时出现。并且在更新源码后会触发构建产物的变化,当构建产物变化的时候也会触发 Storybook 热更新。
23
25
 
24
- 所谓 Bundle 是指对构建产物进行打包,构建产物可能是一个文件,也有可能是基于一定的[代码拆分策略](https://esbuild.github.io/api/#splitting)得到的多个文件。
26
+ ## 扩展 dev 命令
25
27
 
26
- Bundleless 则是指对每个源文件进行编译构建,但是并不将它们打包在一起。每一个产物文件都可以找到与之相对应的源码文件。
28
+ 如果需要扩展 dev 命令或者说提供自己的 Module Tools 调试工具插件,那么你需要先了解以下内容:
27
29
 
28
- ### input 与 sourceDir 的关系
30
+ * [开发插件](plugins/guide/getting-started)
31
+ * [调试工具插件 API](/api/plugin-api/plugin-hooks#调试钩子)
29
32
 
30
- ## 构建过程
33
+ 一般来说,实现一个什么都不做的调试工具,其实现代码以及相关配置如下:
34
+
35
+ ``` ts do-nothing.ts
36
+ export default (): CliPlugin<ModuleTools> => ({
37
+ name: 'do-nothing',
38
+ setup() {
39
+ return {
40
+ registerDev() {
41
+ return {
42
+ // 调试工具名称
43
+ name: 'do-nothing',
44
+ // 菜单显示内容
45
+ menuItem: {
46
+ name: 'DoNothing',
47
+ value: 'do-nothing',
48
+ },
49
+ // 定义的 dev 子命令
50
+ subCommands: ['donothing', 'dn'],
51
+ async action() {
52
+ // dev logic
53
+ console.info('Run build --watch, and do nothing.');
54
+ },
55
+ };
56
+ },
57
+ };
58
+ },
59
+ });
60
+ ```
61
+
62
+ 如果需要使用该调试工具插件,则需要在配置文件中增加它:
63
+
64
+ ``` ts
65
+ import doNothingPlugin from './plugins/do-nothing';
66
+
67
+ export default defineConfig({
68
+ plugins: [
69
+ //..
70
+ doNothingPlugin()
71
+ ],
72
+ });
73
+ ```
74
+
75
+ 此时我们执行 `dev` 或者 `dev do-nothing` 命令的时候,就可以执行它了。在执行后,它会先执行监听模式的源码构建任务,并紧接着打印日志信息。
76
+
77
+ 对于目前官方支持的调试工具和第三方支持的调试工具,可以在[插件列表](plugins/official-list/overview)中查看。
@@ -176,8 +176,10 @@ export default defineConfig({
176
176
  });
177
177
  ```
178
178
 
179
- ```js
180
- // modern.config.js
179
+ **我们推荐使用 `defineConfig` 函数**,不过并不强制使用它。因此你也可以在配置文件中直接返回一个对象:
180
+
181
+ ```ts
182
+ // modern.config.ts
181
183
  import moduleTools from '@modern-js/module-tools';
182
184
 
183
185
  export default {
@@ -185,15 +187,3 @@ export default {
185
187
  buildPreset: 'npm-library',
186
188
  };
187
189
  ```
188
-
189
- **我们推荐使用 `defineConfig` 函数**,不过并不强制使用它。因此你也可以在配置文件中直接返回一个对象:
190
-
191
- ```typescript
192
- // modern.config.ts
193
- export default {};
194
- ```
195
-
196
- ```js
197
- // modern.config.js
198
- export default {};
199
- ```
@@ -33,7 +33,7 @@ Options:
33
33
  除了以上,模块工程还支持 `platform` 构建模式,可以用于执行其他工具的构建任务。例如,目前官方支持在安装了 `@modern-js/plugin-storybook` 插件后,可以通过执行 `modern build --platform` 或者 `modern build --platform storybook` 命令启动 Storybook 构建任务生成 Storybook 产物。
34
34
 
35
35
  :::tip{title=注意}
36
- 在执行 Storybook 构建的时候,它需要读取项目的构建产物。因此**在执行 `modern build --platform` 命令启动 Storybook 构建的时候,要先执行一次 `modern build` 确保源码构建产物的存在**。
36
+ 在执行 Storybook 构建的时候,它可能需要读取项目的构建产物。因此**在执行 `modern build --platform` 命令启动 Storybook 构建的时候,会自动先执行 `modern build --watch` 程序确保源码构建产物的存在**。
37
37
  :::
38
38
 
39
39
  ## `modern new`
@@ -90,7 +90,7 @@ Options:
90
90
  ```
91
91
 
92
92
  需要先执行 `modern new` 开启测试功能,然后才可以执行 `modern test` 命令。
93
- `modern test` 命令会自动将 `src/tests/*.test.(js|ts|jsx|tsx)` 文件当做测试用例运行。
93
+ `modern test` 命令会自动将 `tests/*.test.(js|ts|jsx|tsx)` 文件当做测试用例运行。
94
94
 
95
95
  ## `modern lint`
96
96
 
@@ -58,9 +58,10 @@ export default defineConfig({
58
58
  例如,如果使用预设函数的形式达到预设字符串 `"npm-library-es5"` 同样的效果,可以按照如下的方式:
59
59
 
60
60
  ```typescript
61
- import { defineConfig } from '@modern-js/module-tools';
61
+ import moduleTools, { defineConfig } from '@modern-js/module-tools';
62
62
 
63
63
  export default defineConfig({
64
+ plugins: [moduleTools()],
64
65
  buildPreset({ preset }) {
65
66
  return preset.NPM_LIBRARY.map(config => {
66
67
  return { ...config, target: 'es5' };
@@ -69,9 +70,10 @@ export default defineConfig({
69
70
  });
70
71
  ```
71
72
 
72
- 在上面的代码实现中,`preset.NPM_LIBRARY` 与预设字符串 `"npm-library"` 是相对应的,它代表着 `"npm-library"` 等价的多组构建相关的配置。我们通过 `map` 方法遍历了 `NPM_LIBRARY` 这个数组,在这个数组中包含了多个 `buildConfig` 对象。我们将原本的 `buildConfig` 对象进行了浅拷贝并修改了浅拷贝后得到 `buildConfig.target`,将它指定为 `es5`。
73
+ 在上面的代码实现中,`preset.NPM_LIBRARY` 与预设字符串 `"npm-library"` 是相对应的,它代表着 `"npm-library"` 等价的多组构建相关的配置。我们通过 `map` 方法遍历了 `NPM_LIBRARY` 这个数组,在这个数组中包含了多个 `buildConfig` 对象。我们将原本的 `buildConfig` 对象进行了浅拷贝,并修改了浅拷贝后 `target` 的值,将它指定为 `es5`。
73
74
 
74
75
  > 关于 `preset.NPM_LIBRARY` 具体对应的值,可以通过 [BuildPreset API](/api/config/build-preset) 查看。在 `preset` 对象下不仅包含了 `NPM_LIBRARY`,还包含了其他类似的常量。
76
+ > 我们不仅可以使用 `preset.NPM_LIBRARY` 来获取 `"npm-library"` 对应的构建配置,也可以使用 `preset['npm-library']` 这样的方式。
75
77
 
76
78
  那么这里的 `buildConfig` 对象是什么呢?之前提到的构建产物特点又是根据什么呢?
77
79
 
@@ -112,7 +114,7 @@ export default defineConfig({
112
114
  - 指定 umd 产物外部导入的全局变量:对应的 API 是 [`buildConfig.umdGlobals`](/api/config/build-config#umdglobals)。
113
115
  - 指定 umd 产物的模块名:对应的 API 是 [`buildConfig.umdModuleName`](/api/config/build-config#umdmodulename)。
114
116
 
115
- 除了以上分类以外,关于这些 API 的常见问题和最佳实践可以通过下面的链接来了解
117
+ 除了以上分类以外,关于这些 API 的常见问题和最佳实践可以通过下面的链接来了解:
116
118
 
117
119
  - [什么是 `bundle` 和 `bundleless`?](/guide/advance/in-depth-about-build#bundle-和-bundleless)
118
120
  - [`input` 与 `sourceDir` 的关系](/guide/advance/in-depth-about-build#input-与-sourcedir-的关系)。
@@ -6,8 +6,8 @@ sidebar_position: 7
6
6
 
7
7
  一个 npm 类型的模块项目发布流程包含了两个阶段:
8
8
 
9
- - 第一阶段是在开发期间,开发者需要提供一个变更文件来记录需要发布的变动;
10
- - 第二阶段是在发布期间,Module Tools 可以收集所有的变更文件来更新版本、更新发布日志,并发布新的包到 [npm Registry](https://www.npmjs.com/) 上。
9
+ - 第一阶段是在开发期间,开发者需要提供变更文件,该文件记录了在发布期间需要的变更内容;
10
+ - 第二阶段是在发布期间,Module Tools 会收集所有的变更文件来更新版本、更新发布日志,并发布新的包到 [npm Registry](https://www.npmjs.com/) 上。
11
11
 
12
12
  ## 跟踪变更
13
13
 
@@ -18,7 +18,7 @@ sidebar_position: 7
18
18
  - 配置文件修改
19
19
  - ...
20
20
 
21
- 当这些变化一旦完成后,需要通过以下命令来对当前的变化进行记录:
21
+ 当这些任务一旦开发完成后,需要通过以下命令来对当前的变化进行记录:
22
22
 
23
23
  - [`modern change`](/guide/basic/command-preview#modern-change)
24
24
 
@@ -71,7 +71,7 @@ publish test
71
71
 
72
72
  发布项目可以执行以下命令:
73
73
 
74
- - [`modern publish`](/guide/basic/command-preview#modern-release)
74
+ - [`modern release`](/guide/basic/command-preview#modern-release)
75
75
 
76
76
  `modern release` 命令可以将项目发布到 npm Registry。
77
77
 
@@ -8,7 +8,21 @@ sidebar_position: 6
8
8
 
9
9
  ## 先决条件和约定
10
10
 
11
- 想要使用项目的测试功能,需要确保项目中包含依赖:`"@modern-js/plugin-testing"` ,可以通过[modern new](/guide/basic/command-preview#modern-new)来完成。
11
+ 想要使用项目的测试功能,需要确保项目中包含依赖:`"@modern-js/plugin-testing"`,以及按照类似下面的内容进行配置:
12
+
13
+ ``` ts
14
+ import moduleTools, { defineConfig } from '@modern-js/module-tools';
15
+ import testPlugin from '@modern-js/plugin-testing';
16
+
17
+ export default defineConfig({
18
+ plugins: [
19
+ moduleTools(),
20
+ testPlugin(),
21
+ ],
22
+ });
23
+ ```
24
+
25
+ 可以通过执行 [`modern new`](/guide/basic/command-preview#modern-new) 命令来开启测试功能。
12
26
 
13
27
  在模块工程方案中,对于测试用例或者说编写测试的文件有如下约定:
14
28
 
@@ -18,7 +32,7 @@ sidebar_position: 6
18
32
 
19
33
  ## 运行测试
20
34
 
21
- 当准备好了依赖以及了解了测试用例在哪里编写后,我们可以通过以下命令来执行测试:
35
+ 当准备好了依赖、增加了相关配置以及了解了测试用例在哪里编写后,我们可以通过以下命令来执行测试:
22
36
 
23
37
  ```bash
24
38
  modern test
@@ -33,7 +47,6 @@ modern test --updateSnapshot
33
47
 
34
48
  ## 使用配置
35
49
 
36
- /obj/eden-cn/uhbfnupenuhf/test-result.png
37
50
  模块工程方案对测试提供了以下配置:
38
51
 
39
52
  - [`testing`](/api/config/testing)
@@ -68,7 +81,7 @@ export default function () {
68
81
 
69
82
  然后在测试文件中,我们可以这样。
70
83
 
71
- 其中 `@` 指向了源码目录,在初始化项目的 `tests/tsconfig.json` 中定义了。
84
+ 其中 `@` 指向了源码目录,在初始化项目的 `tests/tsconfig.json` 的 `paths` 中定义了。
72
85
 
73
86
  ```typescript ./tests/index.test.ts
74
87
  import main from '@/index';
@@ -132,7 +145,7 @@ export const default () {
132
145
 
133
146
  然后在测试文件中,我们可以这样。
134
147
 
135
- 其中 `@` 指向了源码目录,在初始化项目的 `tests/tsconfig.json` 中定义了。
148
+ 其中 `@` 指向了源码目录,在初始化项目的 `tests/tsconfig.json` 的 `paths` 中定义了。
136
149
 
137
150
  ```tsx ./tests/index.test.tsx
138
151
  import { render, screen } from '@modern-js/runtime/testing';
@@ -16,12 +16,42 @@ sidebar_position: 4
16
16
 
17
17
  ## Test 测试
18
18
 
19
- 当我们想要对一些模块进行测试的时候,可以启用 test 测试功能。启动该功能后,**会在项目目录下创建 `tests` 目录以及相关文件,在 package.json 中新增 `"@modern-js/plugin-testing"` 依赖**。
19
+ 当我们想要对一些模块进行测试的时候,可以启用测试功能。启动该功能后,**会在项目目录下创建 `tests` 目录以及相关文件,在 package.json 中新增 `"@modern-js/plugin-testing"` 依赖**。
20
+
21
+ :::tip
22
+ 在成功开启后,会提示需要手动在配置中增加如下类似的代码。
23
+ ``` ts
24
+ import moduleTools, { defineConfig } from '@modern-js/module-tools';
25
+ import testPlugin from '@modern-js/plugin-testing';
26
+
27
+ export default defineConfig({
28
+ plugins: [
29
+ moduleTools(),
30
+ testPlugin(),
31
+ ],
32
+ });
33
+ ```
34
+ :::
20
35
 
21
36
  ## Storybook 调试
22
37
 
23
38
  当我们想要对组件或者普通模块进行调试的时候,可以启用 Storybook 调试功能。启动该功能后,**会在项目目录下创建 `stories` 目录以及相关文件,在 package.json 中新增 `"@modern-js/plugin-storybook"` 依赖**。
24
39
 
40
+ :::tip
41
+ 在成功开启后,会提示需要手动在配置中增加如下类似的代码。
42
+ ``` ts
43
+ import moduleTools, { defineConfig } from '@modern-js/module-tools';
44
+ import storybookPlugin from '@modern-js/plugin-storybook';
45
+
46
+ export default defineConfig({
47
+ plugins: [
48
+ moduleTools(),
49
+ storybookPlugin(),
50
+ ],
51
+ });
52
+ ```
53
+ :::
54
+
25
55
  关于如何启动 Storybook 以及如何使用 Storybook,可以查看下面的链接:
26
56
 
27
57
  - [`modern dev`](/guide/basic/command-preview#modern-dev)
@@ -35,8 +65,38 @@ sidebar_position: 4
35
65
 
36
66
  - [使用 Tailwind CSS](https://modernjs.dev/docs/apis/module/config/tools/tailwindcss)
37
67
 
68
+ :::tip
69
+ 在成功开启后,会提示需要手动在配置中增加如下类似的代码。
70
+ ``` ts
71
+ import moduleTools, { defineConfig } from '@modern-js/module-tools';
72
+ import tailwindPlugin from '@modern-js/plugin-tailwindcss';
73
+
74
+ export default defineConfig({
75
+ plugins: [
76
+ moduleTools(),
77
+ tailwindPlugin(),
78
+ ],
79
+ });
80
+ ```
81
+ :::
82
+
38
83
  ## 启动 Modern.js Runtime API
39
84
 
40
85
  **Modern.js 提供了 [Runtime API](https://modernjs.dev/docs/apis/module/runtime/) 能力,这些 API 只能在 Modern.js 的应用项目环境中使用**。如果你需要开发一个 Modern.js 应用环境中使用的组件,那么你可以开启该特性,微生成器会增加 `"@modern-js/runtime"`依赖。
41
86
 
42
87
  另外,Storybook 调试工具也会通过检测项目的依赖确定项目是否需要使用 Runtime API,并且提供与 Modern.js 应用项目一样的 Runtime API 运行环境。
88
+
89
+ :::tip
90
+ 在成功开启后,会提示需要手动在配置中增加如下类似的代码。
91
+ ``` ts
92
+ import moduleTools, { defineConfig } from '@modern-js/module-tools';
93
+ import runtime from '@modern-js/runtime/cli';
94
+
95
+ export default defineConfig({
96
+ plugins: [
97
+ moduleTools(),
98
+ runtime(),
99
+ ],
100
+ });
101
+ ```
102
+ :::