@modern-js/module-tools-docs 2.0.2 → 2.2.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 (313) hide show
  1. package/doc_build/api/config/build-config.html +332 -0
  2. package/doc_build/api/config/build-preset.html +43 -0
  3. package/doc_build/api/config/design-system.html +103 -0
  4. package/doc_build/api/config/plugins.html +7 -0
  5. package/doc_build/api/config/testing.html +21 -0
  6. package/doc_build/api/index.html +1 -0
  7. package/doc_build/api/plugin-api/plugin-hooks.html +113 -0
  8. package/doc_build/en/api/config/build-config.html +316 -0
  9. package/doc_build/en/api/config/build-preset.html +43 -0
  10. package/doc_build/en/api/config/design-system.html +117 -0
  11. package/doc_build/en/api/config/plugins.html +7 -0
  12. package/doc_build/en/api/config/testing.html +21 -0
  13. package/doc_build/en/api/index.html +1 -0
  14. package/doc_build/en/api/plugin-api/plugin-hooks.html +113 -0
  15. package/doc_build/en/guide/advance/asset.html +25 -0
  16. package/doc_build/en/guide/advance/build-umd.html +32 -0
  17. package/doc_build/en/guide/advance/copy.html +42 -0
  18. package/doc_build/en/guide/advance/external-dependency.html +31 -0
  19. package/doc_build/en/guide/advance/in-depth-about-build.html +112 -0
  20. package/doc_build/en/guide/advance/in-depth-about-dev-command.html +12 -0
  21. package/doc_build/en/guide/advance/theme-config.html +29 -0
  22. package/doc_build/en/guide/basic/before-getting-started.html +89 -0
  23. package/doc_build/en/guide/basic/command-preview.html +63 -0
  24. package/doc_build/en/guide/basic/modify-output-product.html +98 -0
  25. package/doc_build/en/guide/basic/publish-your-project.html +50 -0
  26. package/doc_build/en/guide/basic/test-your-project.html +31 -0
  27. package/doc_build/en/guide/basic/use-micro-generator.html +29 -0
  28. package/doc_build/en/guide/basic/using-storybook.html +66 -0
  29. package/doc_build/en/guide/best-practices/components.html +111 -0
  30. package/doc_build/en/guide/intro/getting-started.html +36 -0
  31. package/doc_build/en/guide/intro/welcome.html +13 -0
  32. package/doc_build/en/guide/intro/why-module-engineering-solution.html +9 -0
  33. package/doc_build/en/index.html +1 -0
  34. package/doc_build/en/plugins/guide/getting-started.html +15 -0
  35. package/doc_build/en/plugins/guide/plugin-object.html +14 -0
  36. package/doc_build/en/plugins/guide/setup-function.html +30 -0
  37. package/doc_build/en/plugins/official-list/overview.html +3 -0
  38. package/doc_build/guide/advance/asset.html +25 -0
  39. package/doc_build/guide/advance/build-umd.html +32 -0
  40. package/doc_build/guide/advance/copy.html +42 -0
  41. package/doc_build/guide/advance/external-dependency.html +31 -0
  42. package/doc_build/guide/advance/in-depth-about-build.html +112 -0
  43. package/doc_build/guide/advance/in-depth-about-dev-command.html +14 -0
  44. package/doc_build/guide/advance/theme-config.html +28 -0
  45. package/doc_build/guide/basic/before-getting-started.html +89 -0
  46. package/doc_build/guide/basic/command-preview.html +63 -0
  47. package/doc_build/guide/basic/modify-output-product.html +97 -0
  48. package/doc_build/guide/basic/publish-your-project.html +52 -0
  49. package/doc_build/guide/basic/test-your-project.html +32 -0
  50. package/doc_build/guide/basic/use-micro-generator.html +27 -0
  51. package/doc_build/guide/basic/using-storybook.html +67 -0
  52. package/doc_build/guide/best-practices/components.html +111 -0
  53. package/doc_build/guide/intro/getting-started.html +39 -0
  54. package/doc_build/guide/intro/welcome.html +13 -0
  55. package/doc_build/guide/intro/why-module-engineering-solution.html +9 -0
  56. package/doc_build/index.html +1 -0
  57. package/doc_build/plugins/guide/getting-started.html +15 -0
  58. package/doc_build/plugins/guide/plugin-object.html +14 -0
  59. package/doc_build/plugins/guide/setup-function.html +30 -0
  60. package/doc_build/plugins/official-list/overview.html +3 -0
  61. package/doc_build/static/css/main.edaad072.css +1 -0
  62. package/doc_build/static/js/1607.70af642a.js +2 -0
  63. package/doc_build/static/js/1607.70af642a.js.LICENSE.txt +23 -0
  64. package/doc_build/static/js/async/3799.e31e8293.js +1 -0
  65. package/doc_build/static/js/async/8652.6fbf1cb7.js +1 -0
  66. package/doc_build/static/js/async/en_api_config_build-config.367a5701.js +1 -0
  67. package/doc_build/static/js/async/en_api_config_build-preset.0d78b268.js +1 -0
  68. package/doc_build/static/js/async/en_api_config_design-system.b28d6723.js +1 -0
  69. package/doc_build/static/js/async/en_api_config_plugins.fc95fb77.js +1 -0
  70. package/doc_build/static/js/async/en_api_config_testing.8bc7f316.js +1 -0
  71. package/doc_build/static/js/async/en_api_index.669f0a56.js +1 -0
  72. package/doc_build/static/js/async/en_api_plugin-api_plugin-hooks.60d0260c.js +1 -0
  73. package/doc_build/static/js/async/en_guide_advance_asset.5ff1d623.js +1 -0
  74. package/doc_build/static/js/async/en_guide_advance_build-umd.c254ed46.js +1 -0
  75. package/doc_build/static/js/async/en_guide_advance_copy.45c0a51d.js +1 -0
  76. package/doc_build/static/js/async/en_guide_advance_external-dependency.a52d3247.js +1 -0
  77. package/doc_build/static/js/async/en_guide_advance_in-depth-about-build.51bf3569.js +1 -0
  78. package/doc_build/static/js/async/en_guide_advance_in-depth-about-dev-command.aec0b4e1.js +1 -0
  79. package/doc_build/static/js/async/en_guide_advance_theme-config.db0ad9fc.js +1 -0
  80. package/doc_build/static/js/async/en_guide_basic_before-getting-started.a22fc49a.js +1 -0
  81. package/doc_build/static/js/async/en_guide_basic_command-preview.1707ed29.js +1 -0
  82. package/doc_build/static/js/async/en_guide_basic_modify-output-product.ad453d13.js +1 -0
  83. package/doc_build/static/js/async/en_guide_basic_publish-your-project.08c5112f.js +1 -0
  84. package/doc_build/static/js/async/en_guide_basic_test-your-project.f5f6b204.js +1 -0
  85. package/doc_build/static/js/async/en_guide_basic_use-micro-generator.56325139.js +1 -0
  86. package/doc_build/static/js/async/en_guide_basic_using-storybook.9d721554.js +1 -0
  87. package/doc_build/static/js/async/en_guide_best-practices_components.45155af9.js +1 -0
  88. package/doc_build/static/js/async/en_guide_intro_getting-started.f8682be3.js +1 -0
  89. package/doc_build/static/js/async/en_guide_intro_welcome.9cc45924.js +1 -0
  90. package/doc_build/static/js/async/en_guide_intro_why-module-engineering-solution.7f2dae5c.js +1 -0
  91. package/doc_build/static/js/async/en_index.7bd869c4.js +1 -0
  92. package/doc_build/static/js/async/en_plugins_guide_getting-started.b850249c.js +1 -0
  93. package/doc_build/static/js/async/en_plugins_guide_plugin-object.bf6c6221.js +1 -0
  94. package/doc_build/static/js/async/en_plugins_guide_setup-function.80a2bd97.js +1 -0
  95. package/doc_build/static/js/async/en_plugins_official-list_overview.84e5cea0.js +1 -0
  96. package/doc_build/static/js/async/zh_api_config_build-config.048fd5ec.js +1 -0
  97. package/doc_build/static/js/async/zh_api_config_build-preset.7c13584d.js +1 -0
  98. package/doc_build/static/js/async/zh_api_config_design-system.1eecd474.js +1 -0
  99. package/doc_build/static/js/async/zh_api_config_plugins.c22dc4be.js +1 -0
  100. package/doc_build/static/js/async/zh_api_config_testing.a9888eed.js +1 -0
  101. package/doc_build/static/js/async/zh_api_index.22957707.js +1 -0
  102. package/doc_build/static/js/async/zh_api_plugin-api_plugin-hooks.a4d81bf6.js +1 -0
  103. package/doc_build/static/js/async/zh_guide_advance_asset.5b936003.js +1 -0
  104. package/doc_build/static/js/async/zh_guide_advance_build-umd.b6d541ff.js +1 -0
  105. package/doc_build/static/js/async/zh_guide_advance_copy.21a1aea4.js +1 -0
  106. package/doc_build/static/js/async/zh_guide_advance_external-dependency.c7cf5d4b.js +1 -0
  107. package/doc_build/static/js/async/zh_guide_advance_in-depth-about-build.64e795f3.js +1 -0
  108. package/doc_build/static/js/async/zh_guide_advance_in-depth-about-dev-command.168ce7dd.js +1 -0
  109. package/doc_build/static/js/async/zh_guide_advance_theme-config.b9570109.js +1 -0
  110. package/doc_build/static/js/async/zh_guide_basic_before-getting-started.6b06b54a.js +1 -0
  111. package/doc_build/static/js/async/zh_guide_basic_command-preview.1199124a.js +1 -0
  112. package/doc_build/static/js/async/zh_guide_basic_modify-output-product.8ccbc8d1.js +1 -0
  113. package/doc_build/static/js/async/zh_guide_basic_publish-your-project.bf11b1c4.js +1 -0
  114. package/doc_build/static/js/async/zh_guide_basic_test-your-project.ae52c47a.js +1 -0
  115. package/doc_build/static/js/async/zh_guide_basic_use-micro-generator.a091d57d.js +1 -0
  116. package/doc_build/static/js/async/zh_guide_basic_using-storybook.27829e44.js +1 -0
  117. package/doc_build/static/js/async/zh_guide_best-practices_components.7454d916.js +1 -0
  118. package/doc_build/static/js/async/zh_guide_intro_getting-started.a4c00d9a.js +1 -0
  119. package/doc_build/static/js/async/zh_guide_intro_welcome.71c3fe16.js +1 -0
  120. package/doc_build/static/js/async/zh_guide_intro_why-module-engineering-solution.6f8b5ff6.js +1 -0
  121. package/doc_build/static/js/async/zh_index.c19f9dcf.js +1 -0
  122. package/doc_build/static/js/async/zh_plugins_guide_getting-started.099dfaea.js +1 -0
  123. package/doc_build/static/js/async/zh_plugins_guide_plugin-object.963289d5.js +1 -0
  124. package/doc_build/static/js/async/zh_plugins_guide_setup-function.67d07b91.js +1 -0
  125. package/doc_build/static/js/async/zh_plugins_official-list_overview.a7635714.js +1 -0
  126. package/doc_build/static/js/lib-lodash.c5845536.js +1 -0
  127. package/doc_build/static/js/lib-polyfill.b3038509.js +1 -0
  128. package/doc_build/static/js/lib-react.d41ace5e.js +2 -0
  129. package/doc_build/static/js/lib-react.d41ace5e.js.LICENSE.txt +29 -0
  130. package/doc_build/static/js/main.2d3257a4.js +1 -0
  131. package/doc_build/static/search_index.json +1 -0
  132. package/docs/en/api/config/build-config.md +15 -5
  133. package/docs/en/api/config/build-preset.md +3 -2
  134. package/docs/en/api/config/design-system.md +623 -615
  135. package/docs/en/api/config/plugins.md +2 -2
  136. package/docs/en/api/config/testing.md +2 -1
  137. package/docs/en/guide/advance/asset.mdx +0 -4
  138. package/docs/en/guide/advance/build-umd.mdx +3 -3
  139. package/docs/en/guide/advance/in-depth-about-build.md +14 -13
  140. package/docs/en/guide/advance/in-depth-about-dev-command.md +2 -1
  141. package/docs/en/guide/basic/before-getting-started.md +16 -9
  142. package/docs/en/guide/basic/command-preview.md +2 -2
  143. package/docs/en/guide/basic/modify-output-product.md +65 -69
  144. package/docs/en/guide/basic/test-your-project.mdx +1 -3
  145. package/docs/en/guide/basic/use-micro-generator.md +4 -0
  146. package/docs/en/guide/basic/using-storybook.mdx +1 -13
  147. package/docs/en/plugins/guide/getting-started.mdx +2 -2
  148. package/docs/en/plugins/guide/plugin-object.mdx +5 -5
  149. package/docs/zh/api/config/build-config.md +18 -6
  150. package/docs/zh/api/config/build-preset.md +3 -2
  151. package/docs/zh/api/config/design-system.md +2 -2
  152. package/docs/zh/api/config/plugins.md +2 -2
  153. package/docs/zh/api/config/testing.md +3 -2
  154. package/docs/zh/guide/advance/asset.mdx +0 -5
  155. package/docs/zh/guide/advance/build-umd.mdx +3 -3
  156. package/docs/zh/guide/advance/in-depth-about-build.md +14 -13
  157. package/docs/zh/guide/advance/in-depth-about-dev-command.md +2 -1
  158. package/docs/zh/guide/basic/before-getting-started.md +15 -8
  159. package/docs/zh/guide/basic/command-preview.md +2 -2
  160. package/docs/zh/guide/basic/modify-output-product.md +17 -19
  161. package/docs/zh/guide/basic/test-your-project.mdx +1 -3
  162. package/docs/zh/guide/basic/use-micro-generator.md +5 -1
  163. package/docs/zh/guide/basic/using-storybook.mdx +9 -19
  164. package/docs/zh/guide/intro/getting-started.md +1 -1
  165. package/docs/zh/plugins/guide/getting-started.mdx +2 -2
  166. package/docs/zh/plugins/guide/plugin-object.mdx +5 -5
  167. package/modern.config.ts +11 -5
  168. package/package.json +3 -3
  169. package/LICENSE +0 -144
  170. package/doc_build/html/main/index.html +0 -16
  171. package/doc_build/route.json +0 -10
  172. package/doc_build/static/css/main.css +0 -3370
  173. package/doc_build/static/css/main.css.map +0 -1
  174. package/doc_build/static/css/vendors-node_modules_pnpm_remix-run_router_1_2_0_node_modules_remix-run_router_dist_router_js-9d5e9c.css +0 -85
  175. package/doc_build/static/css/vendors-node_modules_pnpm_remix-run_router_1_2_0_node_modules_remix-run_router_dist_router_js-9d5e9c.css.map +0 -1
  176. package/doc_build/static/js/async/api_.js +0 -56
  177. package/doc_build/static/js/async/api_.js.map +0 -1
  178. package/doc_build/static/js/async/api_config_build-config.js +0 -11309
  179. package/doc_build/static/js/async/api_config_build-config.js.map +0 -1
  180. package/doc_build/static/js/async/api_config_build-preset.js +0 -7849
  181. package/doc_build/static/js/async/api_config_build-preset.js.map +0 -1
  182. package/doc_build/static/js/async/api_config_design-system.js +0 -48708
  183. package/doc_build/static/js/async/api_config_design-system.js.map +0 -1
  184. package/doc_build/static/js/async/api_config_plugins.js +0 -1492
  185. package/doc_build/static/js/async/api_config_plugins.js.map +0 -1
  186. package/doc_build/static/js/async/api_config_testing.js +0 -2130
  187. package/doc_build/static/js/async/api_config_testing.js.map +0 -1
  188. package/doc_build/static/js/async/api_plugin-api_plugin-hooks.js +0 -14394
  189. package/doc_build/static/js/async/api_plugin-api_plugin-hooks.js.map +0 -1
  190. package/doc_build/static/js/async/en_.js +0 -85
  191. package/doc_build/static/js/async/en_.js.map +0 -1
  192. package/doc_build/static/js/async/en_api_.js +0 -55
  193. package/doc_build/static/js/async/en_api_.js.map +0 -1
  194. package/doc_build/static/js/async/en_api_config_build-config.js +0 -8363
  195. package/doc_build/static/js/async/en_api_config_build-config.js.map +0 -1
  196. package/doc_build/static/js/async/en_api_config_build-preset.js +0 -7845
  197. package/doc_build/static/js/async/en_api_config_build-preset.js.map +0 -1
  198. package/doc_build/static/js/async/en_api_config_design-system.js +0 -16345
  199. package/doc_build/static/js/async/en_api_config_design-system.js.map +0 -1
  200. package/doc_build/static/js/async/en_api_config_plugins.js +0 -1492
  201. package/doc_build/static/js/async/en_api_config_plugins.js.map +0 -1
  202. package/doc_build/static/js/async/en_api_config_testing.js +0 -2137
  203. package/doc_build/static/js/async/en_api_config_testing.js.map +0 -1
  204. package/doc_build/static/js/async/en_api_plugin-api_plugin-hooks.js +0 -14362
  205. package/doc_build/static/js/async/en_api_plugin-api_plugin-hooks.js.map +0 -1
  206. package/doc_build/static/js/async/en_guide_advance_asset.js +0 -3997
  207. package/doc_build/static/js/async/en_guide_advance_asset.js.map +0 -1
  208. package/doc_build/static/js/async/en_guide_advance_build-umd.js +0 -9861
  209. package/doc_build/static/js/async/en_guide_advance_build-umd.js.map +0 -1
  210. package/doc_build/static/js/async/en_guide_advance_copy.js +0 -6539
  211. package/doc_build/static/js/async/en_guide_advance_copy.js.map +0 -1
  212. package/doc_build/static/js/async/en_guide_advance_external-dependency.js +0 -3810
  213. package/doc_build/static/js/async/en_guide_advance_external-dependency.js.map +0 -1
  214. package/doc_build/static/js/async/en_guide_advance_in-depth-about-build.js +0 -5046
  215. package/doc_build/static/js/async/en_guide_advance_in-depth-about-build.js.map +0 -1
  216. package/doc_build/static/js/async/en_guide_advance_in-depth-about-dev-command.js +0 -150
  217. package/doc_build/static/js/async/en_guide_advance_in-depth-about-dev-command.js.map +0 -1
  218. package/doc_build/static/js/async/en_guide_advance_theme-config.js +0 -2484
  219. package/doc_build/static/js/async/en_guide_advance_theme-config.js.map +0 -1
  220. package/doc_build/static/js/async/en_guide_basic_before-getting-started.js +0 -3671
  221. package/doc_build/static/js/async/en_guide_basic_before-getting-started.js.map +0 -1
  222. package/doc_build/static/js/async/en_guide_basic_command-preview.js +0 -3961
  223. package/doc_build/static/js/async/en_guide_basic_command-preview.js.map +0 -1
  224. package/doc_build/static/js/async/en_guide_basic_modify-output-product.js +0 -2970
  225. package/doc_build/static/js/async/en_guide_basic_modify-output-product.js.map +0 -1
  226. package/doc_build/static/js/async/en_guide_basic_publish-your-project.js +0 -2182
  227. package/doc_build/static/js/async/en_guide_basic_publish-your-project.js.map +0 -1
  228. package/doc_build/static/js/async/en_guide_basic_test-your-project.js +0 -3892
  229. package/doc_build/static/js/async/en_guide_basic_test-your-project.js.map +0 -1
  230. package/doc_build/static/js/async/en_guide_basic_use-micro-generator.js +0 -168
  231. package/doc_build/static/js/async/en_guide_basic_use-micro-generator.js.map +0 -1
  232. package/doc_build/static/js/async/en_guide_basic_using-storybook.js +0 -4762
  233. package/doc_build/static/js/async/en_guide_basic_using-storybook.js.map +0 -1
  234. package/doc_build/static/js/async/en_guide_best-practices_components.js +0 -21388
  235. package/doc_build/static/js/async/en_guide_best-practices_components.js.map +0 -1
  236. package/doc_build/static/js/async/en_guide_intro_getting-started.js +0 -1906
  237. package/doc_build/static/js/async/en_guide_intro_getting-started.js.map +0 -1
  238. package/doc_build/static/js/async/en_guide_intro_welcome.js +0 -148
  239. package/doc_build/static/js/async/en_guide_intro_welcome.js.map +0 -1
  240. package/doc_build/static/js/async/en_guide_intro_why-module-engineering-solution.js +0 -92
  241. package/doc_build/static/js/async/en_guide_intro_why-module-engineering-solution.js.map +0 -1
  242. package/doc_build/static/js/async/en_plugins_guide_getting-started.js +0 -2560
  243. package/doc_build/static/js/async/en_plugins_guide_getting-started.js.map +0 -1
  244. package/doc_build/static/js/async/en_plugins_guide_plugin-object.js +0 -4177
  245. package/doc_build/static/js/async/en_plugins_guide_plugin-object.js.map +0 -1
  246. package/doc_build/static/js/async/en_plugins_guide_setup-function.js +0 -3819
  247. package/doc_build/static/js/async/en_plugins_guide_setup-function.js.map +0 -1
  248. package/doc_build/static/js/async/en_plugins_official-list_overview.js +0 -70
  249. package/doc_build/static/js/async/en_plugins_official-list_overview.js.map +0 -1
  250. package/doc_build/static/js/async/guide_advance_asset.js +0 -3997
  251. package/doc_build/static/js/async/guide_advance_asset.js.map +0 -1
  252. package/doc_build/static/js/async/guide_advance_build-umd.js +0 -9863
  253. package/doc_build/static/js/async/guide_advance_build-umd.js.map +0 -1
  254. package/doc_build/static/js/async/guide_advance_copy.js +0 -6539
  255. package/doc_build/static/js/async/guide_advance_copy.js.map +0 -1
  256. package/doc_build/static/js/async/guide_advance_external-dependency.js +0 -3812
  257. package/doc_build/static/js/async/guide_advance_external-dependency.js.map +0 -1
  258. package/doc_build/static/js/async/guide_advance_in-depth-about-build.js +0 -5046
  259. package/doc_build/static/js/async/guide_advance_in-depth-about-build.js.map +0 -1
  260. package/doc_build/static/js/async/guide_advance_in-depth-about-dev-command.js +0 -152
  261. package/doc_build/static/js/async/guide_advance_in-depth-about-dev-command.js.map +0 -1
  262. package/doc_build/static/js/async/guide_advance_theme-config.js +0 -2475
  263. package/doc_build/static/js/async/guide_advance_theme-config.js.map +0 -1
  264. package/doc_build/static/js/async/guide_basic_before-getting-started.js +0 -3662
  265. package/doc_build/static/js/async/guide_basic_before-getting-started.js.map +0 -1
  266. package/doc_build/static/js/async/guide_basic_command-preview.js +0 -3793
  267. package/doc_build/static/js/async/guide_basic_command-preview.js.map +0 -1
  268. package/doc_build/static/js/async/guide_basic_modify-output-product.js +0 -2949
  269. package/doc_build/static/js/async/guide_basic_modify-output-product.js.map +0 -1
  270. package/doc_build/static/js/async/guide_basic_publish-your-project.js +0 -2243
  271. package/doc_build/static/js/async/guide_basic_publish-your-project.js.map +0 -1
  272. package/doc_build/static/js/async/guide_basic_test-your-project.js +0 -3892
  273. package/doc_build/static/js/async/guide_basic_test-your-project.js.map +0 -1
  274. package/doc_build/static/js/async/guide_basic_use-micro-generator.js +0 -172
  275. package/doc_build/static/js/async/guide_basic_use-micro-generator.js.map +0 -1
  276. package/doc_build/static/js/async/guide_basic_using-storybook.js +0 -4762
  277. package/doc_build/static/js/async/guide_basic_using-storybook.js.map +0 -1
  278. package/doc_build/static/js/async/guide_best-practices_components.js +0 -21088
  279. package/doc_build/static/js/async/guide_best-practices_components.js.map +0 -1
  280. package/doc_build/static/js/async/guide_intro_getting-started.js +0 -1782
  281. package/doc_build/static/js/async/guide_intro_getting-started.js.map +0 -1
  282. package/doc_build/static/js/async/guide_intro_welcome.js +0 -148
  283. package/doc_build/static/js/async/guide_intro_welcome.js.map +0 -1
  284. package/doc_build/static/js/async/guide_intro_why-module-engineering-solution.js +0 -92
  285. package/doc_build/static/js/async/guide_intro_why-module-engineering-solution.js.map +0 -1
  286. package/doc_build/static/js/async/index.js +0 -85
  287. package/doc_build/static/js/async/index.js.map +0 -1
  288. package/doc_build/static/js/async/packages_cli_doc-core_src_theme-default_components_Search_logic_search_ts.js +0 -447
  289. package/doc_build/static/js/async/packages_cli_doc-core_src_theme-default_components_Search_logic_search_ts.js.map +0 -1
  290. package/doc_build/static/js/async/plugins_guide_getting-started.js +0 -2608
  291. package/doc_build/static/js/async/plugins_guide_getting-started.js.map +0 -1
  292. package/doc_build/static/js/async/plugins_guide_plugin-object.js +0 -4173
  293. package/doc_build/static/js/async/plugins_guide_plugin-object.js.map +0 -1
  294. package/doc_build/static/js/async/plugins_guide_setup-function.js +0 -3819
  295. package/doc_build/static/js/async/plugins_guide_setup-function.js.map +0 -1
  296. package/doc_build/static/js/async/plugins_official-list_overview.js +0 -70
  297. package/doc_build/static/js/async/plugins_official-list_overview.js.map +0 -1
  298. package/doc_build/static/js/async/vendors-node_modules_pnpm_code-hike_mdx_0_7_4_react_18_2_0_node_modules_code-hike_mdx_dist_co-06dd41.js +0 -6656
  299. package/doc_build/static/js/async/vendors-node_modules_pnpm_code-hike_mdx_0_7_4_react_18_2_0_node_modules_code-hike_mdx_dist_co-06dd41.js.map +0 -1
  300. package/doc_build/static/js/async/vendors-node_modules_pnpm_flexsearch_0_6_32_node_modules_flexsearch_dist_flexsearch_min_js.js +0 -54
  301. package/doc_build/static/js/async/vendors-node_modules_pnpm_flexsearch_0_6_32_node_modules_flexsearch_dist_flexsearch_min_js.js.map +0 -1
  302. package/doc_build/static/js/builder-runtime.js +0 -1375
  303. package/doc_build/static/js/builder-runtime.js.map +0 -1
  304. package/doc_build/static/js/lib-lodash.js +0 -4907
  305. package/doc_build/static/js/lib-lodash.js.map +0 -1
  306. package/doc_build/static/js/lib-polyfill.js +0 -24769
  307. package/doc_build/static/js/lib-polyfill.js.map +0 -1
  308. package/doc_build/static/js/lib-react.js +0 -39510
  309. package/doc_build/static/js/lib-react.js.map +0 -1
  310. package/doc_build/static/js/main.js +0 -9237
  311. package/doc_build/static/js/main.js.map +0 -1
  312. 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 +0 -8532
  313. 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 +0 -1
@@ -0,0 +1 @@
1
+ [{"id":0,"title":"BuildConfig","routePath":"/module-tools/en/api/config/build-config","toc":[{"id":"alias-2","text":"alias","depth":2},{"id":"asset-2","text":"asset","depth":2},{"id":"path-2","text":"path","depth":3},{"id":"limit-2","text":"limit","depth":3},{"id":"publicpath-2","text":"publicPath","depth":3},{"id":"svgr-2","text":"svgr","depth":3},{"id":"include-2","text":"include","depth":4},{"id":"exclude-2","text":"exclude","depth":4},{"id":"autoexternal-2","text":"autoExternal","depth":2},{"id":"dependencies-2","text":"dependencies","depth":3},{"id":"peerdependencies-4","text":"peerDependencies","depth":3},{"id":"buildtype-2","text":"buildType","depth":2},{"id":"copy-2","text":"copy","depth":2},{"id":"define-2","text":"define","depth":2},{"id":"dts-2","text":"dts","depth":2},{"id":"tsconfigpath-2","text":"tsconfigPath","depth":3},{"id":"distpath-2","text":"distPath","depth":3},{"id":"only-2","text":"only","depth":3},{"id":"externals-2","text":"externals","depth":2},{"id":"format-2","text":"format","depth":2},{"id":"input-2","text":"input","depth":2},{"id":"jsx-2","text":"jsx","depth":2},{"id":"metafile-2","text":"metafile","depth":2},{"id":"minify-2","text":"minify","depth":2},{"id":"outdir-2","text":"outDir","depth":2},{"id":"platform-2","text":"platform","depth":2},{"id":"sourcedir-4","text":"sourceDir","depth":2},{"id":"sourcemap-2","text":"sourceMap","depth":2},{"id":"splitting-2","text":"splitting","depth":2},{"id":"style-2","text":"style","depth":2},{"id":"less-4","text":"less","depth":3},{"id":"lessoptions-2","text":"lessOptions","depth":4},{"id":"additionaldata-4","text":"additionalData","depth":4},{"id":"implementation-4","text":"implementation","depth":4},{"id":"sass-2","text":"sass","depth":3},{"id":"sassoptions-2","text":"sassOptions","depth":4},{"id":"additionaldata-5","text":"additionalData","depth":4},{"id":"implementation-5","text":"implementation","depth":4},{"id":"postcss-2","text":"postcss","depth":3},{"id":"inject-2","text":"inject","depth":3},{"id":"automodules-2","text":"autoModules","depth":3},{"id":"modules-2","text":"modules","depth":3},{"id":"tailwindcss-4","text":"tailwindcss","depth":3},{"id":"target-2","text":"target","depth":2},{"id":"umdglobals-2","text":"umdGlobals","depth":2},{"id":"umdmodulename-2","text":"umdModuleName","depth":2}],"content":"BUILDCONFIG\n\nThis section describes all the configuration of Module Tools for building\n\n\nALIAS\n\n * type: Record<string, string> | Function\n * default: {'@': 'src',}\n\nFor TypeScript projects, you only need to configure compilerOptions.paths in\ntsconfig.json, Module Tools will automatically recognize the alias in\ntsconfig.json, so there is no need to configure the alias field additionally.\n\nexport default {\n buildConfig: {\n alias: {\n '@common': '. /src/common',\n },\n },\n};\n\n\nAfter the above configuration is done, if @common/Foo.tsx is referenced in the\ncode, it will map to the <root>/src/common/Foo.tsx path.\n\nWhen the value of alias is defined as a function, you can accept the pre-defined\nalias object and modify it.\n\nexport default {\n buildConfig: {\n alias: alias => {\n alias['@common'] = '. /src/common';\n },\n },\n};\n\n\nIt is also possible to return a new object as the final result in the function,\nwhich will override the pre-defined alias object.\n\nexport default {\n buildConfig: {\n alias: alias => {\n return {\n '@common': '. /src/common',\n };\n },\n },\n};\n\n\n\nASSET\n\n\nPATH\n\nStatic resource output path, will be based on outDir\n\n * type: string\n * default: assets\n\n\nLIMIT\n\nThreshold for automatically inlining static resources when building, resources\nless than 10 KB will be automatically inlined into the bundle product\n\n * type: number\n * default: 10 * 1024\n\n\nPUBLICPATH\n\nThe CDN prefix given to unlinked resources when packaging\n\n * type: string\n * default: undefined\n\nexport default {\n buildConfig: {\n asset: {\n publicPath: 'https://xxx/',\n },\n },\n};\n\n\nAt this point, all static resources will be prefixed with https://xxx/\n\n\nSVGR\n\nPackaged to handle svg as a React component, options reference svgr, plus\nsupport for two configuration items include and exclude to match the svg file to\nbe handled\n\n * type: boolean | Object\n * default: false\n\nINCLUDE\n\nSet the matching svg file\n\n * type: string | RegExp | (string | RegExp)[]\n * default: /\\.svg$/\n\nEXCLUDE\n\nSet unmatched svg files\n\n * type: string | RegExp | (string | RegExp)[]\n * default: undefined\n\n\nAUTOEXTERNAL\n\nAutomatically externalize project dependencies and peerDependencies and not\npackage them into the final bundle\n\n * type: boolean | Object\n * default: true\n\n\nDEPENDENCIES\n\nWhether or not the dep dependencies of the external project are needed\n\n * type: boolean\n * default: true\n\n\nPEERDEPENDENCIES\n\nWhether to require peerDep dependencies for external projects\n\n * type: boolean\n * default: true\n\n\nBUILDTYPE\n\nThe build type, bundle will package your code, bundleless will only do the code\nconversion\n\n * type: 'bundle' | 'bundleless'\n * default: bundle\n\n\nCOPY\n\nCopies the specified file or directory into the build output directory\n\n * type: Array\n * default: []\n\nexport default {\n buildConfig: {\n copy: [{ from: '. /src/assets', to: '' }],\n },\n};\n\n\nReference for array settings: copy-webpack-plugin patterns\n\n\nDEFINE\n\nDefine global variables that will be injected into the code\n\n * type: Record<string, string>\n * default: {}\n\nSince the define function is implemented by global text replacement, you need to\nensure that the global variable values are strings. A safer approach is to\nconvert the value of each global variable to a string, using JSON.stringify, as\nfollows.\n\nexport default {\n buildConfig: {\n define: {\n VERSION: JSON.stringify('1.0'),\n },\n },\n};\n\n\nTo prevent excessive global replacement substitution, it is recommended that the\nfollowing two principles be followed when using\n\n * Use upper case for global constants\n * Customize the prefix and suffix of global constants to ensure uniqueness\n\n\nDTS\n\nThe dts file generates the relevant configuration, by default it generates\n\n * type: false | Object\n * default: {}\n\n\nTSCONFIGPATH\n\nPath to the tsconfig file\n\n * type: string\n * default: . /tsconfig.json\n\n\nDISTPATH\n\nThe output path of the dts file, based on outDir\n\n * type: string\n * default: . /types\n\n\nONLY\n\nGenerate only dts files, not js files\n\n * type: boolean\n * default: false\n\n\nEXTERNALS\n\nConfigure external dependencies that will not be packaged into the final bundle\n\n * type: (string | RegExp)[]\n * default: []\n\n\nFORMAT\n\nThe format of the js product output, where iife and umd can only take effect\nwhen buildType is bundle\n\n * type: 'esm' | 'cjs' | 'iife' | 'umd'\n * default: cjs\n\n\nINPUT\n\nSpecify the entry file for the build, in the form of an array that can specify\nthe directory\n\n * type: string[] | Record<string, string>\n * default: ['src/index.ts'] in bundle mode, ['src'] in bundleless mode\n\nexport default {\n buildConfig: {\n input: ['src/index.ts', 'src/index2.ts'],\n },\n};\n\n\n\nJSX\n\nSpecify the compilation method of jsx, default support React17, automatically\ninject jsx runtime code\n\n * type: automatic | classic\n * default: automatic\n\n\nMETAFILE\n\nesbuild to produce some metadata about the build in JSON format, which can be\nvisualized by tools such as bundle-buddy\n\n * type: boolean\n * default: false\n\n\nMINIFY\n\nUse esbuild or terser to compress code, also pass terserOptions\n\n * type: 'terser' | 'esbuild' | false | Object\n * default: false\n\nexport default {\n buildConfig: {\n minify: {\n compress: {\n drop_console: true,\n },\n },\n },\n};\n\n\n\nOUTDIR\n\nSpecifies the output directory of the build\n\n * type: string\n * default: dist\n\n\nPLATFORM\n\nGenerates code for the node environment by default, you can also specify browser\nwhich will generate code for the browser environment\n\n * type: 'browser' | 'node'\n * default: node\n\n\nSOURCEDIR\n\nSpecify the source directory of the build, default is src, which is used to\ngenerate the corresponding product directory based on the source directory\nstructure when building bundleless.\n\n * type: string\n * default: src\n\n\nSOURCEMAP\n\nWhether to generate sourceMap or not\n\n * type: boolean | 'inline' | 'external'\n * default: false\n\n\nSPLITTING\n\nWhether to enable code splitting\n\n * type: boolean\n * default: false\n\n\nSTYLE\n\nConfigure style-related configuration\n\n\nLESS\n\nless-related configuration\n\nLESSOPTIONS\n\nRefer to less for detailed configuration\n\n * type: Object\n * default: { javascriptEnabled: true }\n\nADDITIONALDATA\n\nAdd Less code to the beginning of the entry file.\n\n * type: string\n * default: undefined\n\nexport default {\n buildConfig: {\n style: {\n less: {\n additionalData: `@base-color: #c6538c;`,\n },\n },\n },\n};\n\n\nIMPLEMENTATION\n\nConfigure the implementation library used by Less, if not specified, the\nbuilt-in version used is 4.1.3\n\n * type: string | Object\n * default: undefined\n\nSpecify the implementation library for Less when the Object type is specified\n\nexport default {\n buildConfig: {\n style: {\n less: {\n implementation: require('less'),\n },\n },\n },\n};\n\n\nFor the string type, specify the path to the implementation library for Less\n\nexport default {\n buildConfig: {\n style: {\n less: {\n implementation: require.resolve('less'),\n },\n },\n },\n};\n\n\n\nSASS\n\nsass-related configuration\n\nSASSOPTIONS\n\nRefer to node-sass for detailed configuration\n\n * type: Object\n * default: {}\n\nADDITIONALDATA\n\nAdd Sass code to the beginning of the entry file.\n\n * type: string | Function\n * default: undefined\n\nexport default {\n buildConfig: {\n style: {\n sass: {\n additionalData: `$base-color: #c6538c;\n $border-dark: rgba($base-color, 0.88);`,\n },\n },\n },\n};\n\n\nIMPLEMENTATION\n\nConfigure the implementation library used by Sass, the built-in version used is\n1.5.4 if not specified\n\n * type: string | Object\n * default: undefined\n\nSpecify the implementation library for Sass when the Object type is specified\n\nexport default {\n buildConfig: {\n style: {\n sass: {\n implementation: require('sass'),\n },\n },\n },\n};\n\n\nFor the string type, specify the path to the Sass implementation library\n\nexport default {\n buildConfig: {\n style: {\n sass: {\n implementation: require.resolve('sass'),\n },\n },\n },\n};\n\n\n\nPOSTCSS\n\n * plugins\n * processOptions\n\nSee postcss for detailed configuration\n\n\nINJECT\n\nConfigure whether to insert style into js in packaged mode\n\n * type: boolean\n * default: false\n\n\nAUTOMODULES\n\nEnable CSS Modules automatically based on the filename.\n\n * type: boolean | RegExp\n * default: true\n\ntrue : Enables CSS Modules for style files ending with .module.css .module.less\n.module.scss .module.sass filenames\n\nfalse : Disable CSS Modules.\n\nRegExp : Enables CSS Modules for all files that match the regular condition.\n\n\nMODULES\n\nCSS Modules configuration\n\n * type: Object\n * default: {}\n\nA common configuration is localsConvention, which changes the class name\ngeneration rules for css modules\n\nexport default {\n buildConfig: {\n style: {\n modules: {\n localsConvention: 'camelCaseOnly',\n },\n },\n },\n};\n\n\nFor the following styles\n\n.box-title {\n color: red;\n}\n\n\nYou can use styles.boxTitle to access\n\nFor detailed configuration see postcss-modules\n\n\nTAILWINDCSS\n\ntailwindcss related configuration\n\n * type: Object | Function\n * default: see configuration details below\n\nconst tailwind = {\n content: [\n './config/html/**/*.html',\n './config/html/**/*.ejs',\n './config/html/**/*.hbs',\n './src/**/*.js',\n './src/**/*.jsx',\n './src/**/*.ts',\n './src/**/*.tsx',\n './storybook/**/*',\n ],\n};\n\n\nWhen the value is of type Object, it is merged with the default configuration\nvia Object.assign.\n\nWhen the value is of type Function, the object returned by the function is\nmerged with the default configuration via Object.assign.\n\nThe theme property is not allowed, otherwise the build will fail, using\ndesignSystem as the Tailwind CSS Theme configuration.\n\nThe rest of the usage is the same as Tailwind CSS: Quick Portal.\n\n\nTARGET\n\nSpecify the target environment for the build\n\n * type: 'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' |\n 'es2020' | 'es2021' | 'es2022' | 'esnext'\n * default: 'es6'\n\n\nUMDGLOBALS\n\nSpecify global variables for external import of umd products\n\n * type: Record<string, string>\n * default: {}\n\nexport default {\n buildConfig: {\n umdGlobals: {\n react: 'React',\n 'react-dom': 'ReactDOM',\n },\n },\n};\n\n\nAt this point, react and react-dom will be seen as global variables imported\nexternally and will not be packed into the umd product, but will be accessible\nby way of global.React and global.ReactDOM\n\n\nUMDMODULENAME\n\nSpecifies the module name of the umd product\n\n * type: string | Function\n * default: name => name\n\nexport default {\n buildConfig: {\n format: 'umd',\n umdModuleName: 'myLib',\n },\n};\n\n\nAt this point the umd product will go to mount on global.myLib\n\n * The module name of the umd product must not conflict with the global variable\n name.\n * Module names should not contain special characters like -, @, /, etc.\n\nAlso the function form can take one parameter, which is the output path of the\ncurrent package file\n\nexport default {\n buildConfig: {\n format: 'umd',\n umdModuleName: path => {\n if (path.includes('index')) {\n return 'myLib';\n } else {\n return 'myLib2';\n }\n },\n },\n};\n","frontmatter":{"sidebar_position":1}},{"id":1,"title":"BuildPreset","routePath":"/module-tools/en/api/config/build-preset","toc":[{"id":"string-2","text":"string","depth":2},{"id":"npm-library-2","text":"``npm-library'`","depth":3},{"id":"npm-library-with-umd-2","text":"npm-library-with-umd'","depth":3},{"id":"npm-component-2","text":"'npm-component'","depth":3},{"id":"npm-component-with-umd-2","text":"'npm-component-with-umd'","depth":3},{"id":"about-the-ecmascript-versions-supported-by-the-presets-and-es5-esnext-1","text":"About the ECMAScript versions supported by the presets and {es5.... .esnext}","depth":3},{"id":"function-2","text":"Function","depth":2}],"content":"BUILDPRESET\n\nA build preset string or preset function. Provides out-of-the-box build\nconfiguration\n\n * type: string | Function\n * default: undefined\n\n\nSTRING\n\nThe string form allows you to use the built-in presets directly\n\n\n\nexport default defineConfig({\n buildPreset: 'npm-library',\n});\n\n\n\n``NPM-LIBRARY'`\n\nLibrary generic schema used under class NPM package manager, contains esm and\ncjs Bundle products, and includes a type file.\n\nAbout the class NPM Package Manager\n\n * npm\n * yarn\n * pnpm\n\n{\n \"main\": \". /dist/lib/index.js\",\n \"module\": \". /dist/es/index.js\",\n \"types\": \". /dist/types/index.d.ts\"\n}\n\n\nThe build configuration corresponding to the preset string.\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundle',\n outDir: '. /lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundle',\n outDir: '. /es',\n },\n {\n buildType: 'bundle',\n outDir: '. /types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nNPM-LIBRARY-WITH-UMD'\n\nUsed under class NPM package manager, and Library supports a similar pattern to\nunpkg. Additional umd products are provided on top of the pre-defined\nnpm-library.\n\n{\n \"main\": \". /dist/lib/index.js\",\n \"module\": \". /dist/es/index.js\",\n \"types\": \". /dist/types/index.d.ts\",\n \"unpkg\": \". /dist/umd/index.js\",\n};\n\n\nThe build configuration corresponding to the preset string.\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundle',\n outDir: '. /lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundle',\n outDir: '. /es',\n },\n {\n format: 'umd',\n target: 'es6',\n buildType: 'bundle',\n outDir: '. /umd',\n },\n {\n buildType: 'bundle',\n outDir: '. /types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\n'NPM-COMPONENT'\n\nA generic pattern for components (libraries) used under the class NPM package\nmanager. Contains both esm and cjs Bundleless products (for easy Tree shaking\noptimization), as well as including a copy of the type file.\n\nFor style files included in the source code, the products provide the compiled\nproduct of the style and the source file of the style.\n\n{\n \"main\": \". /dist/lib/index.js\", // bundleless type\n \"module\": \". /dist/es/index.js\", // bundleless type\n \"types\": \". /dist/types/index.d.ts\",\n};\n\n\nThe pre-defined strings correspond to the build configuration.\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundleless',\n outDir: '. /lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundleless',\n outDir: '. /es',\n },\n {\n buildType: 'bundleless',\n outDir: '. /types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\n'NPM-COMPONENT-WITH-UMD'\n\nComponent (library) used under class NPM package manager, with support for class\nunpkg schema. Additional umd products are provided on top of the pre-defined\nnpm-component.\n\n{\n \"main\": \". /dist/lib/index.js\", // bundleless type\n \"module\": \". /dist/es/index.js\", // bundleless type\n \"types\": \". /dist/types/index.d.ts\",\n \"unpkg\": \". /dist/umd/index.js\",\n};\n\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundleless',\n outDir: '. /lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundleless',\n outDir: '. /es',\n },\n {\n format: 'umd',\n target: 'es6',\n buildType: 'bundle',\n outDir: '. /umd',\n },\n {\n buildType: 'bundleless',\n outDir: '. /types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\nABOUT THE ECMASCRIPT VERSIONS SUPPORTED BY THE PRESETS AND {ES5.... .ESNEXT}\n\nWhen you want to use a buildPreset preset that supports other ECMAScript\nversions, you can directly add the supported versions to the 'npm-library',\n'npm-library-with-umd', 'npm-component', 'npm-component-with-umd' presets.\n\nFor example, if you want the 'npm-library' preset to support 'es2017', you can\nconfigure it as follows.\n\n\n\nexport default defineConfig({\n buildPreset: 'npm-library-es2017',\n});\n\n\n\nFUNCTION\n\nThe way the function is configured, you can get the preset value from the preset\nparameter and then modify the build configuration inside to customize your build\nconfiguration. The following is an example of how a function can be configured\nto compress a build product.\n\n\n\nexport default defineConfig({\n buildPreset({ preset }) {\n const { NPM_LIBRARY } = preset;\n return NPM_LIBRARY.map(config => {\n config.minify = {\n compress: {\n drop_console: true,\n },\n };\n return config;\n });\n },\n});\n","frontmatter":{"sidebar_position":2}},{"id":2,"title":"DesignSystem","routePath":"/module-tools/en/api/config/design-system","toc":[{"id":"screens-2","text":"Screens","depth":2},{"id":"max-width-breakpoints-1","text":"Max-width breakpoints","depth":3},{"id":"multiple-range-breakpoints-1","text":"Multiple range breakpoints","depth":3},{"id":"custom-media-queries-1","text":"Custom media queries","depth":3},{"id":"print-styles-1","text":"Print styles","depth":3},{"id":"dark-mode-2","text":"Dark Mode","depth":3},{"id":"colors-2","text":"Colors","depth":2},{"id":"spacing-2","text":"Spacing","depth":2},{"id":"core-plugins-1","text":"Core plugins","depth":2},{"id":"customizing-the-default-configuration-1","text":"Customizing the default configuration","depth":2},{"id":"override-the-default-configuration-1","text":"Override the default configuration","depth":3},{"id":"extending-the-default-configuration-1","text":"Extending the default configuration","depth":3},{"id":"referencing-other-values-1","text":"Referencing other values","depth":3},{"id":"disabling-the-entire-core-plugin-1","text":"Disabling the entire core plugin","depth":3},{"id":"adding-your-own-key-1","text":"Adding your own key","depth":3},{"id":"configuration-references-1","text":"Configuration references","depth":2}],"content":"DESIGNSYSTEM\n\nThis chapter describes the configuration related to designSystem\n\nThe Tailwind CSS feature needs to be enabled first via pnpm run new.\n\n * type: Object\n * default: see configuration details below.\n\nconst designSystem = {\n screens: {\n sm: '640px',\n md: '768px',\n lg: '1024px',\n xl: '1280px',\n },\n colors: {\n transparent: 'transparent',\n current: 'currentColor',\n\n black: '#000',\n white: '#fff',\n\n gray: {\n 100: '#f7fafc',\n 200: '#edf2f7',\n 300: '#e2e8f0',\n 400: '#cbd5e0',\n 500: '#a0aec0',\n 600: '#718096',\n 700: '#4a5568',\n 800: '#2d3748',\n 900: '#1a202c',\n },\n red: {\n 100: '#fff5f5',\n 200: '#fed7d7',\n 300: '#feb2b2',\n 400: '#fc8181',\n 500: '#f56565',\n 600: '#e53e3e',\n 700: '#c53030',\n 800: '#9b2c2c',\n 900: '#742a2a',\n },\n orange: {\n 100: '#fffaf0',\n 200: '#feebc8',\n 300: '#fbd38d',\n 400: '#f6ad55',\n 500: '#ed8936',\n 600: '#dd6b20',\n 700: '#c05621',\n 800: '#9c4221',\n 900: '#7b341e',\n },\n yellow: {\n 100: '#fffff0',\n 200: '#fefcbf',\n 300: '#faf089',\n 400: '#f6e05e',\n 500: '#ecc94b',\n 600: '#d69e2e',\n 700: '#b7791f',\n 800: '#975a16',\n 900: '#744210',\n },\n green: {\n 100: '#f0fff4',\n 200: '#c6f6d5',\n 300: '#9ae6b4',\n 400: '#68d391',\n 500: '#48bb78',\n 600: '#38a169',\n 700: '#2f855a',\n 800: '#276749',\n 900: '#22543d',\n },\n teal: {\n 100: '#e6fffa',\n 200: '#b2f5ea',\n 300: '#81e6d9',\n 400: '#4fd1c5',\n 500: '#38b2ac',\n 600: '#319795',\n 700: '#2c7a7b',\n 800: '#285e61',\n 900: '#234e52',\n },\n blue: {\n 100: '#ebf8ff',\n 200: '#bee3f8',\n 300: '#90cdf4',\n 400: '#63b3ed',\n 500: '#4299e1',\n 600: '#3182ce',\n 700: '#2b6cb0',\n 800: '#2c5282',\n 900: '#2a4365',\n },\n indigo: {\n 100: '#ebf4ff',\n 200: '#c3dafe',\n 300: '#a3bffa',\n 400: '#7f9cf5',\n 500: '#667eea',\n 600: '#5a67d8',\n 700: '#4c51bf',\n 800: '#434190',\n 900: '#3c366b',\n },\n purple: {\n 100: '#faf5ff',\n 200: '#e9d8fd',\n 300: '#d6bcfa',\n 400: '#b794f4',\n 500: '#9f7aea',\n 600: '#805ad5',\n 700: '#6b46c1',\n 800: '#553c9a',\n 900: '#44337a',\n },\n pink: {\n 100: '#fff5f7',\n 200: '#fed7e2',\n 300: '#fbb6ce',\n 400: '#f687b3',\n 500: '#ed64a6',\n 600: '#d53f8c',\n 700: '#b83280',\n 800: '#97266d',\n 900: '#702459',\n },\n },\n spacing: {\n px: '1px',\n 0: '0',\n 1: '0.25rem',\n 2: '0.5rem',\n 3: '0.75rem',\n 4: '1rem',\n 5: '1.25rem',\n 6: '1.5rem',\n 8: '2rem',\n 10: '2.5rem',\n 12: '3rem',\n 16: '4rem',\n 20: '5rem',\n 24: '6rem',\n 32: '8rem',\n 40: '10rem',\n 48: '12rem',\n 56: '14rem',\n 64: '16rem',\n },\n backgroundColor: theme => theme('colors'),\n backgroundOpacity: theme => theme('opacity'),\n backgroundPosition: {\n bottom: 'bottom',\n center: 'center',\n left: 'left',\n 'left-bottom': 'left bottom',\n 'left-top': 'left top',\n right: 'right',\n 'right-bottom': 'right bottom',\n 'right-top': 'right top',\n top: 'top',\n },\n backgroundSize: {\n auto: 'auto',\n cover: 'cover',\n contain: 'contain',\n },\n borderColor: theme => ({\n ...theme('colors'),\n default: theme('colors.gray.300', 'currentColor'),\n }),\n borderOpacity: theme => theme('opacity'),\n borderRadius: {\n none: '0',\n sm: '0.125rem',\n default: '0.25rem',\n md: '0.375rem',\n lg: '0.5rem',\n full: '9999px',\n },\n borderWidth: {\n default: '1px',\n 0: '0',\n 2: '2px',\n 4: '4px',\n 8: '8px',\n },\n boxShadow: {\n xs: '0 0 0 1px rgba(0, 0, 0, 0.05)',\n sm: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',\n default: '0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)',\n md: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',\n lg: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',\n xl: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',\n '2xl': '0 25px 50px -12px rgba(0, 0, 0, 0.25)',\n inner: 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)',\n outline: '0 0 0 3px rgba(66, 153, 225, 0.5)',\n none: 'none',\n },\n container: {},\n cursor: {\n auto: 'auto',\n default: 'default',\n pointer: 'pointer',\n wait: 'wait',\n text: 'text',\n move: 'move',\n 'not-allowed': 'not-allowed',\n },\n divideColor: theme => theme('borderColor'),\n divideOpacity: theme => theme('borderOpacity'),\n divideWidth: theme => theme('borderWidth'),\n fill: {\n current: 'currentColor',\n },\n flex: {\n 1: '1 1 0%',\n auto: '1 1 auto',\n initial: '0 1 auto',\n none: 'none',\n },\n flexGrow: {\n 0: '0',\n default: '1',\n },\n flexShrink: {\n 0: '0',\n default: '1',\n },\n fontFamily: {\n sans: [\n 'system-ui',\n '-apple-system',\n 'BlinkMacSystemFont',\n '\"Segoe UI\"',\n 'Roboto',\n '\"Helvetica Neue\"',\n 'Arial',\n '\"Noto Sans\"',\n 'sans-serif',\n '\"Apple Color Emoji\"',\n '\"Segoe UI Emoji\"',\n '\"Segoe UI Symbol\"',\n '\"Noto Color Emoji\"',\n ],\n serif: ['Georgia', 'Cambria', '\"Times New Roman\"', 'Times', 'serif'],\n mono: [\n 'Menlo',\n 'Monaco',\n 'Consolas',\n '\"Liberation Mono\"',\n '\"Courier New\"',\n 'monospace',\n ],\n },\n fontSize: {\n xs: '0.75rem',\n sm: '0.875rem',\n base: '1rem',\n lg: '1.125rem',\n xl: '1.25rem',\n '2xl': '1.5rem',\n '3xl': '1.875rem',\n '4xl': '2.25rem',\n '5xl': '3rem',\n '6xl': '4rem',\n },\n fontWeight: {\n hairline: '100',\n thin: '200',\n light: '300',\n normal: '400',\n medium: '500',\n semibold: '600',\n bold: '700',\n extrabold: '800',\n black: '900',\n },\n height: theme => ({\n auto: 'auto',\n ...theme('spacing'),\n full: '100%',\n screen: '100vh',\n }),\n inset: {\n 0: '0',\n auto: 'auto',\n },\n letterSpacing: {\n tighter: '-0.05em',\n tight: '-0.025em',\n normal: '0',\n wide: '0.025em',\n wider: '0.05em',\n widest: '0.1em',\n },\n lineHeight: {\n none: '1',\n tight: '1.25',\n snug: '1.375',\n normal: '1.5',\n relaxed: '1.625',\n loose: '2',\n 3: '.75rem',\n 4: '1rem',\n 5: '1.25rem',\n 6: '1.5rem',\n 7: '1.75rem',\n 8: '2rem',\n 9: '2.25rem',\n 10: '2.5rem',\n },\n listStyleType: {\n none: 'none',\n disc: 'disc',\n decimal: 'decimal',\n },\n margin: (theme, { negative }) => ({\n auto: 'auto',\n ...theme('spacing'),\n ...negative(theme('spacing')),\n }),\n maxHeight: {\n full: '100%',\n screen: '100vh',\n },\n maxWidth: (theme, { breakpoints }) => ({\n none: 'none',\n xs: '20rem',\n sm: '24rem',\n md: '28rem',\n lg: '32rem',\n xl: '36rem',\n '2xl': '42rem',\n '3xl': '48rem',\n '4xl': '56rem',\n '5xl': '64rem',\n '6xl': '72rem',\n full: '100%',\n ...breakpoints(theme('screens')),\n }),\n minHeight: {\n 0: '0',\n full: '100%',\n screen: '100vh',\n },\n minWidth: {\n 0: '0',\n full: '100%',\n },\n objectPosition: {\n bottom: 'bottom',\n center: 'center',\n left: 'left',\n 'left-bottom': 'left bottom',\n 'left-top': 'left top',\n right: 'right',\n 'right-bottom': 'right bottom',\n 'right-top': 'right top',\n top: 'top',\n },\n opacity: {\n 0: '0',\n 25: '0.25',\n 50: '0.5',\n 75: '0.75',\n 100: '1',\n },\n order: {\n first: '-9999',\n last: '9999',\n none: '0',\n 1: '1',\n 2: '2',\n 3: '3',\n 4: '4',\n 5: '5',\n 6: '6',\n 7: '7',\n 8: '8',\n 9: '9',\n 10: '10',\n 11: '11',\n 12: '12',\n },\n padding: theme => theme('spacing'),\n placeholderColor: theme => theme('colors'),\n placeholderOpacity: theme => theme('opacity'),\n space: (theme, { negative }) => ({\n ...theme('spacing'),\n ...negative(theme('spacing')),\n }),\n stroke: {\n current: 'currentColor',\n },\n strokeWidth: {\n 0: '0',\n 1: '1',\n 2: '2',\n },\n textColor: theme => theme('colors'),\n textOpacity: theme => theme('opacity'),\n width: theme => ({\n auto: 'auto',\n ...theme('spacing'),\n '1/2': '50%',\n '1/3': '33.333333%',\n '2/3': '66.666667%',\n '1/4': '25%',\n '2/4': '50%',\n '3/4': '75%',\n '1/5': '20%',\n '2/5': '40%',\n '3/5': '60%',\n '4/5': '80%',\n '1/6': '16.666667%',\n '2/6': '33.333333%',\n '3/6': '50%',\n '4/6': '66.666667%',\n '5/6': '83.333333%',\n '1/12': '8.333333%',\n '2/12': '16.666667%',\n '3/12': '25%',\n '4/12': '33.333333%',\n '5/12': '41.666667%',\n '6/12': '50%',\n '7/12': '58.333333%',\n '8/12': '66.666667%',\n '9/12': '75%',\n '10/12': '83.333333%',\n '11/12': '91.666667%',\n full: '100%',\n screen: '100vw',\n }),\n zIndex: {\n auto: 'auto',\n 0: '0',\n 10: '10',\n 20: '20',\n 30: '30',\n 40: '40',\n 50: '50',\n },\n gap: theme => theme('spacing'),\n gridTemplateColumns: {\n none: 'none',\n 1: 'repeat(1, minmax(0, 1fr))',\n 2: 'repeat(2, minmax(0, 1fr))',\n 3: 'repeat(3, minmax(0, 1fr))',\n 4: 'repeat(4, minmax(0, 1fr))',\n 5: 'repeat(5, minmax(0, 1fr))',\n 6: 'repeat(6, minmax(0, 1fr))',\n 7: 'repeat(7, minmax(0, 1fr))',\n 8: 'repeat(8, minmax(0, 1fr))',\n 9: 'repeat(9, minmax(0, 1fr))',\n 10: 'repeat(10, minmax(0, 1fr))',\n 11: 'repeat(11, minmax(0, 1fr))',\n 12: 'repeat(12, minmax(0, 1fr))',\n },\n gridColumn: {\n auto: 'auto',\n 'span-1': 'span 1 / span 1',\n 'span-2': 'span 2 / span 2',\n 'span-3': 'span 3 / span 3',\n 'span-4': 'span 4 / span 4',\n 'span-5': 'span 5 / span 5',\n 'span-6': 'span 6 / span 6',\n 'span-7': 'span 7 / span 7',\n 'span-8': 'span 8 / span 8',\n 'span-9': 'span 9 / span 9',\n 'span-10': 'span 10 / span 10',\n 'span-11': 'span 11 / span 11',\n 'span-12': 'span 12 / span 12',\n },\n gridColumnStart: {\n auto: 'auto',\n 1: '1',\n 2: '2',\n 3: '3',\n 4: '4',\n 5: '5',\n 6: '6',\n 7: '7',\n 8: '8',\n 9: '9',\n 10: '10',\n 11: '11',\n 12: '12',\n 13: '13',\n },\n gridColumnEnd: {\n auto: 'auto',\n 1: '1',\n 2: '2',\n 3: '3',\n 4: '4',\n 5: '5',\n 6: '6',\n 7: '7',\n 8: '8',\n 9: '9',\n 10: '10',\n 11: '11',\n 12: '12',\n 13: '13',\n },\n gridTemplateRows: {\n none: 'none',\n 1: 'repeat(1, minmax(0, 1fr))',\n 2: 'repeat(2, minmax(0, 1fr))',\n 3: 'repeat(3, minmax(0, 1fr))',\n 4: 'repeat(4, minmax(0, 1fr))',\n 5: 'repeat(5, minmax(0, 1fr))',\n 6: 'repeat(6, minmax(0, 1fr))',\n },\n gridRow: {\n auto: 'auto',\n 'span-1': 'span 1 / span 1',\n 'span-2': 'span 2 / span 2',\n 'span-3': 'span 3 / span 3',\n 'span-4': 'span 4 / span 4',\n 'span-5': 'span 5 / span 5',\n 'span-6': 'span 6 / span 6',\n },\n gridRowStart: {\n auto: 'auto',\n 1: '1',\n 2: '2',\n 3: '3',\n 4: '4',\n 5: '5',\n 6: '6',\n 7: '7',\n },\n gridRowEnd: {\n auto: 'auto',\n 1: '1',\n 2: '2',\n 3: '3',\n 4: '4',\n 5: '5',\n 6: '6',\n 7: '7',\n },\n transformOrigin: {\n center: 'center',\n top: 'top',\n 'top-right': 'top right',\n right: 'right',\n 'bottom-right': 'bottom right',\n bottom: 'bottom',\n 'bottom-left': 'bottom left',\n left: 'left',\n 'top-left': 'top left',\n },\n scale: {\n 0: '0',\n 50: '.5',\n 75: '.75',\n 90: '.9',\n 95: '.95',\n 100: '1',\n 105: '1.05',\n 110: '1.1',\n 125: '1.25',\n 150: '1.5',\n },\n rotate: {\n '-180': '-180deg',\n '-90': '-90deg',\n '-45': '-45deg',\n 0: '0',\n 45: '45deg',\n 90: '90deg',\n 180: '180deg',\n },\n translate: (theme, { negative }) => ({\n ...theme('spacing'),\n ...negative(theme('spacing')),\n '-full': '-100%',\n '-1/2': '-50%',\n '1/2': '50%',\n full: '100%',\n }),\n skew: {\n '-12': '-12deg',\n '-6': '-6deg',\n '-3': '-3deg',\n 0: '0',\n 3: '3deg',\n 6: '6deg',\n 12: '12deg',\n },\n transitionProperty: {\n none: 'none',\n all: 'all',\n default:\n 'background-color, border-color, color, fill, stroke, opacity, box-shadow, transform',\n colors: 'background-color, border-color, color, fill, stroke',\n opacity: 'opacity',\n shadow: 'box-shadow',\n transform: 'transform',\n },\n transitionTimingFunction: {\n linear: 'linear',\n in: 'cubic-bezier(0.4, 0, 1, 1)',\n out: 'cubic-bezier(0, 0, 0.2, 1)',\n 'in-out': 'cubic-bezier(0.4, 0, 0.2, 1)',\n },\n transitionDuration: {\n 75: '75ms',\n 100: '100ms',\n 150: '150ms',\n 200: '200ms',\n 300: '300ms',\n 500: '500ms',\n 700: '700ms',\n 1000: '1000ms',\n },\n transitionDelay: {\n 75: '75ms',\n 100: '100ms',\n 150: '150ms',\n 200: '200ms',\n 300: '300ms',\n 500: '500ms',\n 700: '700ms',\n 1000: '1000ms',\n },\n};\n\n\nMore about TailwindCSS configuration\n\nThe designSystem is used to define the project's color palette, typographic\nscales (Typographic Scales or Type Scale), font list, breakpoints, border\nrounding values, etc. Since Modern.js borrows the design approach from Tailwind\nTheme and integrates with Tailwind CSS internally, designSystem is used in the\nsame way as Tailwind CSS Theme\n\nThe designSystem object contains the screens, colors and spacing properties, as\nwell as each customizable core plugin.\n\n\nSCREENS\n\nThe responsive breakpoints in your project can be customized using screens: the\n\nconst designSystem = {\n screens: {\n sm: '640px',\n md: '768px',\n lg: '1024px',\n xl: '1280px',\n },\n};\n\n\nwhere the property name in the screens object is the screen name (used as a\nprefix for the adaptive utility variants generated by Tailwind CSS, e.g.\nmd:text-center) and the value is the min-width at which the breakpoint should\nstart.\n\nDefault breakpoints are inspired by common device resolutions: the\n\nconst designSystem = {\n screens: {\n sm: '640px',\n // => @media (min-width: 640px) { ... }\n\n md: '768px',\n // => @media (min-width: 768px) { ... }\n\n lg: '1024px',\n // => @media (min-width: 1024px) { ... }\n\n xl: '1280px',\n // => @media (min-width: 1280px) { ... }\n },\n};\n\n\nYou can use any name you like as a breakpoint property in your project: the\n\nconst designSystem = {\n screens: {\n tablet: '640px',\n // => @media (min-width: 640px) { ... }\n\n laptop: '1024px',\n // => @media (min-width: 1024px) { ... }\n\n desktop: '1280px',\n // => @media (min-width: 1280px) { ... }\n },\n};\n\n\nThese screen names are reflected in utilities, so text-center now looks like\nthis\n\n.text-center {\n text-align: center;\n}\n\n@media (min-width: 640px) {\n .tablet\\:text-center {\n text-align: center;\n }\n}\n\n@media (min-width: 1024px) {\n .laptop\\:text-center {\n text-align: center;\n }\n}\n\n@media (min-width: 1280px) {\n .desktop\\:text-center {\n text-align: center;\n }\n}\n\n\n\nMAX-WIDTH BREAKPOINTS\n\nTo use the max-width breakpoint instead of min-width, you can specify the screen\nas an object with the max attribute.\n\nconst designSystem = {\n screens: {\n xl: { max: '1279px' }\n // => @media (max-width: 1279px) { ... }\n\n lg: { max: '1023px' },\n // => @media (max-width: 1023px) { ... }\n\n md: { max: '767px' },\n // => @media (max-width: 767px) { ... }\n\n sm: { max: '639px' },\n // => @media (max-width: 639px) { ... }\n },\n};\n\n\nIf necessary, to create breakpoints with min-width and max-width definitions,\ne.g.\n\nconst designSystem = {\n screens: {\n sm: { min: '640px', max: '767px' }\n md: { min: '768px', max: '1023px' }\n lg: { min: '1024px', max: '1279px' }, lg: { min: '1024px', max: '1279px' },\n xl: { min: '1280px' }\n },\n};\n\n\n\nMULTIPLE RANGE BREAKPOINTS\n\nSometimes it can be useful to apply a single breakpoint definition to multiple\nscopes.\n\nFor example, suppose you have a sidebar and want the breakpoint to be based on\nthe width of the content area rather than the entire viewport. You can simulate\nthis situation by using a smaller breakpoint style when the sidebar is visible\nand the content area is narrowed: the\n\nconst designSystem = {\n screens: {\n sm: '500px',\n md: [\n // Sidebar appears at 768px, so revert to `sm:` styles between 768px\n // and 868px, after which the main content area is wide enough again to\n // apply the `md:` styles.\n { min: '668px', max: '767px' }\n { min: '868px' }, { min: '868px' },\n ],\n lg: '1100px',\n xl: '1400px',\n },\n};\n\n\n\nCUSTOM MEDIA QUERIES\n\nIf a fully customizable media query is required for a breakpoint, an object with\nthe raw attribute can be used.\n\nconst designSystem = {\n extend: {\n screens: {\n portrait: { raw: '(orientation: portrait)' },\n // => @media (orientation: portrait) { ... }\n },\n },\n};\n\n\n\nPRINT STYLES\n\nThe raw option may be particularly useful if you need to apply different styles\nto printing.\n\nAll that needs to be done is to add a print under designSystem.extend.screens.\n\n``js const designSystem = { extend: { screens: { print: { raw: 'print' }, // =>\n@media print { ... } }, }, };\n\n\nThen, 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: ``\n\n```html\n<div class=\"text-gray-700 print:text-black\">\n <! -- ... -->\n</div>\n\n\n\nDARK MODE\n\nraw 选项可以用于实现 “暗模式” 屏幕:\n\nconst designSystem = {\n extend: {\n screens: {\n dark: { raw: '(prefers-color-scheme: dark)' },\n // => @media (prefers-color-scheme: dark) { ... }\n },\n },\n};\n\n\n然后,您可以使用 dark: 前缀在暗模式下为元素设置不同的样式:\n\n<div class=\"text-gray-700 dark:text-gray-200\">\n <! -- ... -->\n</div>\n\n\n请注意,由于这些 screen variants 是在 Tailwind CSS 中实现的,因此无法使用这种方法将断点与暗模式结合使用 ,例如\nmd:dark:text-gray-300 将不起作用。\n\n\nCOLORS\n\ncolors 属性可让您自定义项目的全局调色板。\n\nconst designSystem = {\n colors: {\n transparent: 'transparent',\n black: '#000',\n white: '#fff',\n gray: {\n 100: '#f7fafc',\n // ...\n 900: '#1a202c',\n },\n\n // ...\n },\n};\n\n\nBy default, these colors are inherited by the backgroundColor, textColor and\nborderColor core plugins.\n\nTo learn more, you can check out: Customizing Colors.\n\n\nSPACING\n\nThe global spacing and scaling of items can be customized using the space\nattribute: the\n\nconst designSystem = {\n spacing: {\n px: '1px',\n 0: '0',\n 1: '0.25rem',\n 2: '0.5rem',\n 3: '0.75rem',\n 4: '1rem',\n 5: '1.25rem',\n 6: '1.5rem',\n 8: '2rem',\n 10: '2.5rem',\n 12: '3rem',\n 16: '4rem',\n 20: '5rem',\n 24: '6rem',\n 32: '8rem',\n 40: '10rem',\n 48: '12rem',\n 56: '14rem',\n 64: '16rem',\n },\n};\n\n\nBy default, these values are inherited by the padding, margin, negativeMargin,\nwidth and height core plugins.\n\nTo learn more, see Customizing Spacing.\n\n\nCORE PLUGINS\n\nThe rest of the theme section is used to configure the values available for each\ncore plugin.\n\nFor example, the borderRadius property allows you to customize the ``utilities`\nthat will generate the rounded corners.\n\n``js const designSystem = { borderRadius: { none: '0', sm: '.125rem', default:\n'.25rem', lg: '.5rem', full: '9999px', }, };\n\n\n** The attribute name determines the suffix of the generated class, and the value determines the value of the actual CSS declaration. **\nThe example ``borderRadius`` configuration above will generate the following CSS classes.\n\n```css\n.rounded-none { border-radius: 0 }\n.rounded-sm { border-radius: .125rem }\n.rounded { border-radius: .25rem }\n.rounded-lg { border-radius: .5rem }\n.rounded-full { border-radius: 9999px }\n\n\nYou will notice that the rounded class is created without the suffix in the\ntheme configuration using the default attribute. This is a common convention in\nTailwind CSS supported by many (though not all) of the core plugins.\n\nTo learn more about customizing a specific core plugin, please visit the\ndocumentation for that plugin.\n\n\nCUSTOMIZING THE DEFAULT CONFIGURATION\n\nOut of the box, your project will automatically inherit values from the default\ntheme configuration. If you want to customize the default theme, there are\nseveral different options depending on the goal.\n\n\nOVERRIDE THE DEFAULT CONFIGURATION\n\nTo override the options in the default configuration, add the properties to be\noverridden to designSystem at\n\n\n\nconst designSystem = {\n // Replaces all of the default `opacity` values\n opacity: {\n 0: '0',\n 20: '0.2',\n 40: '0.4',\n 60: '0.6',\n 80: '0.8',\n 100: '1',\n },\n};\n\nexport default defineConfig({\n designSystem,\n});\n\n\nThis will completely replace the default property configuration, so in the above\nexample, the default opacity utilities will not be generated.\n\nAny properties you do not provide will be inherited from the default theme, so\nin the example above, the default theme configuration for color, spacing, border\nrounding, background position, etc. will be retained.\n\n\nEXTENDING THE DEFAULT CONFIGURATION\n\nIf you want to keep the default values of the theme options but add new values,\nadd the extensions under the designSystem.extend property.\n\nFor example, if you want to add an additional breakpoint but keep the existing\none, you can extend the screens property with.\n\n\n\nconst designSystem = {\n extend: {\n // Adds a new breakpoint in addition to the default breakpoints\n screens: {\n '2xl': '1440px',\n },\n },\n};\n\nexport default defineConfig({\n designSystem,\n});\n\n\nYou can certainly override some parts of the default theme and extend other\nparts of the default theme in the same configuration: the\n\n\n\nconst designSystem = {\n opacity: {\n 0: '0',\n 20: '0.2',\n 40: '0.4',\n 60: '0.6',\n 80: '0.8',\n 100: '1',\n },\n extend: {\n screens: {\n '2xl': '1440px',\n },\n },\n};\n\nexport default defineConfig({\n designSystem,\n});\n\n\n\nREFERENCING OTHER VALUES\n\nIf you need to reference another value in the configuration, you can do so by\nproviding a closure function instead of a static value. The function will\nreceive the theme() function as an argument, and you can use this function to\nfind other values in the configuration using a dot representation.\n\nFor example, you can generate fill utilities for each color in the palette by\nreferring to theme('colors') on the fill configuration.\n\n\n\nconst designSystem = {\n colors: {\n // ...\n },\n fill: theme => theme('colors'),\n};\n\nexport default defineConfig({\n designSystem,\n});\n\n\nThe theme() function tries to find the value you are looking for from an already\nfully merged configuration object, so it can reference your own custom settings\nas well as the default theme value. It also works recursively, so as long as\nthere is a static value at the end of the chain, it can resolve the value you\nare looking for.\n\nReference to the default configuration\n\nIf for any reason you want to reference a value in the default configuration,\nyou can import it from tailwindcss/defaultTheme. A useful example would be to\nadd one of the fonts provided by the default configuration to.\n\n\n\nconst defaultTheme = require('tailwindcss/defaultTheme');\n\nconst designSystem = {\n extend: {\n fontFamily: {\n sans: ['Lato', ... .defaultTheme.fontFamily.sans],\n },\n },\n};\n\nexport default defineConfig({\n designSystem,\n});\n\n\n\nDISABLING THE ENTIRE CORE PLUGIN\n\nIf you don't want to generate any classes for a core plugin, it's better to set\nthe plugin to false in the corePlugins configuration, rather than providing an\nempty object for the property in the configuration: ``\n\n// Don't assign an empty object in your theme configuration\n\nconst designSystem = {\n opacity: {},\n};\n\n// Do disable the plugin in your corePlugins configuration\nconst designSyttem = {\n corePlugins: {\n opacity: { false,\n },\n};\n\n\nThe end result is the same, but since many core plugins don't expose any\nconfiguration, it's best to keep it consistent by only disabling them with\ncorePlugins anyway.\n\n\nADDING YOUR OWN KEY\n\nIn many cases it may be useful to add your own properties to the configuration\nobject.\n\nOne example is to add new properties for multiplexing between multiple core\nplugins. For example, you can extract a positions object that both the\nbackgroundPosition and objectPosition plugins can refer to.\n\nconst designSystem = {\n positions: {\n bottom: 'bottom',\n center: 'center',\n left: 'left',\n 'left-bottom': 'left bottom',\n 'left-top': 'left top',\n right: 'right',\n 'right-bottom': 'right bottom',\n 'right-top': 'right top',\n top: 'top',\n },\n backgroundPosition: theme => theme('positions'),\n objectPosition: theme => theme('positions'),\n};\n\n\nAnother example is to add a new property to a custom plugin for referencing. For\nexample, if you write a gradient plugin for your project, you can add a gradient\nproperty to the theme object referenced by that plugin.\n\n\n\nconst designSystem = {\n gradients: theme => ({\n 'blue-green': [theme('colors.blue.500'), theme('colors.green.500')],\n 'purple-blue': [theme('colors.purple.500'), theme('colors.blue.500')],\n // ...\n }),\n};\n\nexport default defineConfig({\n designSystem,\n buildConfig: {\n style: {\n postcss: {\n plugins: [require('. /plugins/gradients')],\n },\n },\n },\n});\n\n\n\nCONFIGURATION REFERENCES\n\nAll properties in the configuration object, except screens, colors and spacing,\nare mapped to the core plugins of Tailwind CSS. Since many plugins are\nresponsible for CSS properties that accept only static sets of values (e.g.,\ne.g., float), please note that not every plugin has a corresponding property in\nthe theme object.\n\nAll of these properties can also be used under the designSystem.extend property\nto extend the default theme.\n\nFor more information about what all the properties do, check out this link.","frontmatter":{"sidebar_position":3}},{"id":3,"title":"Plugins","routePath":"/module-tools/en/api/config/plugins","toc":[],"content":"PLUGINS\n\nThis chapter describes the configuration of the registered module-tools plugin.\n\n * type: Array<ModuleToolsPlugin>\n\n\nexport default defineConfig({\n plugins: [examplePlugin()],\n});\n\n\nFor more information on how to write plugins, check out the [Plugin Writing\nGuide].","frontmatter":{"sidebar_position":4}},{"id":4,"title":"Testing","routePath":"/module-tools/en/api/config/testing","toc":[{"id":"jest-2","text":"jest","depth":2},{"id":"transformer-2","text":"transformer","depth":2}],"content":"TESTING\n\nThis chapter describes the test-related configuration\n\nYou need to enable the unit testing feature with pnpm run new first.\n\n\nJEST\n\n * Type: Object | Function\n * Default value: {}\n\nThe configuration corresponding to Jest, when of type Object, can be configured\nwith all the underlying configurations supported by Jest .\n\n\n\nexport default defineConfig({\n testing: {\n jest: {\n testTimeout: 10000,\n },\n },\n});\n\n\nWhen the value is of type Function, the default configuration is passed as the\nfirst parameter and a new Jest configuration object needs to be returned.\n\n\n\nexport default defineConfig({\n testing: {\n jest: options => {\n return {\n ... . options,\n testTimeout: 10000\n }\n }\n }\n});\n\n\n\nTRANSFORMER\n\n * type: 'babel-jest' | 'ts-jest'\n * Default value: 'babel-jest'\n\nConfigure the compilation tool for the source code when executing tests:\nbabel-jest or ts-jest. The default is babel-jest.\n\nbabel-jest can also compile TS files without type errors, so use ts-jest if you\nneed to check the TS type when running tests.","frontmatter":{"sidebar_position":5}},{"id":5,"title":"Overview","routePath":"/module-tools/en/api/","toc":[],"content":"OVERVIEW","frontmatter":{"overview":true,"sidebar_label":"Overview"}},{"id":6,"title":"Plugin Hooks","routePath":"/module-tools/en/api/plugin-api/plugin-hooks","toc":[{"id":"build-hooks-1","text":"build hooks","depth":2},{"id":"beforebuild-2","text":"beforeBuild","depth":3},{"id":"beforebuildtask-2","text":"beforeBuildTask","depth":3},{"id":"afterbuildtask-2","text":"afterBuildTask","depth":3},{"id":"afterbuild-2","text":"afterBuild","depth":3},{"id":"buildplatform-hooks-1","text":"buildPlatform hooks","depth":2},{"id":"registerbuildplatform-2","text":"registerBuildPlatform","depth":3},{"id":"beforebuildplatform-2","text":"beforeBuildPlatform","depth":3},{"id":"buildplatform-2","text":"buildPlatform","depth":3},{"id":"afterbuildplatform-2","text":"afterBuildPlatform","depth":3},{"id":"dev-hooks-1","text":"Dev Hooks","depth":2},{"id":"registerdev-2","text":"registerDev.","depth":3},{"id":"beforedev-2","text":"beforeDev","depth":3},{"id":"beforeafterdevmenu-2","text":"(before|after)DevMenu","depth":3},{"id":"beforedevtask-2","text":"beforeDevTask","depth":3},{"id":"afterdev-2","text":"afterDev","depth":3}],"content":"PLUGIN HOOKS\n\nThis chapter describes the lifecycle hooks supported by module-tools.\n\nCurrently there are two main types of lifecycle hooks.\n\n * Build hooks: triggered only when the build command is executed to build the\n source code product.\n * buildPlatform hook: triggered only when the build --platform command is\n executed to generate other build products.\n * dev hooks: hooks that are triggered when running the dev command.\n\n\nBUILD HOOKS\n\nThe following Hooks are triggered in order when the build command is executed.\n\n * beforeBuild\n * beforeBuildTask\n * afterBuildTask\n * afterBuild\n\n\nBEFOREBUILD\n\nTriggered before the execution of the overall build process.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuild(options: Options): Return {\n return options.config;\n }\n }\n },\n});\n\n\nParameters and return value types.\n\ntype Options = { options: { config: BuildConfig; cliOptions: BuildCommandOptions } }\n\nexport interface BuildCommandOptions {\n config: string;\n clear?: boolean;\n dts?: boolean;\n platform?: boolean | string[];\n tsconfig: string;\n watch?: boolean;\n}\n\ntype Return = BuildConfig;\n\n\n> BuildConfig type reference API configuration\n\n\nBEFOREBUILDTASK\n\nBased on the build configuration, Module Tools will split the overall build into\nmultiple sub-build tasks. The Hook will be triggered before each build subtask.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuildTask(config: BaseBuildConfig): BaseBuildConfig {\n return config;\n }\n }\n },\n});\n\n\nParameters and return value types.\n\nBaseBuildConfig type reference API configuration\n\n\nAFTERBUILDTASK\n\nTriggered after the end of each build subtask.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuildTask(options: BuildTaskResult): void {\n // ...\n }\n }\n },\n});\n\n\nParameters and return value types.\n\nexport interface BuildTaskResult {\n status: 'success' | 'fail';\n message?: string;\n config: BaseBuildConfig;\n}\n\n\n\nAFTERBUILD\n\nTriggered after the end of the overall build process.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuild(options: BuildResult): void {\n // ...\n }\n }\n },\n});\n\n\nParameters and return value types.\n\nexport interface BuildResult {\n status: 'success' | 'fail';\n message?: string;\n config: BuildConfig;\n commandOptions: BuildCommandOptions;\n totalDuration: number;\n}\n\n\n\nBUILDPLATFORM HOOKS\n\nmodule-tools also provides the build --platform command to perform specific\nbuild tasks.\n\nFor example, after installing the Storybook plugin, you can run build --platform\nor build --platform storybook to perform Storybook build tasks. This is because\nthe Storybook plugin is based on the buildPlatform Hooks.\n\nHooks are triggered in the following order after executing build --platform.\n\n * registerBuildPlatform\n * beforeBuildPlatform\n * buildPlatform\n * afterBuildPlatform\n\n\nREGISTERBUILDPLATFORM\n\nGets information about the tasks that need to be run when executing the build\n--platform command.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n registerBuildPlatform(): RegisterBuildPlatformResult {\n // ...\n return {\n platform: 'stroybook',\n build() {\n // run storybook logic\n },\n }, };\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface RegisterBuildPlatformResult {\n platform: string | string[];\n build: (\n currentPlatform: string, // the currently running platform build task\n context: { isTsProject: boolean },\n ) => void | Promise<void>;\n}\n\n\n\nBEFOREBUILDPLATFORM\n\nTriggers all registered build tasks when the build --platform command is\nexecuted. beforeBuildPlatform will be triggered before the execution of the\noverall build task.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuildPlatform(platforms: RegisterBuildPlatformResult[]): void {\n console.info(`have ${platforms.length} platform tasks`);\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface RegisterBuildPlatformResult {\n platform: string | string[];\n build: (\n currentPlatform: string, // the currently running platform build task\n context: { isTsProject: boolean },\n ) => void | Promise<void>;\n}\n\n\n\nBUILDPLATFORM\n\nWhen the build --platform command is executed, all registered build tasks will\nbe triggered. buildPlatform will be triggered before each build task is\nexecuted.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n buildPlatform({ platform }: Options): void {\n console.info(`current task is ${platform}`);\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface Options {\n platform: string;\n}\n\n\n\nAFTERBUILDPLATFORM\n\nWhen the build --platform command is executed, all registered build tasks will\nbe triggered. afterBuildPlatform will be triggered after the overall platform\nbuild task is finished.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuildPlatform(result: BuildPlatformResult): void {\n if (result.status === 'success') {\n console.info(`all platform build task success`);\n } else {\n console.error(result.message);\n }\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface BuildPlatformResult {\n status: 'success' | 'fail';\n message: string | Error | null;\n}\n\n\n\nDEV HOOKS\n\nThe following Hooks are triggered in order when the dev command is executed.\n\n * registerDev: triggered when getting dev function information.\n * beforeDev: Triggered before starting the dev process as a whole.\n * beforeDevMenu: triggered before the dev list/menu appears.\n * afterDevMenu: triggered after dev list/menu option is selected.\n * beforeDevTask: Triggered before executing the dev task.\n * afterDev: Triggered at the end of the overall dev process.\n\n\nREGISTERDEV.\n\nRegister dev tool related data. Mainly contains.\n\n * the name of the dev tool\n * The name of the item displayed in the menu list and the corresponding value.\n * The definition of the dev subcommand.\n * Whether to execute the source code build before running the dev task\n * The function to execute the dev task.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n registerDev() {\n return {\n // Dev tool name\n name: 'storybook',\n // Menu content\n menuItem: {\n name: 'Storybook',\n value: 'storybook',\n },\n // Defined dev subcommands\n subCommands: ['storybook', 'story'],\n async action() {\n // dev logic\n },\n };\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n // Whether to disable the source build before the dev command is executed\n disableRunBuild?: boolean;\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise<void>;\n}\n\n\nWhen dev a project, it may be possible to set disableRunBuild: true to disable\nbuild tasks for source execution (in listening mode) if you only need to dev\ncode functionality.\n\nThe currently supported Storybook dev supports using source code products as dev\nobjects, so disableRunBuild: false in the Storybook plugin.\n\n\nBEFOREDEV\n\nTriggered before the dev task is executed after all dev tool metadata has been\ncollected.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDev(metas: DevToolData[]) {\n console.info(`have ${metas.length} dev tools`);\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n // Whether to disable the source build before the dev command is executed\n disableRunBuild?: boolean;\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise<void>;\n}\n\n\n\n(BEFORE|AFTER)DEVMENU\n\nbeforeDevMenu is triggered before the dev list/menu appears. Receives inquirer\nquestion as argument. Default value is.\n\nconst question = [\n {\n name: 'choiceDevTool',\n message: 'Select dev tool',\n type: 'list',\n // Registered dev messages\n choices,\n },\n];\n\n\nafterDevMenu Triggered after selecting dev list/menu options.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDevMenu(questions) {\n questions[0].message += '!' ;\n return questions; // required\n },\n afterDevMenu(options: Options) {\n console.info(`choise ${options.result.choiceDevTool} dev tools`);\n }\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport type { QuestionCollection } from 'inquirer';\n\nexport interface Options {\n result: PromptResult;\n devTools: DevToolData[];\n}\n\nexport type PromptResult = { choiceDevTool: string }\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n // Whether to disable the source build before the dev command is executed\n disableRunBuild?: boolean;\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise<void>;\n}\n\n\n\nBEFOREDEVTASK\n\nTriggered before the dev task is executed.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDevTask(currentDevData: DevToolData) {\n console.info(`${currentDevData.name} running`);\n },\n };\n },\n});\n\n\nTypes of parameters entered and returned.\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n // Whether to disable the source build before the dev command is executed\n disableRunBuild?: boolean;\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise<void>;\n}\n\n\n\nAFTERDEV\n\nTriggered when the dev task process is interrupted.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterDev() {\n console.info(`exit!`);\n },\n };\n },\n});\n","frontmatter":{}},{"id":7,"title":"Handle static resource files","routePath":"/module-tools/en/guide/advance/asset","toc":[{"id":"default-behavior-1","text":"Default behavior","depth":2},{"id":"setting-cdn-prefix-1","text":"Setting CDN Prefix","depth":2}],"content":"HANDLE STATIC RESOURCE FILES\n\nThe module project will handle static resources used in the code. If\nconfiguration is required, then the buildConfig.asset API can be used.\n\n\nDEFAULT BEHAVIOR\n\nBy default, module projects are processed for the following static resources:\n\n * '.svg'、'.png'、'.jpg'、'.jpeg'、'.gif'、'.webp'\n * '.ttf'、'.otf'、'.woff'、'.woff2'、'.eot'\n * '.mp3'、'.mp4'、'.webm'、'.ogg'、'.wav'、'.flac'、'.aac'、'.mov'\n\nFor the handling of static files, the module project currently supports the\nfollowing functions.\n\n * Set the static resource path to . /assets.\n * For files over 10kb they are inlined into the code.\n\nLet us look at the following example:\n\n<CH.Spotlight>\n\n\n//...\n\n\n--------------------------------------------------------------------------------\n\nProject source code.\n\n\n//...\n\n\n--------------------------------------------------------------------------------\n\nIf the size of bg.png is less than 10 kb, then the product directory structure\nand product content are.\n\n<CH.Code>\n\n./dist\n└── asset.js\n\n\n--------------------------------------------------------------------------------\n\nvar bg_default = 'data:image/png;base64,';\nconsole.info(bg_default);\n\n\n</CH.Code>\n\nIf the size of bg.png is larger than 10 kb, then the product directory structure\nand product content are.\n\n<CH.Code>\n\n./dist\n├── asset.js\n└── assets\n └── bg.13e2aba2.png\n\n\n--------------------------------------------------------------------------------\n\nvar bg_default = 'assets/bg.13e2aba2.png';\nconsole.info(bg_default);\n\n\n</CH.Code>\n\n</CH.Spotlight>\n\nWhen wanting to modify the default behavior, the following API can be used:\n\n * asset.path: modify the output path of the static resource file.\n * asset.limit: modify the threshold value for inline static resource files.\n\n\nSETTING CDN PREFIX\n\nIf the project is running in a browser environment, we may need to host static\nresources to a CDN and then use them in the production environment.\n\nThen we need to add the CDN base path in front of the path to the static\nresource file in the default generated build product. Again, see an example:\n\n<CH.Spotlight>\n\n\n//...\n\n\n--------------------------------------------------------------------------------\n\nProject source code.\n\n\n\n--------------------------------------------------------------------------------\n\nmodern.config config file。\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n asset: {\n publicPath: 'https://cdn/',\n },\n },\n});\n\n\n--------------------------------------------------------------------------------\n\nIf the size of bg.png is larger than 10 kb, then the product content will be.\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory();\n else if (typeof define === 'function' && define.amd) define([], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory();\n})(this, function () {\n 'use strict';\n var bg_default = 'http://cdn/assets/bg.13e2aba2.png';\n // src/asset.tsx\n console.info(bg_default);\n});\n\n\n</CH.Spotlight>","frontmatter":{"sidebar_position":6}},{"id":8,"title":"Build umd products","routePath":"/module-tools/en/guide/advance/build-umd","toc":[{"id":"third-party-dependency-handling-for-umd-products-1","text":"Third-party dependency handling for umd products","depth":2},{"id":"changing-the-name-of-a-global-variable-in-a-project-1","text":"Changing the name of a global variable in a project","depth":2}],"content":"BUILD UMD PRODUCTS\n\nThe full name of umd is Universal Module Definition, and JS files in this format\ncan run in multiple runtime environments: the\n\n * Browser environment: module loading based on AMD specification\n * Node.js environment: module loading based on CommonJS\n * Other cases: mount the module on a global object.\n\nWe can therefore specify the build product of the project as an umd product in\nthe following way:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n },\n});\n\n\n\nTHIRD-PARTY DEPENDENCY HANDLING FOR UMD PRODUCTS\n\nIn the [How to handle third-party dependencies] chapter, we know that we can\ncontrol whether or not the project packages third-party dependencies via the\nautoExternals and externals APIs. So when building umd products, we can also use\nit like this:\n\n<CH.Spotlight>\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n //...other dependencies\n }\n}\n\n\n--------------------------------------------------------------------------------\n\nIf the project depends on react.\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n //...other dependencies\n }\n}\n\n\n--------------------------------------------------------------------------------\n\nmodern.config.ts.\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n autoExternal: false,\n externals: ['react'],\n },\n});\n\n\n--------------------------------------------------------------------------------\n\nWhen a react dependency is used in the source code.\n\n\nconsole.info(React);\n\n\n--------------------------------------------------------------------------------\n\nThe react code is not packaged into the product at this point.\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports, require('react'));\n else if (typeof define === 'function' && define.amd)\n define(['exports', 'react'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.index = {}), global.react);\n})(this, function (exports, _react) {\n 'use strict';\n Object.defineProperty(exports, '__esModule', {\n value: true,\n });\n _react = /*#__PURE__*/ _interopRequireDefault(_react);\n function _interopRequireDefault(obj) {\n return obj && obj.__esModule\n ? obj\n : {\n default: obj,\n };\n }\n console.info(_react.default);\n});\n\n\n</CH.Spotlight>\n\nWe know from the above example that when using the autoExternal and externals\nAPIs.\n\n * In a Node.js environment, you can get the react dependency with\n require('react').\n * In a browser environment, you can get the react dependency via global.react.\n\nHowever, in the browser environment, when getting third-party dependencies,\nglobal variable names are not necessarily identical to the dependency names, so\nyou have to use the buildConfig.umdGlobals API.\n\nAgain using the previous example, when the react dependency exists in the\nbrowser environment as a windows.React or global.React global variable, then:\n\n<CH.Spotlight>\n\n{\n \"devDependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\n--------------------------------------------------------------------------------\n\nIf the project depends on react.\n\n{\n \"devDependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\n--------------------------------------------------------------------------------\n\nmodern.config.ts config file。\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdGlobals: {\n react: 'React',\n },\n },\n});\n\n\n--------------------------------------------------------------------------------\n\nWhen a react dependency is used in the source code.\n\n\nconsole.info(React);\n\n\n--------------------------------------------------------------------------------\n\nAt this point we will see the product code like this.\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory();\n else if (typeof define === 'function' && define.amd) define([], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory();\n})(this, function () {\n // ...\n // libuild:globals:react\n var require_react = __commonJS({\n 'libuild:globals:react'(exports, module1) {\n module1.exports = Function('return this')()['React'];\n },\n });\n // src/index.ts\n var import_react = __toESM(require_react());\n console.info(import_react.default);\n});\n\n\n</CH.Spotlight>\n\nThe project can then run in the browser and use the React variables that exist\non the global object.\n\n\nCHANGING THE NAME OF A GLOBAL VARIABLE IN A PROJECT\n\nWhen we package the following code into an umd product and run it in the\nbrowser, we can use the module via window.index.\n\nexport default () => {\n console.info('hello world');\n};\n\n\n** By default, the name of the source file is used as the name of the module's\nglobal variable in the browser. **For the above example, the product would read\nas follows:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports);\n else if (typeof define === 'function' && define.amd)\n define(['exports'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.index = {}));\n})(this, function (exports) {\n //...\n});\n\n\nIf you need to modify it, you need to use the buildConfig.umdModuleName API.\n\nWhen this API is used:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdModuleName: 'myLib',\n },\n});\n\n\nThe construction products at this point are:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports);\n else if (typeof define === 'function' && define.amd)\n define(['exports'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.myLib = {}));\n})(this, function (exports) {\n //...\n});\n","frontmatter":{"sidebar_position":5}},{"id":9,"title":"Use the Copy Tools","routePath":"/module-tools/en/guide/advance/copy","toc":[{"id":"understanding-the-copy-api-1","text":"Understanding the Copy API","depth":2},{"id":"api-description-1","text":"API Description","depth":2},{"id":"不同场景使用示例-2","text":"不同场景使用示例","depth":2},{"id":"将文件复制文件-2","text":"将文件复制文件","depth":3},{"id":"将文件复制到目录-2","text":"将文件复制到目录","depth":3},{"id":"从目录复制到目录-2","text":"从目录复制到目录","depth":3},{"id":"从目录到文件-2","text":"从目录到文件","depth":3},{"id":"使用-glob-2","text":"使用 Glob","depth":3}],"content":"USE THE COPY TOOLS\n\nThe Module Project provides the Copy utility for copying already existing\nindividual files or entire directories into the product directory. Next we learn\nhow to use it.\n\n\nUNDERSTANDING THE COPY API\n\nWe can use the Copy tool via the buildConfig.copy API, which contains the\nfollowing two main configurations.\n\n * patterns\n * options\n\nIt is recommended to spend some time getting to know them before you start\nlearning.\n\n\nAPI DESCRIPTION\n\ncopy.patterns 用于寻找复制的文件以及配置输出的路径。\n\n其中 patterns.from 用于指定要复制的文件或者目录。它接收 Glob 形式字符串或具体路径。Glob 形式字符串是指 fast-glob\npattern-syntax。因此我们可以按照如下两种方式使用它:\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n { from: './index.html', to: '' },\n { from: './*.html', to: '' },\n ],\n },\n },\n});\n\n\npatterns.context 一般和 patterns.from 配合使用,默认情况下它的值与 buildConfig.sourceDir\n相同,因此我们可以按照如下方式指定 src/data.json 文件为要复制的文件:\n\n> 默认情况下,buildConfig.sourceDir 为 src\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n { from: './data.json' to: ''},\n ],\n },\n },\n});\n\n\n当指定的文件不在源码目录的时候,可以修改 context 配置。例如指定项目目录下的 temp/index.html 为要复制的文件:\n\n\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n {\n from: './index.html',\n context: path.join(__dirname, './temp')\n to: '',\n }\n ],\n },\n },\n});\n\n\npatterns.to 用于指定复制文件的输出路径,默认情况下它的值为 buildConfig.outDir对应的值。因此我们按照如下方式将\nsrc/index.html 复制到 dist 目录下:\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [{ from: './index.html' }],\n },\n },\n});\n\n\n当我们配置了 patterns.to 的时候:\n\n * 如果是相对路径,则该路径会相对于 buildConfig.outDir 计算出复制文件输出的绝对路径。\n * 如果是绝对路径,则会直接使用该值。\n\n最后 patterns.globOptions 用于配置寻找复制文件 globby 对象,其配置可参考:\n\n * globby.options\n\n\n不同场景使用示例\n\n\n将文件复制文件\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy file to file\n */\n {\n from: './temp-1/a.png',\n context: __dirname,\n to: './temp-1/b.png',\n },\n ],\n },\n },\n ],\n});\n\n\n\n将文件复制到目录\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy file to dir\n */\n {\n from: './temp-2/a.png',\n context: __dirname,\n to: './temp-2',\n },\n ],\n },\n },\n ],\n});\n\n\n\n从目录复制到目录\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy dir to dir\n */\n {\n from: './temp-3/',\n to: './temp-3',\n context: __dirname,\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n\n\n\n从目录到文件\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy dir to file\n */\n {\n from: './temp-4/',\n context: __dirname,\n to: './temp-4/_index.html',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n\n\n\n使用 GLOB\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy glob to dir\n */\n {\n from: './*.html',\n to: './temp-5',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n {\n copy: {\n patterns: [\n /**\n * copy glob to file\n */\n {\n from: './*.html',\n to: './temp-6/index.html',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n","frontmatter":{"sidebar_position":3}},{"id":10,"title":"How to handle third-party dependencies","routePath":"/module-tools/en/guide/advance/external-dependency","toc":[{"id":"default-handling-of-third-party-dependencies-1","text":"Default handling of third-party dependencies","depth":2},{"id":"packaging-third-party-dependencies-1","text":"Packaging third-party dependencies","depth":2},{"id":"turn-off-default-behavior-1","text":"Turn off default behavior","depth":3},{"id":"exclude-specified-third-party-dependencies-1","text":"Exclude specified third-party dependencies","depth":3}],"content":"HOW TO HANDLE THIRD-PARTY DEPENDENCIES\n\nGenerally, third-party dependencies required by a project can be installed via\nthe install command in the package manager. After the third-party dependencies\nare successfully installed, they will generally appear under dependencies and\ndevDependencies in the project package.json.\n\n{\n \"dependencies\": {},\n \"devDependencies\": {}\n}\n\n\nDependencies under \"dependencies\" are generally related to project code and\nbuilds, and if these third-party dependencies are declared under\n\"devDependencies\", then there will be missing dependencies in production\nenvironments.\n\nIn addition to \"dependencies\", \"peerDependencies\" can also declare dependencies\nthat are needed in the production environment, but it puts more emphasis on the\nexistence of these dependencies declared by \"peerDependencies\" in the project's\nruntime environment, similar to the plugin mechanism.\n\n\nDEFAULT HANDLING OF THIRD-PARTY DEPENDENCIES\n\nBy default, third-party dependencies under \"dependencies\" and \"peerDependencies\"\nare not packaged in the module project**, so:\n\n<CH.Spotlight>\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n },\n // or\n \"peerDependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\n--------------------------------------------------------------------------------\n\nIf the project has a dependency on react.\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n },\n // or\n \"peerDependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\n--------------------------------------------------------------------------------\n\nWhen a react dependency is used in the source code.\n\n\nconsole.info(React);\n\n\n--------------------------------------------------------------------------------\n\nThe react code is not packaged into the product at this point.\n\n\nconsole.info(React);\n\n\n</CH.Spotlight>\n\n\nPACKAGING THIRD-PARTY DEPENDENCIES\n\nHowever there are cases where you want to package these third-party dependencies\ninto the product. The benefits of packaging third-party dependencies into the\nproduct are: Reducing the time spent downloading third-party dependencies.\n\nThis way of handling third-party dependencies is generally more common in\ndeveloping command-line tools, which can improve the loading speed of\ncommand-line tools and give users a better experience.\n\nSo how do you enable the packaging of third-party dependencies in your module\nproject?\n\nThe following APIs are provided in the build configuration to handle third-party\ndependencies:\n\n * buildConfig.autoExternal\n * buildConfig.externals\n\n\nTURN OFF DEFAULT BEHAVIOR\n\nWhen we want to turn off the default handling behavior for third-party\ndependencies, we can do so by:\n\nexport default defineConfig({\n buildConfig: {\n autoExternal: false,\n },\n});\n\n\nThis way the dependencies under \"dependencies\" and \"peerDependencies\" will be\npackaged. If you want to turn off the processing of only one of these\ndependencies, you can use the buildConfig.autoExternal in the form of an object.\n\nexport default defineConfig({\n buildConfig: {\n autoExternal: {\n dependencies: false,\n peerDependencies: false,\n },\n },\n});\n\n\n\nEXCLUDE SPECIFIED THIRD-PARTY DEPENDENCIES\n\nAnd in addition to the buildConfig.autoExternal API, buildConfig.externals can\nalso control which third-party dependencies are to be handled. We can combine\nthese two APIs to handle the project's dependencies in a more granular way.\n\nFor example, when we need to leave only certain dependencies unpacked, we can\nconfigure it as follows.\n\n> In this case, it is likely that some dependencies are not suitable for\n> packaging. If this is the case, then you can handle it as follows.\n\nepxort default defineConfig({\n buildConfig: {\n autoExternal: false,\n externals: ['pkg-1', /pkg-2/],\n }\n});\n","frontmatter":{"sidebar_position":4}},{"id":11,"title":"In-depth understanding of build","routePath":"/module-tools/en/guide/advance/in-depth-about-build","toc":[{"id":"in-depth-understanding-of-buildconfig-1","text":"In-depth understanding of buildConfig","depth":2},{"id":"bundle-and-bundleless-1","text":"Bundle and Bundleless","depth":3},{"id":"relationship-between-input-and-sourcedir-1","text":"Relationship between input and sourceDir","depth":3},{"id":"object-type-of-input-1","text":"Object type of input","depth":4},{"id":"sourcedir-5","text":"sourceDir","depth":4},{"id":"declaration-type-files-1","text":"Declaration Type Files","depth":3},{"id":"turn-off-type-generation-1","text":"Turn off type generation","depth":4},{"id":"build-type-files-1","text":"Build type files","depth":4},{"id":"alias-conversion-1","text":"Alias Conversion","depth":4},{"id":"some-examples-of-the-use-of-dts-1","text":"Some examples of the use of dts","depth":4},{"id":"buildconfigdefine-usage-for-different-scenarios-1","text":"buildConfig.define Usage for different scenarios","depth":3},{"id":"environment-variable-replacement-1","text":"Environment variable replacement","depth":4},{"id":"global-variable-replacement-1","text":"Global variable replacement","depth":4},{"id":"build-process-1","text":"Build process","depth":2},{"id":"build-errors-1","text":"Build errors","depth":2}],"content":"IN-DEPTH UNDERSTANDING OF BUILD\n\nIn the [Basic Usage] section, we already knew that you can modify the output\nproduct of a project through the buildConfig configuration. buildConfig not only\ndescribes some of the features of the product, but also provides some\nfunctionality for building the product.\n\nIf you are not sure what buildConfig is, it is recommended to take some time to\nunderstand it by following this link.\n\n * [modify-output-product]\n\nIn this chapter we'll dive into the use of certain build configurations and\nunderstand what happens when the modern build command is executed.\n\n\nIN-DEPTH UNDERSTANDING OF BUILDCONFIG\n\n\nBUNDLE AND BUNDLELESS\n\nSo first let's understand Bundle and Bundleless.\n\nA Bundle is a package of build products, which may be a single file or multiple\nfiles based on a certain code splitting strategy.\n\nBundleless, on the other hand, means that each source file is compiled and built\nseparately, but not packaged together. Each product file can be found with its\ncorresponding source code file. The process of Bundleless build can also be\nunderstood as the process of code conversion of source files only.\n\nIn buildConfig you can specify whether the current build task is Bundle or\nBundleless by using buildConfig.buildType.\n\n\nRELATIONSHIP BETWEEN INPUT AND SOURCEDIR\n\nbuildConfig.input is used to specify the file path or directory path where the\nsource code is read, and its default value differs between Bundle and Bundleless\nbuilds.\n\n * When buildType: 'bundle', input defaults to ['src/index.ts']\n * When buildType: 'bundleless', input defaults to ['src']\n \n > In fact, at buildType: 'bundle', the build tool detects the existence of a\n > file matching the name rule src/index.(j|t)sx? and uses it as an entry\n > file.\n\nIt is recommended that you do not specify multiple source file directories\nduring a Bundleless build, as unintended results may occur. Bundleless builds\nwith multiple source directories are currently in an unstable stage.\n\nWe know from the defaults: Bundle builds can generally specify a file path as\nthe entry point to the build, while Bundleless builds are more expected to use\ndirectory paths to find source files.\n\nOBJECT TYPE OF INPUT\n\nIn addition to setting input to an array, you can also set it to an object\nduring the Bundle build process. By using the object form, we can modify the\nname of the file that the build product outputs. So for the following example, .\n/src/index.ts corresponds to the path of the build product file as .\n/dist/main.js.\n\n\n\nexport default defineConfig({\n buildConfig: {\n input: {\n main: ['./src/index.ts'],\n },\n outDir: './dist',\n },\n});\n\n\nThe Bundleless build process also supports such use, but it is not recommended.\n\nSOURCEDIR\n\nsourceDir is used to specify the source code directory, which is related to\nboth.\n\n * type file generation\n * outbase for specifying the build process\n\nIn general:\n\n * During the Bundleless build process, the values of sourceDir and input should\n be the same, and their default values are both src.\n * It is rarely necessary to use sourceDir during the Bundle build process.\n\n\nDECLARATION TYPE FILES\n\nThe buildConfig.dts configuration is mainly used for type file generation.\n\nTURN OFF TYPE GENERATION\n\nType generation is turned on by default, if you need to turn it off, you can\nconfigure it as follows:\n\n\n\nexport default defineConfig({\n buildConfig: {\n dts: false,\n },\n});\n\n\nThe build speed is generally improved by closing the type file.\n\nBUILD TYPE FILES\n\nWith buildType: 'bundleless', type files are generated using the project's tsc\ncommand to complete production.\n\nThe module engineering solution also supports packaging of type files, although\ncare needs to be taken when using this feature.\n\n * Some third-party dependencies have incorrect syntax that can cause the\n packaging process to fail. So in this case, you need to exclude such\n third-party packages manually with buildConfig.externals.\n * It is not possible to handle the case where the type file of a third-party\n dependency points to a .ts file. For example, the package.json of a\n third-party dependency contains something like this: {\"types\": \".\n /src/index.ts\"}.\n\nALIAS CONVERSION\n\nDuring the Bundleless build process, if an alias appears in the source code,\ne.g.\n\n\n\nNormally, product type files generated with tsc will also contain these aliases.\nHowever, Module Tools will convert the aliases in the type file generated by tsc\nto:\n\n * Alias conversion is possible for code of the form ``.\n * Aliasing is possible for code of the form export { utils } from\n '@common/utils'.\n\nHowever, there are some cases that cannot be handled at this time.\n\n * Output types of the form Promise<import('@common/utils')> cannot be converted\n at this time.\n\nSOME EXAMPLES OF THE USE OF DTS\n\nGeneral usage:\n\n\n\nexport default defineConfig({\n // The output path of the packaged type file at this point is `./dist/types`\n buildConfig: {\n buildType: 'bundle',\n dts: {\n tsconfigPath: './other-tsconfig.json',\n distPath: './types',\n },\n outDir: './dist',\n },\n});\n\n\nFor the use of dts.only:\n\n\n\nexport default defineConfig({\n // At this moment the type file is not packaged and the output path is `./dist/types`\n buildConfig: [\n {\n buildType: 'bundle',\n dts: false,\n outDir: './dist',\n },\n {\n buildType: 'bundleless',\n dts: {\n only: true,\n },\n outDir: './dist/types',\n },\n ],\n});\n\n\n\nBUILDCONFIG.DEFINE USAGE FOR DIFFERENT SCENARIOS\n\nbuildConfig.define functions somewhat similar to webpack.DefinePlugin. A few\nusage scenarios are described here.\n\nENVIRONMENT VARIABLE REPLACEMENT\n\n\nexport default defineConfig({\n buildConfig: {\n define: {\n 'process.env.VERSION': JSON.stringify(process.env.VERSION || '0.0.0'),\n },\n },\n});\n\n\nWith the above configuration, we can put the following code.\n\n// pre-compiler code\nconsole.log(process.env.VERSION);\n\n\nWhen executing VERSION=1.0.0 modern build, the conversion is:\n\n// compiled code\nconsole.log('1.0.0');\n\n\nGLOBAL VARIABLE REPLACEMENT\n\n\nexport default defineConfig({\n buildConfig: {\n define: {\n VERSION: JSON.stringify(require('. /package.json').version || '0.0.0'),\n },\n },\n});\n\n\nWith the above configuration, we can put the following code.\n\n// pre-compile code\nconsole.log(VERSION);\n\n\nConvert to:\n\n// post-compile code\nconsole.log('1.0.0');\n\n\nNote, however: If the project is a TypeScript project, then you may need to add\nthe following to the .d.ts file in the project source directory.\n\n> If the .d.ts file does not exist, then you can create it manually.\n\ndeclare const YOUR_ADD_GLOBAL_VAR;\n\n\n\nBUILD PROCESS\n\nWhen the modern build command is executed, the\n\n * Clear the products directory according to buildConfig.outDir.\n * Compile js/ts source code to generate the JS build product for\n Bundle/Bundleless.\n * Generate Bundle/Bundleless type files using tsc.\n * Handle Copy tasks.\n\n\nBUILD ERRORS\n\nWhen a build error occurs, based on the information learned above, it is easy to\nunderstand what error appears in the terminal.\n\nErrors reported for js or ts builds:\n\nerror ModuleBuildError:\n\n╭───────────────────────╮\n│ bundle failed: │\n│ - format is \"cjs\" │\n│ - target is \"esnext\" │\n╰───────────────────────╯\n\nDetailed Information:\n\n\nErrors reported for the type file generation process:\n\nerror ModuleBuildError:\n\nbundle DTS failed:\n\n\nFor js/ts build errors, we can tell from the error message.\n\n * By 'bundle failed:' to determine if the error is reported for a Bundle build\n or a Bundleless build?\n * What is the format of the build process?\n * What is the target of the build process?\n * The specific error message.","frontmatter":{"sidebar_position":1}},{"id":12,"title":"深入理解 dev 命令","routePath":"/module-tools/en/guide/advance/in-depth-about-dev-command","toc":[{"id":"深入理解-buildconfig-3","text":"深入理解 buildConfig","depth":2},{"id":"bundle-和-bundleless-3","text":"bundle 和 bundleless","depth":3},{"id":"input-与-sourcedir-的关系-3","text":"input 与 sourceDir 的关系","depth":3},{"id":"构建过程-3","text":"构建过程","depth":2}],"content":"深入理解 DEV 命令\n\n在【基础使用】的部分,我们已经知道可以通过 buildConfig 配置对项目的输出产物进行修改。buildConfig\n不仅描述了产物的一些特性,同时还为构建产物提供了一些功能。\n\n如果你还不清楚 buildConfig 是什么,建议花一些时间通过下面的链接了解一下:\n\n * 【修改输出产物】\n\n而在本章里我们将要深入理解某些构建配置的使用以及了解执行 modern build 命令的时候发生了什么。\n\n\n深入理解 BUILDCONFIG\n\n那么首先我们来理解 bundle 和 bundleless 的构建模式。\n\n\nBUNDLE 和 BUNDLELESS\n\n\nINPUT 与 SOURCEDIR 的关系\n\n\n构建过程","frontmatter":{"sidebar_position":2}},{"id":13,"title":"Theme Configuration","routePath":"/module-tools/en/guide/advance/theme-config","toc":[{"id":"motivation-and-rationale-1","text":"Motivation and rationale","depth":2},{"id":"usage-examples-1","text":"Usage examples","depth":2},{"id":"tailwindcss-5","text":"tailwindcss","depth":3},{"id":"html-class-2","text":"HTML Class","depth":4},{"id":"apply-directives-1","text":"@apply Directives","depth":4}],"content":"THEME CONFIGURATION\n\nThe module project provides the ability to configure themes through the\ndesignSystem API.\n\n\nMOTIVATION AND RATIONALE\n\nTheme configuration is somewhat similar to the custom theme functionality in the\ncomponent library and is mainly used in style development. We can use the\ndesignToken generated by the designSystem configuration in different style\ndevelopment environments.\n\nThe so-called designToken corresponds to different things in different style\ndevelopment environments.\n\n * tailwindcss: use designSystem as the theme configuration for tailwindcss. So\n you can use.\n * The name of the HTML class supported by tailwindcss.\n * @apply custom directive under css/less/sass to use a string with the same\n name as the HTML class name supported by tailwindcss.\n * css/less/scss: Generate global style variables via designSystem.\n\nThe data structure of the designSystem API is borrowed from the theme API in the\ntailwindcss configuration object, so a default set of designToken exists. For\nthe default values, see the designSystem API.\n\nThe css/less/sass global variables are not supported yet.\n\n\nUSAGE EXAMPLES\n\n\nTAILWINDCSS\n\nWhen using tailwindcss, its theme configuration can be set via designSystem.\n\nFor example, the following configuration extends the original color\nconfiguration:\n\nexport default {\n designSystem: {\n extend: {\n colors: {\n primary: '#1677ff',\n },\n },\n },\n};\n\n\nWe can have two ways of using tailwindcss in our code.\n\nHTML CLASS\n\nimport 'tailwindcss/utilities.css';\n\nexport default () => {\n return <div className=\"bg-primary\"></div>;\n};\n\n\n@APPLY DIRECTIVES\n\nAbout @apply。\n\n<CH.Code>\n\nimport './index.css';\n\nexport default () => {\n return <div className=\"btn-primary\"></div>;\n};\n\n\n.btn-primary {\n @apply bg-primary;\n}\n\n\n</CH.Code>","frontmatter":{"sidebar_position":7}},{"id":14,"title":"Before you start","routePath":"/module-tools/en/guide/basic/before-getting-started","toc":[{"id":"environment-preparation-1","text":"Environment preparation","depth":2},{"id":"getting-started-with-npm-1","text":"Getting Started with npm","depth":2},{"id":"npm-package-type-project-1","text":"npm package type project","depth":2},{"id":"using-third-party-npm-packages-1","text":"Using third-party npm packages","depth":2},{"id":"other-npm-bits-and-pieces-to-know-1","text":"Other npm bits and pieces to know","depth":2},{"id":"program-entry-for-npm-packages-1","text":"Program entry for npm packages","depth":3},{"id":"scripts-2","text":"\"scripts\"","depth":3},{"id":"npm-install-2","text":"npm install","depth":4},{"id":"npm-publish-2","text":"npm publish","depth":4},{"id":"peerdependencies-5","text":"peerDependencies","depth":3},{"id":"npm-package-manager-1","text":"npm package manager","depth":2},{"id":"module-tools-configuration-file-1","text":"Module Tools configuration file","depth":2}],"content":"BEFORE YOU START\n\n\nENVIRONMENT PREPARATION\n\nIn order to use the Modern.js module engineering solution, you first need NodeJS\nengine, we recommend the latest LTS version, and make sure the Node version is\n>=14.18.0. because non-stable NodeJS releases frequently have bugs. You might\nconsider installing via nvm-windows and nvm (Mac/linux), so you can easily\nswitch to different NodeJS versions that might be required for different\nprojects that you work on.\n\n\nGETTING STARTED WITH NPM\n\nOnce NodeJS is installed, not only can you access the node executable from the\ncommand line, but you can also execute the npm command.\n\nNpm is the standard package manager for NodeJS. It started out as a tool for\ndownloading and managing NodeJS package dependencies, but it has since evolved\ninto a tool for front-end JavaScript.\n\nIf you already know something about usage of npm and npm packages, then you can\ndirectly see npm package manager section.\n\n\nNPM PACKAGE TYPE PROJECT\n\nSo what is an npm package type project? When we execute the npm init command in\nan empty project directory, it creates a JSON file with the file name\npackage.json under the current directory. During the creation process, we will\nneed to fill in information including but not limited to the name, version\nnumber, description, etc. of the npm package, which will be found in the\nresulting package.json file as follows\n\n{\n \"name\": \"npm-demo\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"index.js\",\n \"scripts\": {\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n },\n \"author\": \"\",\n \"license\": \"ISC\"\n}\n\n\nAt this point the project containing the initialized package.json file is an npm\npackage type project, and you can execute the npm publish command to publish the\nproject to the npm Registry.\n\nThe npm Registry is a npm package store where developers can not only publish\ntheir own npm packages to the npm Registry, but also use npm packages published\nby other developers through the npm Registry.\n\nA quality npm package will be used by more people because it not only saves a\nlot of code implementation work, but is also less likely to cause problems with\nthe project.\n\n\nUSING THIRD-PARTY NPM PACKAGES\n\nWhen adding a third-party npm package to an initial project, we can call this\nprocess \"installing dependencies for the project\" or \"adding dependencies to the\nproject\". Before adding dependencies, we need to know one thing in particular --\nthe types of packages npm depends on.\n\n * \"dependencies\": a type of package that your application will need in a\n production environment.\n * \"devDependencies\": another type of package that is only needed for local\n development and testing.\n \n > packages can be understood as third-party npm packages.\n\nYou can install the packages you need in a production environment by running npm\ninstall npm-package-name or npm add npm-package-name, or you can manually write\nthe packages you need to install and the corresponding semantic version in\n\"dependencies\" in the package.json file, and run the npm install command to.\n\n{\n \"name\": \"your-npm-project\",\n \"dependencies\": {\n \"npm-package-name\": \"0.1.0\"\n }\n}\n\n\nSimilarly, you can install only packages needed for local development and\ntesting by running npm install npm-package-name --save-dev or npm add\nnpm-package-name --save-dev, or you can manually write the packages to be\ninstalled and the corresponding semantic version in \"devDependencies\" in the\npackage.json file, and run the npm install command as follows\n\n{\n \"name\": \"your-npm-project\",\n \"devDependencies\": {\n \"npm-package-name\": \"0.1.0\"\n }\n}\n\n\nWhen installing or using third-party npm packages be sure to determine what they\nare for and whether they should be placed in \"dependencies\" or \"devDependencies\"\nby distinguishing between their types.\n\nIn general, packages that need to be used in source code are dependencies\ndependencies. Unless you are exporting dependent code locally via packaging, in\nwhich case it can be treated as a devDependencies dependency.\n\n\nOTHER NPM BITS AND PIECES TO KNOW\n\n\nPROGRAM ENTRY FOR NPM PACKAGES\n\nThere is a \"main\" attribute in package.json that corresponds to a module ID or,\nmore intuitively, a NodeJS file path, which is the main entry point for your\napplication.\n\nFor example, if your package is named foo and the user installs it, and then\nexecutes the require(\"foo\") code, then the file corresponding to the \"main\"\nfield of the npm package foo will be exported.\n\nIt is recommended to set the \"main\" field in your npm package. If \"main\" is not\nset, the default entry will be the index.js file in the root of the package.\n\nIn addition to the \"main\" attribute, the \"module\" attribute is usually set. It\nis similar to the \"main\" attribute in that it is mainly used in webpack\nscenarios. webpack reads the npm package entry (file) in most cases in the order\n\"module\" -> \"main \".\n\n> To learn more about how webpack does this, check out this link.\n\n\n\"SCRIPTS\"\n\nThe \"scripts\" attribute of the package.json file supports a number of built-in\nscripts and npm-preset lifecycle events, as well as arbitrary scripts.\n\nThese can be executed by running npm run-script <stage> or simply npm run\n<stage>.\n\nName matching pre and post commands will also be run (e.g. premyscript,\nmyscript, postmyscript ).\n\n{\n \"scripts\": {\n \"premyscript\": \"\",\n \"myscript\": \"\",\n \"postmyscript\": \"\"\n }\n}\n\n\nWhen npm run myscripts is executed, the script corresponding to premyscripts\nwill be executed before it, and the script corresponding to postmyscripts will\nbe executed after it.\n\nScript commands from dependencies can be run with npm explore <pkg> -- npm run\n<stage>.\n\nThere are also special lifecycle scripts that occur only under certain\ncircumstances. Here are a few that are usually necessary to know.\n\nNPM INSTALL\n\nWhen you run npm install -g <pkg-name>, the following scripts will run.\n\n * preinstall\n * install\n * postinstall\n * prepublish\n * preprepare\n * prepare\n * postprepare\n\nIf your package root has a binding.gyp file and you don't define an install or\npreinstall script, then npm will build with node-gyp rebuild as the default\ninstall command, using node-gyp.\n\nNPM PUBLISH\n\nWhen publishing a project, executing this command will trigger the following\nscript.\n\n * prepublishOnly\n * prepack\n * prepare\n * postpack\n * publish\n * postpublish\n\nWhen running in -dry-run mode, the script corresponding to prepare will not be\nexecuted.\n\n\nPEERDEPENDENCIES\n\nIn some cases, your npm project has a compatibility relationship with its host\ntool or library (e.g. a webpack plugin project and webpack), and your npm\nproject does not want to use the host as a necessary dependency, which usually\nmeans that your project is probably a plugin for that host tool or library. Your\nnpm project will have certain requirements for the version of the host package,\nas only the APIs required by the npm project will be exposed under a specific\nversion.\n\nFor more explanation of peerDependencies, you can learn about the different ways\nnpm, pnpm, and Yarn handle it at the following links.\n\n * npm's explanation of peerDependencies\n * pnpm vs npm vs Yarn\n\n\nNPM PACKAGE MANAGER\n\nIn addition to the standard package manager like npm, the mainstream ones are\npnpm and Yarn, both of which are good alternatives to npm cli.\n\nIt is recommended to use pnpm to manage project dependencies, which can be\ninstalled as follows.\n\nnpm install -g pnpm\n\n\n\nMODULE TOOLS CONFIGURATION FILE\n\nThe Module Tools configuration file - modern.config.(j|t)s - is provided in the\nproject directory of the module project created with @modern-js/create. However,\nthe modern.config configuration file is not required to exist.\n\nBy default, the contents of the generated configuration file are as follows.\n\n// modern.config.ts\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n});\n\n\n// modern.config.js\n\n\nexport default {\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n};\n\n\nWe recommend using the defineConfig function, but it is not mandatory to use it.\nSo you can also return an object directly in the config file: the\n\n// modern.config.ts\nexport default {};\n\n\n// modern.config.js\nexport default {};\n","frontmatter":{"sidebar_position":1}},{"id":15,"title":"Command Preview","routePath":"/module-tools/en/guide/basic/command-preview","toc":[{"id":"modern-build-2","text":"modern build","depth":2},{"id":"modern-new-2","text":"modern new","depth":2},{"id":"modern-dev-2","text":"modern dev","depth":2},{"id":"modern-test-2","text":"modern test","depth":2},{"id":"modern-lint-2","text":"modern lint","depth":2},{"id":"-modern-change-1","text":"-modern change","depth":2},{"id":"modern-pre-2","text":"modern pre","depth":2},{"id":"modern-bump-2","text":"modern bump","depth":2},{"id":"modern-release-2","text":"modern release","depth":2},{"id":"modern-gen-release-note-2","text":"modern gen-release-note","depth":2},{"id":"modern-upgrade-2","text":"modern upgrade","depth":2}],"content":"COMMAND PREVIEW\n\nCommands available for module engineering projects.\n\n\nMODERN BUILD\n\nUsage: modern build [options]\n\nBuild module command\n\nOptions:\n -w, --watch Build code in listening mode\n --tsconfig [tsconfig] Specify the path to the tsconfig.json file (default:\n \". /tsconfig.json\")\n --platform [platform] Build products for all or specified platforms\n --no-dts disables DTS type file generation and type checking\n --no-clear disables automatic clearing of product output directories\n -h, --help Show information about the current command\n\n\nWhen you want to start a project build, you can execute the modern build\ncommand. When using this command, we can:\n\n * When wanting to start a build in watch mode, use the --watch option.\n * When you want to specify the path to the TypeScript configuration file read\n by the project build, use -build --tsconfig . /path/config.json option. This\n option overrides all buildConfig configurations in dts.tsconfigPath.\n * The -no-dts option can be used when the DTS type file generation and type\n checking behavior of the project needs to be turned off. Note: The generation\n of type files depends on the results of type checking. If type checking is\n turned off, then type files will not be generated either.\n * The --no-clear option can be used when the automatic clearing of the product\n output directory needs to be turned off.\n\nIn addition to the above, module projects also support platform build mode,\nwhich can be used to perform build tasks for other tools. For example, it is\ncurrently officially supported to start a Storybook build task to generate\nStorybook products by executing the modern build --platform or modern build\n--platform storybook commands after installing the @modern-js/plugin-storybook\nplugin.\n\nWhen executing a Storybook build, it needs to read the project's build product.\nSo when running the modern build --platform command to start a Storybook build,\nrun modern build once to ensure that the source build product exists.\n\n\nMODERN NEW\n\nUsage: modern new [options]\n\nExecute the generator in a modular project scenario\n\nOptions:\n -d, --debug Enable Debug mode, print debug log messages (default: false)\n -c, --config <config> Generators run default configuration (JSON string)\n --dist-tag <tag> Generator uses a special version of npm Tag\n --registry customize npm Registry during generator runtime\n -h, --help display help for command\n\n\nThe modern new command is used to start the microgenerator functionality, which\nenables features for the project that are not provided by default.\n\nThe following features can currently be enabled.\n\n * Testing support\n * Storybook debugging\n * Tailwind CSS support\n * Modern.js Runtime API\n\nYou can learn more about these features in the Using the micro generator\nsection.\n\n\nMODERN DEV\n\nUsage: modern dev [options]\n\nLocal development commands\n\nOptions:\n -h, --help display help for command\n\nCommands:\n[dev-tools-subCommand]\n\n\nThe module engineering solution provides the ability to use debugging tools,\nwhich can be started with the modern dev command. Note, however, that no\ndebugging-related plugins are provided by default, so executing modern dev will\nprompt: \"No dev tools found available \".\n\nThe officially supported debugging tool is Storybook, so you can run modern dev\nor modern dev storybook to execute it after you run modern new to enable it.\n\n\nMODERN TEST\n\nUsage: modern test [options]\n\nOptions:\n -h, --help display help for command\n\n\nYou need to execute modern new to turn on the test function before you can\nexecute the modern test command. The modern test command will automatically run\nthe src/tests/*.test.(js|ts|jsx|tsx) file as a test case.\n\n\nMODERN LINT\n\nUsage: modern lint [options] [. .files]\n\nlint and fix source files\n\nOptions:\n --no-fix disable auto fix source file\n -h, --help display help for command\n\n\nRun ESLint to check the syntax of the code. Usually, we only need to check the\npart of the code that was changed in this commit with lint-staged during the\n-git commit phase.\n\n * The -no-fix argument turns off the ability to automatically fix lint error\n code.\n\n\n-MODERN CHANGE\n\nUsage: modern change [options]\n\nCreate a changeset\n\nOptions:\n --empty Create an empty changeset (default: false)\n --open Open the created changeset in the editor (default: false)\n -h, --help display help for command\n\n\nThe modern change command is used to generate the required Markdown file for\nchangesets.\n\n\nMODERN PRE\n\nUsage: modern pre [options] <enter|exit> [tag]\n\nEntering and exiting pre-publishing mode\n\nOptions:\n -h, --help display help for command\n\n\nYou can use the modern pre command to pre-release a version before the official\nrelease.\n\n\nMODERN BUMP\n\nUsage: modern bump [options]\n\nUse changesets to automatically update releases and changelogs\n\nOptions:\n --canary Create a pre-release for testing (default: false)\n --preid <tag> Specify an identifier when versioning a pre-release (default: \"next\")\n --snapshot Create a special version for testing (default: false)\n -h, --help display help for command\n\n\nModify the version number in package.json according to the Markdown file of the\nchangelog generated by changesets, and generate the CHANGELOG.md file.\n\n\nMODERN RELEASE\n\nUsage: modern release [options]\n\nRelease npm packages\n\nOptions:\n --tag <tag> Release npm packages with a specific tag (default: \"\")\n --ignore-scripts release ignores the scripts command in package.json, only supported in pnpm monorepo\n (default: \"\")\n -h, --help display help for command\n\n\nThe -modern release command releases the module to the npm Registry.\n\n * The -tag argument specifies the specific dist tags to be used for the\n release.\n\n\nMODERN GEN-RELEASE-NOTE\n\nUsage: modern gen-release-note [options]\n\nGenerate Release Note based on current repository changeset information\n\nOptions:\n --repo <repo> The name of the repository to generate the Pull Request link, e.g.: modern-js-dev/modern.js\n --custom <cumtom> Custom Release Note generation function\n -h, --help display help for command\n\n\nAutomatically generate Release Note based on the changeset information of the\ncurrent repository.\n\nneeds to be executed before the bump command.\n\n\nMODERN UPGRADE\n\nUsage: modern upgrade [options]\n\nUpgrade Modern.js to the latest version\n\nOptions:\n --registry <registry> customize npm registry (default: \"\")\n -d,--debug Enable Debug mode to print debug log messages (default: false)\n --cwd <cwd> project path (default: \"\")\n -h, --help display help for command\n\n\nThe modern upgrade command is used to upgrade the project Modern.js related\ndependencies to the latest version.\n\nExecuting the command npx modern upgrade in the project root directory will\nupdate the Modern.js dependencies in package.json of the currently executing\nproject to the latest version by default.","frontmatter":{"sidebar_position":2}},{"id":16,"title":"modify-output-product","routePath":"/module-tools/en/guide/basic/modify-output-product","toc":[{"id":"modify-the-output-product-1","text":"Modify the output product","depth":2},{"id":"default-output-products-1","text":"Default output products","depth":2},{"id":"buildpreset-1","text":"buildPreset","depth":2},{"id":"string-form-of-build-preset-1","text":"String form of build preset","depth":3},{"id":"build-pre-defined-function-forms-1","text":"Build pre-defined function forms","depth":3},{"id":"build-configuration-object-1","text":"Build configuration (object)","depth":2},{"id":"when-to-use-buildconfig-1","text":"When to use buildConfig","depth":2}],"content":"MODIFY-OUTPUT-PRODUCT\n\n\nMODIFY THE OUTPUT PRODUCT\n\n\nDEFAULT OUTPUT PRODUCTS\n\nWhen the modern build command is used in an initialized project, the products\nare generated according to the default configuration supported by Module Tools.\nThe default supported configurations are specified as follows.\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n});\n\n\nThe default generation product has the following characteristics.\n\n * will generate CommonJS and [ESM](https://nodejs.org/api/esm.html#modules-\n ecmascript-modules).\n * The code syntax is supported up to ES6 , and more advanced syntax will be\n converted.\n * All code is packaged into one file, i.e. bundle processing is performed.\n * The output root directory is the dist directory under the project, and the\n type file output directory is dist/types.\n\nYou may have the following questions when you see this.\n\n 1. what is buildPreset?\n 2. what determines these characteristics of the product?\n\nThen the next step is to first explain buildPreset.\n\n\nBUILDPRESET\n\nThe buildPreset represents one or more sets of build-related configurations\nprepared in advance. By using the corresponding preset values of the\nbuildPreset, you can eliminate the troublesome and complicated configuration\nwork and get the expected product.\n\n\nSTRING FORM OF BUILD PRESET\n\nThe value of a build preset can be in the form of a string, so a build preset of\nthis form is called a preset string.\n\nThe module engineering solution provides generic build preset strings and\ncorresponding variants, depending on the generic scenario in which the npm\npackage is used. All currently supported preset strings can be viewed via the\nBuildPreset API. Here is an explanation about the relationship between generic\npreset strings and variants.\n\nAmong the generic preset strings, \"npm-library\" can be used in the scenario of\ndeveloping npm packages of the library type, which is suitable for most common\nmodule type projects. When \"npm-library\" is set, the output product of the\nproject will have the following characteristics.\n\n * In the dist/lib directory you will get code formatted as cjs, syntax\n supported up to es6 and packaged.\n * In the dist/es directory, you get code in the format esm, with syntax support\n up to es6 and after packaging.\n * In the dist/types directory, you get the type files. If it is not a\n TypeScript project, there is no such directory.\n\nThe default string \"npm-library\" is a variant of the original product with a\nmodified code syntax support feature and a string naming change to\n\"npm-library-[es5 | es2016.... . es2020 | esnext]\".\n\nFor example, if the output product is based on the preset string \"npm-library\"\nand the syntax supported by the product code is changed to es5, then simply\nchanging \"npm-library\" to \"npm-library-es5\" would be sufficient.\n\n\nBUILD PRE-DEFINED FUNCTION FORMS\n\nIn addition to the string form, the value of a build preset can also be in the\nform of a function, where the specific configuration corresponding to a preset\nvalue can be printed or modified.\n\nFor example, to achieve the same effect as the preset string ``npm-library-es5\"`\nusing the form of a preset function, you can do the following.\n\n\n\nexport default defineConfig({\n buildPreset({ preset }) {\n return preset.NPM_LIBRARY.map(config => {\n return { ... .config, target: 'es5' }\n });\n },\n});\n\n\nIn the above code implementation, preset.NPM_LIBRARY corresponds to the preset\nstring \"npm-library\", which represents the \"npm-library\" equivalent of a\nmulti-group build-related configuration. We traverse the NPM_LIBRARY array,\nwhich contains multiple buildConfig objects, with the map method. We make a\nshallow copy of the original buildConfig object and modify the shallow copy to\nget buildConfig.target, specifying it as es5.\n\n> NPM_LIBRARY, you can check it with [BuildPreset\n> API](/api/config/build-preset). Thepresetobject contains not onlyNPM_LIBRARY`,\n> but also other similar constants.\n\nSo what is the buildConfig object here? What is the basis for the build product\nfeature mentioned before?\n\nLet's explain next.\n\n\nBUILD CONFIGURATION (OBJECT)\n\nbuildConfig is a configuration object that describes how to compile and generate\nbuild products. What was mentioned at the beginning about \"features of build\nproducts\" are actually properties supported by buildConfig. The currently\nsupported properties cover the needs of most module type projects when building\nproducts. buildConfig not only contains some properties that products have, but\nalso contains some features needed to build products. The following is a brief\nlist from a classification point of view.\n\nThe basic attributes of a build product include:\n\n * Whether the product is packaged or not: the corresponding API is\n buildConfig.buildType.\n * Product support for syntax: the corresponding API is buildConfig.target.\n * Output format: the corresponding API is buildConfig.format.\n * How the output type file is handled: the corresponding API is\n buildConfig.dts.\n * How the sourceMap of the product is handled: the corresponding API is\n buildConfig.sourceMap.\n * The input (or source file) corresponding to the output: the corresponding API\n is buildConfig.input.\n * The directory of the output of the product: the corresponding API is\n buildConfig.outDir.\n * Build source directory: the corresponding API is buildConfig.sourceDir.\n\nCommon functions required for build products include:\n\n * Alias: The corresponding API is buildConfig.alias.\n * Static resource handling: the corresponding API is buildConfig.asset.\n * Third-party dependency handling: The corresponding APIs are\n * buildConfig.autoExternal.\n * buildConfig.externals.\n * Copy: The corresponding API is buildConfig.copy.\n * Global variable substitution: the corresponding API is buildConfig.define.\n * Specify JSX compilation method, the corresponding API is\n [buildConfig.jsx](/api/config/ build-config#jsx).\n\nSome advanced properties or less frequently used functions:\n\n * Product code compression: The corresponding API is buildConfig.minify.\n * Code splitting: buildConfig.splitting\n * Specify whether the build product is for the NodeJS environment or the\n browser environment: the corresponding API is buildConfig.platform.\n * umd product-related.\n * Specifies the global variables imported externally to the umd product: the\n corresponding API is buildConfig.umdGlobals.\n * Specify the module name of the umd product: the corresponding API is\n buildConfig.umdModuleName.\n\nIn addition to the above categories, frequently asked questions and best\npractices about these APIs can be found at the following links\n\n * [What are bundle and bundleless?](/guide/advance/in-depth-about-build#bundle-\n and-bundleless)\n * [Relationship of input to\n sourceDir](/guide/advance/in-depth-about-build#input- to -sourcedir-)\n * Multiple ways to generate type files in product.\n * [buildConfig.define Different ways to use it for different\n scenarios.](/guide/advance/in-depth-about-build#buildconfigdefine - How to\n use it for different scenarios)\n * How to handle third-party dependencies?\n * How to use copy?\n * How do I build umd products? (/guide/advance/build-umd# sets the global\n variable name of the project)\n * The capabilities currently supported by static resources.\n\n\nWHEN TO USE BUILDCONFIG\n\nbuildConfig is one of the methods used to modify the product, only buildConfig\nwill take effect when configured in conjunction with buildPreset. So if\nconfigured as follows.\n\n\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n },\n buildPreset: 'npm-library',\n});\n\n\nThen at this point you will see the following prompt.\n\nSince both 'buildConfig' and 'buildPreset' are present, only the 'buildConfig' configuration will take effect\n\n\nThe set or sets of build-related configurations represented by buildPreset are\ncomposed of buildConfig, which can be used to customize output products when the\ncurrent project needs cannot be met using buildPreset.\n\nThe process of using buildConfig is the process of thinking about what kind of\nbuild product to get.","frontmatter":{"sidebar_position":3}},{"id":17,"title":"Versioning and Publishing","routePath":"/module-tools/en/guide/basic/publish-your-project","toc":[{"id":"tracking-changes-1","text":"Tracking changes","depth":2},{"id":"version-update-1","text":"Version update","depth":2},{"id":"publish-1","text":"Publish","depth":2},{"id":"pre-releases-1","text":"Pre-releases","depth":2}],"content":"VERSIONING AND PUBLISHING\n\nAn npm-type module project release process consists of two phases.\n\n * The first phase is during development, where the developer needs to provide a\n change file to record changes that need to be released.\n * The second phase is during release, where Module Tools can collect all the\n change files to update the version, update the release log, and release new\n packages to the npm Registry.\n\n\nTRACKING CHANGES\n\nChanges need to be logged when they happen to the project. Changes that occur in\na project are typically.\n\n * New features\n * Fixes to issues\n * Configuration file changes\n * ...\n\nOnce these changes have been made, the current changes need to be documented\nwith the following command.\n\n * modern change\n\nExecuting the modern change command asks the developer several questions and\ngenerates a change log based on the developer's answers. The changelog file\ncontains the type of change and its description, and is committed to the git\nrepository.\n\n$ npx modern change\n🦋 What kind of change is this for module-example? (current version is 0.1.0) - patch\n🦋 Please enter a summary for this change (this will be in the changelogs). Submit empty line to open external editor\n🦋 Summary - publish test\n🦋 === Releasing the following packages ===\n🦋 [Patch]\n🦋 module\n🦋 Is this your desired changeset? (Y/n) - true\n🦋 Changeset added! - you can now commit it\n🦋\n🦋 If you want to modify or expand on the changeset summary, you can find it here\n🦋 info /xxxxxx/module/.changeset/brave-dryers-agree.md\n\n\nWhen executed successfully, the resulting Markdown file containing the change\nlog is saved in the project's .changeset directory. The contents will look like\nthe following.\n\n---\n\"``module-example'': patch\n---\n\npublish test\n\n\n\nVERSION UPDATE\n\nWhen the project version needs to be updated, execute the following command.\n\n * modern bump\n\nExecuting modern bump will modify the version number in package.json based on\nthe contents of the Markdown file in the .changeset/ directory where the changes\nwere recorded, and generate the CHANGELOG.md file. These Markdown files are also\ndeleted when the version update is complete, so they are \"consumed \".\n\n# module\n\n## 0.1.1\n\n### Patch Changes\n\n- publish test\n\n\n\nPUBLISH\n\nTo publish a project, you can execute the following command.\n\n * modern publish\n\nThe modern release command publishes the project to the npm Registry.\n\nThe release is the latest version, which is also the official version. If you\nwant to change the dist-tag, you can specify it with the modern release --tag\ncommand. For example.\n\nmodern release --tag beta\n\n\nHowever, if you want to change the version number of the current project to a\npre-release as well, you need to use the modern pre command.\n\n> dist-tag can be understood as: tagging the current release. Generally\n> speaking, the dist-tag for the default release is latest, so you can consider\n> latest as the dist-tag for the official release.\n\n\nPRE-RELEASES\n\nWhen a pre-release is needed before the official release, the following command\nis executed.\n\n * modern pre\n\nFirst modern pre enter <tag> to enter pre-release mode, <tag> can be the same as\nthe tag specified with the modern release --tag command when releasing the\nproject.\n\n$ npx modern pre enter next\n🦋 success Entered pre mode with tag next\n🦋 info Run `changeset version` to version packages with prerelease versions\n✨ Done in 5.30s.\nDone in 5.30s. ```\n\nThen 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\n\n``` bash\n$ npx modern bump\n🦋 warn ===============================IMPORTANT!===============================\n🦋 warn You are in prerelease mode\n🦋 warn If you meant to do a normal release you should revert these changes and run `changeset pre exit`\n🦋 warn You can then run `changeset version` again to do a normal release\n🦋 warn ----------------------------------------------------------------------\n🦋 All files have been updated. review them and commit at your leisure\n\n\nThen you can see that the updated version number in package.json will look like\nthis: 0.1.2-next.0.\n\nFinally, if you don't need to do a pre-release anymore, be sure to run the\nmodern pre exit command to exit the pre-release state and to release the\nofficial version when you run the modern bump command again.","frontmatter":{"sidebar_position":7}},{"id":18,"title":"Testing Projects","routePath":"/module-tools/en/guide/basic/test-your-project","toc":[{"id":"prerequisites-and-conventions-1","text":"Prerequisites and conventions","depth":2},{"id":"run-the-tests-1","text":"Run the tests","depth":2},{"id":"usage-configuration-1","text":"Usage Configuration","depth":2},{"id":"test-example-1","text":"Test example","depth":2},{"id":"common-modules-1","text":"Common modules","depth":3},{"id":"components-1","text":"Components","depth":3}],"content":"TESTING PROJECTS\n\nThis chapter will describe how to test modules.\n\n\nPREREQUISITES AND CONVENTIONS\n\nTo use the testing features of the project, you need to make sure that the\nproject contains the dependency: \"@modern-js/plugin-testing\" , which can be done\nwith modern new.\n\nIn the module engineering scheme, the following conventions are in place for\ntest cases, or files for writing tests:\n\n * The tests directory in the project directory is the directory for test cases\n and test files, no support for changing the directory for running test cases.\n * Files with the suffix .test.[tj]sx? are automatically recognized as test\n files by default.\n * Other . [tj]sx? suffixes are recognized as normal files that can be used as\n test utils files or for other purposes.\n\n\nRUN THE TESTS\n\nOnce the dependencies are prepared and we know where to write the test cases, we\ncan execute the tests with the following command:\n\nmodern test\n\n// Update snapshot\nmodern test --updateSnapshot\n\n\nAfter execution, you will see the results of the test:\n\n\n\n\nUSAGE CONFIGURATION\n\nThe Module Engineering Program provides the following configurations for\ntesting.\n\n * testing\n\nYou can add it in modern.config.(j|t)s.\n\n\nTEST EXAMPLE\n\n\nCOMMON MODULES\n\nFor common modules, we can use the test function as follows:\n\n<CH.Spotlight>\n\nexport default function () {\n return 'hello world';\n}\n\n\n--------------------------------------------------------------------------------\n\nFirst is the code of the module.\n\nexport default function () {\n return 'hello world';\n}\n\n\n--------------------------------------------------------------------------------\n\nThen in the test file, we can do this.\n\nWhere @ points to the source directory, defined in tests/tsconfig.json in the\ninitialization project.\n\n\n\ndescribe('default cases', () => {\n test('Have returns', () => {\n const drink = jest.fn(main);\n drink();\n expect(drink).toHaveReturned();\n });\n});\n\n\n--------------------------------------------------------------------------------\n\nFinally we can execute modern test.\n\npnpm test\n## or\nyarn test\n## or\nnpm run test\n\n\n</CH.Spotlight>\n\n\nCOMPONENTS\n\n{/* 链接待补充 */}\n\nFor components, Modern.js's Runtime API provides functionality for testing UI\ncomponents, which is provided by @modern-js/runtime/testing.\n\nIf you need to use the Runtime API, then you can turn it on via microgenerator.\n\n<CH.Spotlight>\n\nexport const default () {\n return (\n <div>This is a UI Component</div>\n );\n}\n\n\n--------------------------------------------------------------------------------\n\nFirst is the code of the component.\n\nexport const default () {\n return (\n <div>This is a UI Component</div>\n );\n}\n\n\n--------------------------------------------------------------------------------\n\nThen in the test file, we can do this.\n\nWhere @ points to the source directory, defined in tests/tsconfig.json in the\ninitialization project.\n\n\n\n\n\ndescribe('default cases', () => {\n test('Rendered', () => {\n render(<Component />);\n expect(screen.getByText('This is a UI Component')).toBeInTheDocument();\n });\n});\n\n\n--------------------------------------------------------------------------------\n\nFinally we can execute modern test.\n\npnpm test\n## or\nyarn test\n## or\nnpm run test\n\n\n</CH.Spotlight>","frontmatter":{"sidebar_position":6}},{"id":19,"title":"Using the Microgenerator","routePath":"/module-tools/en/guide/basic/use-micro-generator","toc":[{"id":"test-1","text":"Test","depth":2},{"id":"storybook-1","text":"Storybook","depth":2},{"id":"tailwind-css-support-1","text":"Tailwind CSS support","depth":2},{"id":"modernjs-runtime-api-1","text":"Modern.js Runtime API","depth":2}],"content":"USING THE MICROGENERATOR\n\nThe Module Engineering solution provides the Microgenerator tool, which allows\nfor the current project to.\n\n * add new directories and files\n * Modify the contents of the package.json file\n * Execute commands\n\nThus with these capabilities, Microgenerator can enable additional feature\nfunctionality for the project.\n\nThe microgenerator can be started via modern new. The current Microgenerator\nfeatures supported by the Module Engineering program are:\n\n\nTEST\n\nWhen we want to test some modules, we can enable the test test feature. When\nthis feature is enabled, a tests directory and related files will be created in\nthe project directory, and a new \"@modern-js/plugin-testing\" dependency will be\nadded to package.json.\n\n\nSTORYBOOK\n\nThe Storybook feature can be enabled when we want to debug a component or a\ncommon module. When this feature is enabled, the stories directory and related\nfiles are created in the project directory, and a new\n\"@modern-js/plugin-storybook\" dependency is added to package.json.\n\nFor more information on how to start Storybook and how to use it, check out the\nfollowing link.\n\n * modern dev\n * using Storybook\n\n\nTAILWIND CSS SUPPORT\n\nThis can be enabled when we want to add Tailwind CSS support to our project.\nTailwind CSS is a CSS library that provides out-of-the-box styling.\n\nFor more information on how to use Tailwind CSS in your module projects, check\nout.\n\n * Using Tailwind CSS\n\n\nMODERN.JS RUNTIME API\n\nModern.js provides Runtime API capabilities that can only be used in the\nModern.js application project environment. If you need to develop a component\nfor use in a Modern.js application environment, then you can turn on this\nfeature and the microgenerator will add the \"@modern-js/runtime\" dependency.\n\nAlso, the Storybook debugging tool will determine if the project needs to use\nthe Runtime API by checking the project's dependencies and providing the same\nRuntime API runtime environment as the Modern.js application project.","frontmatter":{"sidebar_position":4}},{"id":20,"title":"Using Storybook","routePath":"/module-tools/en/guide/basic/using-storybook","toc":[{"id":"debugging-code-1","text":"Debugging code","depth":2},{"id":"referencing-component-products-1","text":"Referencing component products","depth":3},{"id":"referencing-component-source-code-1","text":"Referencing component source code","depth":3},{"id":"configure-storybook-1","text":"Configure Storybook","depth":2},{"id":"building-storybook-products-1","text":"Building Storybook Products","depth":2}],"content":"USING STORYBOOK\n\nFirst of all, if you haven't read the following, take a few minutes to\nunderstand it first.\n\n * use micro-generator to enable Storybook debugging\n * modern dev\n\nStorybook is a tool dedicated to component debugging, providing around component\ndevelopment.\n\n * Develop UIs that are more durable\n * Test UIs with less effort and no flakes\n * Document UI for your team to reuse\n * Share how the UI actually works\n * Automate UI workflows\n\nSo it is a complex and powerful tool.\n\nThe modular engineering solution is integrated with Storybook, so you can pretty\nmuch follow the official Storybook documentation. However, there are still a few\nthings to keep in mind, which are explained below.\n\n\nDEBUGGING CODE\n\nComponent code needs to be introduced during debugging code, and currently\ncomponent code can be introduced in two ways:\n\n * Referencing the component product\n * Referencing component source code\n\nWe recommend the first way of \"referencing component product\". Because it is\nalmost close to the real usage scenario, not only can we debug the component\nfunctionality, but also verify the correctness of the build product.\n\nNext, we will talk about how to use each of these two methods.\n\n\nREFERENCING COMPONENT PRODUCTS\n\nIf the TypeScript project foo exists.\n\n<CH.Spotlight>\n\n{\n \"name\": \"foo\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/types/index.d.ts\"\n}\n\n\n--------------------------------------------------------------------------------\n\nMake sure the main and types of package.json values are real paths.\n\n{\n \"name\": \"foo\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/types/index.d.ts\"\n}\n\n\n--------------------------------------------------------------------------------\n\nThe source code of the foo project.\n\nexport const content = 'hello world';\n\n\n--------------------------------------------------------------------------------\n\nMake sure that the paths configuration pointing to the project root is set in\nstories/tsconfig.json. The key of paths is the same as the project name.\n\n{\n \"extends\": \"../tsconfig.json\",\n \"include\": [\"./\"],\n \"compilerOptions\": {\n \"jsx\": \"preserve\",\n \"baseUrl\": \".\",\n \"paths\": {\n \"foo\": [\"../\"]\n }\n }\n}\n\n\n--------------------------------------------------------------------------------\n\nFinally, it is referenced directly in the Story code by the project name.\n\n\n\nconst Component = () => <div>this is a Story Component {content}</div>;\n\nexport const YourStory = () => <Component />;\n\nexport default {\n title: 'Your Stories',\n};\n\n\n</CH.Spotlight>\n\nIf, during development, you encounter a situation where the type definition is\nnot available in real time, at that point.\n\nFor pnpm projects, package.json can be modified as follows.\n\n{\n \"name\": \"foo\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./src/index.ts\",\n \"publishConfig\": {\n \"types\": \"./dist/index.d.ts\",\n }\n}\n\n\n> For the use of pnpm's publishConfig, you can read the following link.\n\nFor npm and Yarn projects, the values of types of package.json can only be\nchanged manually in development phase and release phase.\n\nSo why is it possible to reference the product directly?\n\n 1. the modern build command is executed automatically before the modern dev\n storybook command, ensuring the existence of the project build product.\n 2. The project name is added as an alias inside Storybook to ensure that the\n path to the project's product can be parsed according to package.json.\n\n\nREFERENCING COMPONENT SOURCE CODE\n\nReferencing component source code can be done by means of relative paths to:\n\n\n\nconst Component = () => <div>this is a Story Component {content}</div>;\n\nexport const YourStory = () => <Component />;\n\nexport default {\n title: 'Your Stories',\n};\n\n\nSo why is the source code approach not recommended?\n\nNot only is it impossible to verify that the component product is correct using\nthe component source code, but also some of the configurations supported by the\nmodule project for building the product cannot be fully translated into\nStorybook internal configuration. If some of the configurations cannot be\nconverted to each other, there will be unintended results during Storybook\ndebugging.\n\n\nCONFIGURE STORYBOOK\n\nStorybook is officially configured for projects through a folder called\n.storybook, which contains various configuration files. In a module project\nscenario, Storybook configuration files can be added to the config/storybook\ndirectory of the project.\n\nFor more information on how to use the various Storybook configuration files,\nsee the following links:\n\n * Configure Storybook\n\nBut there are some limitations to Storybooking in a module project:\n\n * It is currently not possible to change the location of the Story file, i.e.,\n you cannot change the stories configuration in the main.js file.\n * Currently you cannot modify Webpack and Babel related configuration, i.e. you\n cannot modify webpackFinal and babel configuration in the main.js file.\n\nIn the future we will consider whether these configurations can be allowed to be\nmodified, but for now we are limiting their use to reduce unpredictable issues.\n\n\nBUILDING STORYBOOK PRODUCTS\n\nIn addition to Storybook debugging of components or common modules, you can also\nperform Storybook build tasks with the following commands.\n\nmodern build --platform storybook\n\n\nFor the modern build --platform command you can see.\n\n * modern build\n\nAfter the build is complete, you can see the build product files in the\ndist/storybook-static directory.","frontmatter":{"sidebar_position":5}},{"id":21,"title":"# Initialize the project","routePath":"/module-tools/en/guide/best-practices/components","toc":[{"id":"debugging-code-with-storybook-1","text":"Debugging code with Storybook","depth":2},{"id":"developing-styles-1","text":"Developing Styles","depth":2},{"id":"csspostcss-2","text":"CSS/PostCSS","depth":3},{"id":"less-5","text":"Less","depth":3},{"id":"sassscss-2","text":"Sass/Scss","depth":3},{"id":"tailwind-css-2","text":"Tailwind CSS","depth":3},{"id":"html-class-3","text":"HTML class","depth":4},{"id":"apply-2","text":"@apply","depth":4},{"id":"recommended-method-1","text":"Recommended method","depth":4},{"id":"the-difference-between-bundle-and-bundleless-build-products-1","text":"The difference between bundle and bundleless build products","depth":4},{"id":"css-modules-2","text":"CSS Modules","depth":3},{"id":"configuring-build-products-1","text":"Configuring build products","depth":2},{"id":"testing-components-1","text":"Testing components","depth":2},{"id":"releasing-components-1","text":"Releasing components","depth":2}],"content":"DEVELOPING COMPONENTS\n\nThis chapter will describe how to develop component projects using the module\nengineering solution.\n\n\n# INITIALIZE THE PROJECT\n\n<CH.Spotlight>\n\nnpx @modern-js/create components-project\n\n? Please select the solution you want to create Module Solution\n? Package Name components-demo\n? Development Language TS\n? Package Management Tool pnpm\n\n\n--------------------------------------------------------------------------------\n\nIt is recommended to use the @modern-js/create command to initialize an npm\nproject.\n\nnpx @modern-js/create components-project\n\n? Please select the solution you want to create Module Solution\n? Package Name components-demo\n? Development Language TS\n? Package Management Tool pnpm\n\n\n--------------------------------------------------------------------------------\n\nThe initialized directory structure.\n\n.\n├── README.md\n├── node_modules/\n├── dist/\n├── modern.config.ts\n├── package.json\n├── pnpm-lock.yaml\n├── src\n│ ├── index.ts\n│ └── modern-app-env.d.ts\n└── tsconfig.json\n\n\n--------------------------------------------------------------------------------\n\nModify the . /src/index.ts file suffix and content.\n\nAt this point, a component project is initialized.\n\nexport default () => {\n return <div>hello world</div>;\n};\n\n\n</CH.Spotlight>\n\n\nDEBUGGING CODE WITH STORYBOOK\n\n<CH.Spotlight>\n\npnpm run new\n\n? Action Enable features\n? Enable features Enable Visual Testing (Storybook)\n\n\n--------------------------------------------------------------------------------\n\nExecute the new command in the project root directory to enable the Storybook\nfeature.\n\npnpm run new\n\n? Action Enable features\n? Enable features Enable Visual Testing (Storybook)\n\n\n--------------------------------------------------------------------------------\n\nOnce successfully opened, you will see that a new dependency has been added to\npackage.json. The stories directory and related initialization files are also\ncreated.\n\n<CH.Code>\n\n{\n \"name\": \"components-demo\",\n \"devDependencies\": {\n \"@modern-js/plugin-storybook\": \"x.y.z\",\n \"@modern-js/runtime\": \"x.y.z\",\n \"react\": \"^17\",\n \"react-dom\": \"^17\"\n }\n}\n\n\n.\n├── src\n│ ├── index.ts\n│ └── modern-app-env.d.ts\n├── stories\n│ ├── .eslintrc.js\n│ ├── index.stories.tsx\n│ └── tsconfig.json\n\n\n</CH.Code>\n\n--------------------------------------------------------------------------------\n\nAfter initialization, the tsconfig.json file in the . /stories directory, the\ntsconfig.json file is set by default with the paths configuration of the same\nname as the project.\n\n{\n \"extends\": \"../tsconfig.json\",\n \"compilerOptions\": {\n \"baseUrl\": \"../\",\n \"paths\": {\n \"components-demo\": [\"./\"],\n \"components-demo/*\": [\"./*\"]\n }\n },\n \"include\": [\"**/*\"]\n}\n\n\n--------------------------------------------------------------------------------\n\nSuch a configuration allows you to introduce code in Story code directly using\nthe name of the project.\n\n<CH.Code>\n\n\n\nexport const YourStory = () => <Component />;\n\nexport default {\n title: 'Your Stories',\n};\n\n\n--------------------------------------------------------------------------------\n\nexport default () => {\n return <div>hello world</div>;\n};\n\n\n</CH.Code>\n\n--------------------------------------------------------------------------------\n\nAt this point Storybook identifies the entry point for the imported code based\non fields like main, exports in the project's package.json file. The location of\nthe type file is determined by the types field.\n\n{\n \"name\": \"components-demo\",\n \"main\": \"./dist/esm/index.js\",\n \"types\": \"./dist/types/index.d.ts\"\n}\n\n\n--------------------------------------------------------------------------------\n\nWhile importing source code for debugging is also supported, debugging using\nproject artifacts is more reliable.\n\nDebugging with source code has a limitation: some configurations are not\nequivalent in Storybook and in the original build support.\n\nThis is why debugging with the product is recommended.\n\n\n\nexport const YourStory = () => <Component />;\n\nexport default {\n title: 'Your Stories',\n};\n\n\n</CH.Spotlight>\n\n\nDEVELOPING STYLES\n\nNext we can add styles to the component.\n\nThe following capabilities are currently supported for developing styles.\n\n * CSS/PostCSS\n * Less\n * Scss/Sass\n * Tailwind CSS\n * CSS Modules\n\n\nCSS/POSTCSS\n\nThe module project supports PostCSS and has the following built-in postcss\nplugins.\n\n * flexbugs-fixes\n * custom-properties\n * initial\n * page-break\n * font-variant\n * media-minmax\n * nesting\n\nSo we can create .css files in our projects and use the syntax support and\ncapabilities provided by these plugins directly in our css files.\n\n<CH.Spotlight>\n\na,\nb {\n color: red;\n\n /* \"&\" comes first */\n & c,\n & d {\n color: white;\n }\n\n /* \"&\" comes later, requiring \"@nest\" */\n @nest e & {\n color: yellow;\n }\n}\n\n\n--------------------------------------------------------------------------------\n\nSource Code.\n\n\n\n--------------------------------------------------------------------------------\n\ncss product.\n\na,\nb {\n color: red;\n}\na c,\nb c,\na d,\nb d {\n color: white;\n}\ne a,\ne b {\n color: yellow;\n}\n\n\n</CH.Spotlight>\n\n\nLESS\n\nModule projects support development styles using Less.\n\n> Currently supported version is 4.1.3\n\n<CH.Spotlight>\n\n@bg: black;\n@bg-light: boolean(luma(@bg) > 50%);\n\ndiv {\n background: @bg;\n color: if(@bg-light, black, white);\n}\n\n\n--------------------------------------------------------------------------------\n\nSource Code.\n\n\n\n--------------------------------------------------------------------------------\n\nLess product.\n\ndiv {\n background: black;\n color: white;\n}\n\n\n</CH.Spotlight>\n\n\nSASS/SCSS\n\nModule projects support developing styles using Scss/Sass.\n\n> Currently supported version is 1.54.4\n\n<CH.Spotlight>\n\n$font-stack: Helvetica, sans-serif;\n$primary-color: #333;\n\nbody {\n font: 100% $font-stack;\n color: $primary-color;\n}\n\n\n--------------------------------------------------------------------------------\n\n源代码。\n\n\n\n--------------------------------------------------------------------------------\n\nLess product.\n\nbody {\n font: 100% Helvetica, sans-serif;\n color: #333;\n}\n\n\n</CH.Spotlight>\n\n\nTAILWIND CSS\n\nThe module project supports the development of component styles using Tailwind\nCSS.\n\nBy default, this feature is not enabled in the module project, you need to\nenable it as follows.\n\n<CH.Spotlight>\n\npnpm run new\n\n? Action Enable features\n? Enable features Enable Visual Testing (Storybook)\n\n\n--------------------------------------------------------------------------------\n\nThe Tailwind CSS feature can be enabled by executing the new command in the\nproject root directory.\n\npnpm run new\n\n? Action Enable features\n? Enable features Enable Tailwind CSS\n\n\n--------------------------------------------------------------------------------\n\nOnce successfully opened, you will see that a new dependency has been added to\npackage.json.\n\n{\n \"devDependencies\": {\n \"@modern-js/plugin-tailwindcss\": \"x.y.z\"\n }\n}\n\n\n</CH.Spotlight>\n\nTailwind CSS offers two ways to use it.\n\nHTML CLASS\n\n<CH.Spotlight>\n\nimport 'tailwindcss/utilities.css';\n\nexport default () => {\n return <div className=\"bg-black text-white\">hello world</div>;\n};\n\n\n--------------------------------------------------------------------------------\n\nTailwind CSS supports adding styles to HTML tags by using class names.\n\n\n\n--------------------------------------------------------------------------------\n\n**When using HTML class names, be sure to import the Tailwind CSS equivalent css\nfile. **\n\n\n\n--------------------------------------------------------------------------------\n\nStyle product.\n\n> This is a bundle build.\n\n/* ../../node_modules/.pnpm/tailwindcss@2.2.19/node_modules/tailwindcss/utilities.css */\n.table {\n display: table;\n}\n@keyframes spin {\n to {\n transform: rotate(360deg);\n }\n}\n@keyframes ping {\n 75%,\n 100% {\n transform: scale(2);\n opacity: 0;\n }\n}\n@keyframes pulse {\n 50% {\n opacity: 0.5;\n }\n}\n@keyframes bounce {\n 0%,\n 100% {\n transform: translateY(-25%);\n animation-timing-function: cubic-bezier(0.8, 0, 1, 1);\n }\n 50% {\n transform: none;\n animation-timing-function: cubic-bezier(0, 0, 0.2, 1);\n }\n}\n.bg-black {\n --tw-bg-opacity: 1;\n background-color: rgba(0, 0, 0, var(--tw-bg-opacity));\n}\n.text-white {\n --tw-text-opacity: 1;\n color: rgba(255, 255, 255, var(--tw-text-opacity));\n}\n*,\n::before,\n::after {\n --tw-shadow: 0 0 #0000;\n}\n*,\n::before,\n::after {\n --tw-ring-inset: var(--tw-empty);\n --tw-ring-offset-width: 0px;\n --tw-ring-offset-color: #fff;\n --tw-ring-color: rgba(59, 130, 246, 0.5);\n --tw-ring-offset-shadow: 0 0 #0000;\n --tw-ring-shadow: 0 0 #0000;\n}\n@media (min-width: 640px) {\n}\n@media (min-width: 768px) {\n}\n@media (min-width: 1024px) {\n}\n@media (min-width: 1280px) {\n}\n@media (min-width: 1536px) {\n}\n\n\n</CH.Spotlight>\n\n@APPLY\n\nTailwind CSS provides the @apply directive, which allows us to inline the styles\nprovided by Tailwind CSS into the styles we write.\n\n@apply can be used in CSS, Less, and Sass.\n\n.btn {\n @apply font-bold py-2 px-4 rounded;\n}\n\n\nHowever, there are some things to keep in mind when using Less and Sass.\n\nSASS\n\nWhen using Tailwind with Sass, the presence of !important after @apply requires\ninterpolation to get Sass to compile correctly.\n\n<CH.Spotlight>\n\n.alert {\n @apply bg-red-500 !important;\n}\n\n\n--------------------------------------------------------------------------------\n\nIt does not work properly.\n\n\n\n--------------------------------------------------------------------------------\n\nCan work properly.\n\n.alert {\n @apply bg-red-500 #{!important};\n}\n\n\n</CH.Spotlight>\n\nLESS\n\nWhen using Tailwind with Less, you cannot nest Tailwind's @screen directive.\n\n<CH.Spotlight>\n\n.card {\n @apply rounded-none;\n\n @screen sm {\n @apply rounded-lg;\n }\n}\n\n\n--------------------------------------------------------------------------------\n\nIt does not work properly.\n\n\n\n--------------------------------------------------------------------------------\n\nInstead, use regular media queries and the theme() function to reference your\nscreen size, or simply don't nest your @screen directive.\n\n<CH.Code>\n\n// Use a regular media query and theme()\n.card {\n @apply rounded-none;\n\n @media (min-width: theme('screens.sm')) {\n @apply rounded-lg;\n }\n}\n\n\n--------------------------------------------------------------------------------\n\n// Use the @screen directive at the top-level\n.card {\n @apply rounded-none;\n\n @media (min-width: theme('screens.sm')) {\n @apply rounded-lg;\n }\n}\n\n\n</CH.Code>\n\n</CH.Spotlight>\n\nRECOMMENDED METHOD\n\n**It is recommended to develop styles in the way specified by @apply, so that\nonly styles inlined by directives are included in the style product. **\n\nWhen adding styles using HTML class names, by default Tailwind will not only add\nthe styles corresponding to its own class name to the product, but will also\nhave additional style code that may not affect its own styles.\n\nTHE DIFFERENCE BETWEEN BUNDLE AND BUNDLELESS BUILD PRODUCTS\n\nFor the following code, there is a big difference between the bundle and\nbundleless modes of building products.\n\n> The so-called bundle and bundleless can be found in [[Bundle and\n> Bundleless]](/en/guide/advance/in-depth-about-build#bundle- and-bundleless)\n\nimport 'tailwindcss/utilities.css';\n\nexport default () => {\n return <div className=\"bg-black text-white\">hello world11</div>;\n};\n\n\nIn Bundle mode, third-party dependencies are packaged in.\n\nFor styles, a separate product file is generated, and there is no code related\nto importing styles in the Js product file.\n\nIf you need to inject styles into Js products, you can enable the style.inject\nAPI.\n\n<CH.Code>\n\n/* ../../node_modules/.pnpm/tailwindcss@2.2.19/node_modules/tailwindcss/utilities.css */\n.table {\n display: table;\n}\n@keyframes spin {\n to {\n transform: rotate(360deg);\n }\n}\n@keyframes ping {\n 75%, 100% {\n transform: scale(2);\n opacity: 0;\n }\n}\n@keyframes pulse {\n 50% {\n opacity: .5;\n }\n}\n@keyframes bounce {\n 0%, 100% {\n transform: translateY(-25%);\n animation-timing-function: cubic-bezier(0.8, 0, 1, 1);\n }\n 50% {\n transform: none;\n animation-timing-function: cubic-bezier(0, 0, 0.2, 1);\n }\n}\n.bg-black {\n --tw-bg-opacity: 1;\n background-color: rgba(0, 0, 0, var(--tw-bg-opacity));\n}\n.text-white {\n --tw-text-opacity: 1;\n color: rgba(255, 255, 255, var(--tw-text-opacity));\n}\n*,\n::before,\n::after {\n --tw-shadow: 0 0 #0000 ;\n}\n*,\n::before,\n::after {\n --tw-ring-inset: var(--tw-empty, );\n --tw-ring-offset-width: 0px;\n --tw-ring-offset-color: #fff;\n --tw-ring-color: rgba(59, 130, 246, 0.5);\n --tw-ring-offset-shadow: 0 0 #0000;\n --tw-ring-shadow: 0 0 #0000 ;\n}\n@media (min-width: 640px) {\n}\n@media (min-width: 768px) {\n}\n@media (min-width: 1024px) {\n}\n@media (min-width: 1280px) {\n}\n@media (min-width: 1536px) {\n}\n\n\n--------------------------------------------------------------------------------\n\n// src/index.tsx\n\nvar src_default = () => {\n return /* @__PURE__ */ jsx(\"div\", {\n className: \"bg-black text-white\",\n children: \"hello world11\"\n });\n};\nexport {\n src_default as default\n};\n\n\n</CH.Code>\n\nIn Bundleless mode, no third-party dependencies are packaged in, and no style\nproducts are generated at this time.\n\n\nimport 'tailwindcss/utilities.css';\nvar src_default = () => {\n return /* @__PURE__ */ jsx('div', {\n className: 'bg-black text-white',\n children: 'hello world11',\n });\n};\nexport { src_default as default };\n\n\n\nCSS MODULES\n\nModule projects support the development of styles using CSS Modules. By default,\nthe following files are recognized as CSS Module files.\n\n * .module.css\n * .module.less\n * .module.scss\n * .module.sass\n\nIf you need to configure CSS Modules, you can check out the API at\n\n * autoModules\n * modules\n\nThe following is a code example.\n\n<CH.Code>\n\n\n\nexport default () => {\n return <div className={style.btn}>hello world</div>;\n};\n\n\n.btn {\n color: blue;\n}\n\n\n</CH.Code>\n\n\nCONFIGURING BUILD PRODUCTS\n\nBased on most scenarios of component project usage, it is recommended to use the\nnpm-component build preset. This preset yields a product directory structure of\n\n.\n├── dist\n│ ├── es\n│ ├── lib\n│ └── types\n\n\n * . /dist/es: Contains bundleless products in ES modules format that support\n the es6 syntax.\n * . /dist/lib: Contains bundleless products in CommonJS format with support for\n es6 syntax.\n * . /dist/types: Contains the types file.\n\nThe buildPreset can be configured manually if there is a requirement to use\nsyntax support, and supports modifying the supported syntax by adding a suffix\nto npm-component.\n\nexport default defineConfig({\n buildPreset: 'npm-component-es2019',\n});\n\n\nIf you have special needs for the build product directory structure, you can use\nthe buildConfig API, which can be used by the following documentation.\n\n * modify-output-product\n * in-depth-about-build\n\n\nTESTING COMPONENTS\n\nFor more information on how to test components, please refer to [Test project].\n\n\nRELEASING COMPONENTS\n\nIt is recommended to use module project to provide version publishing function,\nyou can refer to [Versioning and publishing].","frontmatter":{}},{"id":22,"title":"Quick start","routePath":"/module-tools/en/guide/intro/getting-started","toc":[{"id":"3-minute-demo-1","text":"3 minute demo","depth":2},{"id":"lets-get-started-1","text":"Let's get started","depth":2}],"content":"QUICK START\n\n\n3 MINUTE DEMO\n\nWant to experience Module Tools in action? The only prerequisite you need is\nNode.js LTS and make sure your Node version is >= 14.17.6.\n\nFrom your shell, install the following dependencies in your project.\n\n * @modern-js/module-tools\n * @modern-js/plugin-testing\n\n> If it's a TypeScript project, add the \"typescript\" dependency.\n\nnpm install -D @modern-js/module-tools @modern-js/plugin-testing\n\n\n> For projects that use pnpm or the Yarn package manager, just replace npm. pnpm\n> is recommended.\n\nThen add the command \"build\": \"modern build\" to your project's package.json\nfile.\n\n{\n \"scripts\": {\n \"build\": \"modern build\"\n }\n}\n\n\nIf your project has a src/index.(js|jsx) file or both src/index.(ts|tsx) and\ntsconfig.json files, then congratulations you can run the npm run build command\ndirectly to build your project with Module Tools.\n\nIf you want to see real projects that use the module engineering solution, you\ncan execute the following command.\n\ngit clone https://github.com/modern-js-dev/module-tools-examples\ncd module-tools-example\n\n## Execute the build.\npnpm build\n\n## Execute the build in listening mode.\npnpm build --watch\n\n## Start Storybook\npnpm dev storybook\n\n## Test\npnpm test\npnpm test\n\n\nIf you want to create a complete module project, you can execute the following\ncommand:\n\nnpx @modern-js/create your-project-dir-name\n\n\nNext, in the issue interaction, follow the options below.\n\n? Please select the type of project you want to create Module\n? Please fill in the project name library\n? Please select the development language TS\n? Please select the package management tool pnpm\n\n\n> The project name is the value of the \"name\" field in package.json.\n\nThen the process of initializing the project will start. After the project\ndirectory and files are generated and the dependencies are installed, a complete\nmodule project is created.\n\nWe can start the project build directly with the pnpm build command, and start\nthe build in watching mode with the pnpm build --watch command.\n\n\nLET'S GET STARTED\n\nChoose your tutorial scenario...\n\n * I'm a beginner and need to learn basic usage of Module Tools.\n * I have learned the basic usage of Module Tools and can learn advanced usage\n of Module Tools.\n * I am the maintainer of the project and need to learn how to develop plugins\n for Module Tools and learn more about Module Tools Advanced.","frontmatter":{"sidebar_position":3}},{"id":23,"title":"Welcome to Module Tools","routePath":"/module-tools/en/guide/intro/welcome","toc":[],"content":"WELCOME TO MODULE TOOLS\n\nModule Tools is a modules engineering solution for Modern.js, as well as a core\ndependency. It allows developers to build, debug, and publish module type\nproject more easily. A module type project can mostly be thought of as an npm\npackage type project, which may be a component, component library or tool\nlibrary project.\n\nIf you are planning to develop a project of the npm package type, then you came\nto the right place! Modern.js provides a professional module engineering\nsolution. It gives you:\n\n * Simple project initialization: simply execute the npx @modern-js/create\n project-dir command, followed by a few interactive questions, to create a\n complete module type project. The created project also supports the choice of\n two package managers, pnpm and Yarn.\n * Code formatting: In a module project, you can execute modern lint to format\n the code. The initialized module project includes the ESLint ruleset for\n Modern.js for most scenarios.\n * Comprehensive build capabilities and faster builds: Module Tools provides\n high-performance build capabilities based on esbuild and SWC, and provides\n rich configurations for different build scenarios.\n * Storybook debugging tools: Module Tools provides Storybook debugging tools\n for debugging module projects. After installing the Storybook plugin for\n Module Tools, you can start it with the modern dev storybook command. You can\n use Storybook not only for debugging components, but also for other types of\n modules.\n * Testing capabilities with Jest: When you need to test a module, you can use\n the modern test command of Module Tools, which not only integrates with Jest,\n but also provides an API for configuring Jest.\n * Versioning based on Changesets: When you need to record changes to a project,\n you can use the modern change command to generate a Markdown file containing\n the changes; when you need to upgrade a project, you can use the modern bump\n command to analyze and upgrade the version through the Markdown file; when\n you need to release a project, you can use the modern release command to\n release the project; Module Tools implements these commands based on\n Changesets.\n * Extensible plug-in mechanism: Want to integrate additional debugging tools\n for your project? Or maybe you want to do some extra processing during the\n build process, Module Tools provides a plugin mechanism and plugin hooks that\n cover both the dev command and the build command process. You can use them to\n extend the capabilities of your project.\n * Lots more! Module Tools will continue to optimize its build and debug\n features in the future. If there are important issues to be solved in module\n project building, or if a mainstream module project debugging tool or pattern\n emerges, then they will probably be supported by Module Tools.","frontmatter":{"sidebar_position":1}},{"id":24,"title":"Why module project solution","routePath":"/module-tools/en/guide/intro/why-module-engineering-solution","toc":[],"content":"WHY MODULE PROJECT SOLUTION\n\nYou've probably all experienced it: when developing a component library or tool\nlibrary from scratch, we have to consider not only how to write the code logic\nof the project itself, but also how to build, debug, test, format the code, and\nother things that have nothing to do with the code logic.\n\nFor example, when we consider which builder is used to build the code for a\nmodule project, we might previously consider webpack or Rollup, but now we might\nalso consider esbuild or SWC.\n\nRegardless of which builder is chosen, this is going to be a costly learning\ncurve for developers who are not skilled in the use of these build tools. Even\nif you want to use them quickly, it will take a lot of time and effort.\n\nIn addition to the build, things like providing debugging tools for projects,\nsupporting testing capabilities, adding code format validation, etc. can take a\nlong time and effort for a novice to understand or master them and actually\nserve the current project.\n\nTo ensure the quality of the code and the integrity of the project, we often\nneed to do these things that are not related to the logical implementation of\nthe code. However, these things are likely to affect the overall project\ndevelopment progress, reduce the developer's development experience, and make\nthe developer feel that the development threshold of the module project is very\nhigh.\n\nIf you have to go through all this work every time you develop a module type\nproject, you will spend most of your development time in the beginning on these\nthings that are not related to code implementation. If we could provide a module\nengineering solution that would help developers to solve the project engineering\nissues and allow them to focus more on code implementation, it would greatly\nimprove the module type project development experience.\n\n\n\nModern.js, in order to make developing module type projects easier, provides a\nmodule engineering solution in order to solve the above mentioned problems and\nprovides the main features using Module Tools. Module-tools can be understood as\na tool dedicated to the development of module type projects.","frontmatter":{"sidebar_position":2}},{"id":25,"title":"index","routePath":"/module-tools/en/","toc":[],"content":"INDEX","frontmatter":{"pageType":"home","hero":{"name":"Module Tools","text":"Module engineering solutions","tagline":"simple, powerful, high-performance modern npm package development solution","actions":[{"theme":"brand","text":"welcome","link":"/guide/intro/welcome"}]},"features":[{"title":"Esbuild: The High Performance JS Bundler","details":"Built on Esbuild, the build is extremely fast and gives you the ultimate development experience.","icon":"🚀"},{"title":"Storybook: The community popular UI development tool","details":"Integrated with Storybook, you can use it to debug UI.","icon":"📦"},{"title":"transform + bundle","details":"Both bundle and bundleless build modes are supported.","icon":"✨"},{"title":"zero configuration","details":"Develop your npm packages without any configuration, with built-in presets covering multiple scenarios.","icon":"🛠️"},{"title":"Extensible: Provides a powerful plugin mechanism","details":"With its plugin extension mechanism, you can easily extend the capabilities of Module Tools.","icon":"🎨"}]}},{"id":26,"title":"Quick Start","routePath":"/module-tools/en/plugins/guide/getting-started","toc":[],"content":"QUICK START\n\nModule engineering solution not only provides a rich set of features, but also\nsupports extending the capabilities of the current project by way of plugins.\n\nWe can quickly see how to write a module-tools plugin by using the following\nexample.\n\n<CH.Spotlight>\n\n. /project .\n├── plugins\n│ └── example.ts\n├── src/\n└── modern.config.ts\n\n\n--------------------------------------------------------------------------------\n\nFirst we create . /plugins/example.ts file under the initialized project.\n\n\n\n--------------------------------------------------------------------------------\n\nNext add the code for the plugin to the example.ts file.\n\n\n\nexport const ExamplePlugin = (): CliPlugin<ModuleTools> => {\n return {\n name: 'example',\n setup() {\n console.info('this is example plugin');\n return {\n // use hooks\n afterBuild() {\n console.info('build over');\n }\n };\n };\n };\n};\n\n\n--------------------------------------------------------------------------------\n\nThen we register the plugin we just wrote via the plugins API.\n\n\nexport default defineConfig({\n plugins: [examplePlugin()],\n});\n\n\n--------------------------------------------------------------------------------\n\nFinally, run modern build and you will see.\n\nThis is example plugin\nBuild succeed: 510.684ms\nbuild over\n\n\n</CH.Spotlight>\n\nWith the above example, we learned the following things.\n\n * The recommended plugin directory structure\n * The initialization code of the plugin\n * Plugin registration\n\nIn addition to the above, we also need to understand.\n\n * plugin objects, type definitions and recommended configuration items\n * setup functions, api object parameters, lifecycle hooks","frontmatter":{"sidebar_position":1}},{"id":27,"title":"Plugin Object","routePath":"/module-tools/en/plugins/guide/plugin-object","toc":[{"id":"plugin-type-definitions-1","text":"Plugin type definitions","depth":2},{"id":"plugin-configuration-items-1","text":"Plugin configuration items","depth":2}],"content":"PLUGIN OBJECT\n\nThe module-tools plugin is an object, and the object contains the following\nproperties.\n\n * name: The name of the plugin, a unique identifier.\n * setup: plugin initialization function, which will be executed only once.\n setup function can return a Hooks object, and module-tools will execute the\n function corresponding to the Hook defined on the Hooks object at a specific\n time.\n\nFor example, in the following plugin code example, the beforeBuild function is\ntriggered before the project starts the build task and the build start log is\nprinted.\n\n<CH.Code>\n\n\n\nconst myPlugin: CliPlugin<ModuleTools> = {\n name: 'my-plugin',\n\n setup() {\n return {\n // this is hook\n beforeBuild: () => {\n console.info('build start');\n },\n };\n },\n};\n\n\n--------------------------------------------------------------------------------\n\n\nexport default {\n plugins: [myPlugin()],\n};\n\n\n</CH.Code>\n\n\nPLUGIN TYPE DEFINITIONS\n\nWhen using TypeScript, you can introduce the built-in CliPlugin and ModuleTools\ntypes to provide the correct type derivation for plugins: ``\n\n\n\nconst myPlugin: CliPlugin<ModuleTools> = {\n name: 'my-plugin',\n\n setup() {\n const foo = '1';\n\n return {\n // this is hook\n afterBuild: () => {\n //...\n },\n };\n },\n};\n\n\n\nPLUGIN CONFIGURATION ITEMS\n\nIt is recommended to write the plugin as a function, so that the plugin can\nreceive configuration items via function entry.\n\n\n\ntype MyPluginOptions = {\n foo: string;\n};\n\nconst myPlugin = (options: MyPluginOptions): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n console.log(options.foo);\n },\n});\n","frontmatter":{"sidebar_position":2}},{"id":28,"title":"Setup function","routePath":"/module-tools/en/plugins/guide/setup-function","toc":[{"id":"plugin-api-objects-1","text":"Plugin API objects","depth":2},{"id":"apiuseappcontext-3","text":"api.useAppContext","depth":3},{"id":"apiuseresolvedconfigcontext-3","text":"api.useResolvedConfigContext","depth":3},{"id":"apiusehookrunners-3","text":"api.useHookRunners","depth":3},{"id":"asynchronous-setup-1","text":"Asynchronous setup","depth":2},{"id":"life-cycle-hooks-1","text":"Life cycle hooks","depth":2}],"content":"SETUP FUNCTION\n\nIn the [Plugin object] section we know that the plug-in object contains a setup\nfunction that not only contains an api object parameter, but also returns a\nHooks object.\n\n\nPLUGIN API OBJECTS\n\nThe setup function of the plugin will provide an api object parameter, and you\ncan call some of the methods provided on this object to get information about\nthe configuration, project context, etc.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup(api) {\n // Get the original configuration of the application\n const config = api.useConfigContext();\n // Get the application runtime context\n const appContext = api.useAppContext();\n // Get the final configuration after resolving\n const resolvedConfig = api.useResolvedConfigContext();\n },\n});\n\n\n\nAPI.USEAPPCONTEXT\n\nUsed to get project context information.\n\nconst useAppContext: () => IAppContext;\n\ninterface IAppContext {\n appDirectory: string;\n configFile: string | false;\n packageName: string;\n nodeModulesDirectory: string;\n internalDirectory: string;\n plugins: {\n cli?: any;\n server?: any;\n }[];\n}\n\n\nWe can see through the actual type file that there are other fields, but the\nonly ones that make sense for the module project at the moment are the above.\napi object other methods are the same.\n\n\nAPI.USERESOLVEDCONFIGCONTEXT\n\nUsed to get the final configuration after parsing.\n\nIf you need to get the build-related final configuration, you need to use the\nbeforeBuild Hook.\n\nconst useResolvedConfigContext: () => NormalizedConfig;\n\ninterface NormalizedConfig {\n buildConfig: PartialBuildConfig;\n buildPreset: BuildPreset;\n designSystem?: Record<string, any>;\n dev: Dev;\n plugins: PluginConfig;\n runtime: RuntimeConfig;\n runtimeByEntries?: RuntimeByEntriesConfig;\n _raw: UserConfig;\n}\n\n\n\nAPI.USEHOOKRUNNERS\n\nUsed to get the executors of Hooks and trigger the execution of a specific Hook.\n\n\n\nexport default (): CliPlugin => ({\n name: 'my-plugin',\n\n async setup(api) {\n const hookRunners = api.useHookRunners();\n // trigger the afterBuild Hook\n await hookRunners.afterBuild();\n },\n});\n\n\n\nASYNCHRONOUS SETUP\n\nThe setup of a CLI plugin can be an asynchronous function that performs\nasynchronous logic during the initialization process.\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n async setup(api) {\n await doSomething();\n },\n});\n\n\n\nLIFE CYCLE HOOKS\n\nWe know that the setup function returns a Hooks object, which can also be\nunderstood as an object with module-tools lifecycle hooks.\n\nCurrently there are two main types of hooks.\n\n * build hooks: triggered only when the build command is executed to build the\n source code product.\n * buildPlatform hook: triggered only when the build --platform command is\n executed to generate other build products.\n * debug hooks: hooks that are triggered when running the dev command.\n\nSee the API documentation for a full list of lifecycle hooks.","frontmatter":{"sidebar_position":3}},{"id":29,"title":"Overview","routePath":"/module-tools/en/plugins/official-list/overview","toc":[{"id":"official-plugin-1","text":"Official Plugin","depth":2}],"content":"OVERVIEW\n\n\nOFFICIAL PLUGIN\n\n(Under Building)","frontmatter":{}},{"id":30,"title":"BuildConfig","routePath":"/module-tools/api/config/build-config","toc":[{"id":"alias-3","text":"alias","depth":2},{"id":"asset-3","text":"asset","depth":2},{"id":"path-3","text":"path","depth":3},{"id":"limit-3","text":"limit","depth":3},{"id":"publicpath-3","text":"publicPath","depth":3},{"id":"svgr-3","text":"svgr","depth":3},{"id":"include-3","text":"include","depth":4},{"id":"exclude-3","text":"exclude","depth":4},{"id":"autoexternal-3","text":"autoExternal","depth":2},{"id":"dependencies-3","text":"dependencies","depth":3},{"id":"peerdependencies-7","text":"peerDependencies","depth":3},{"id":"buildtype-3","text":"buildType","depth":2},{"id":"copy-3","text":"copy","depth":2},{"id":"copypatterns-1","text":"copy.patterns","depth":3},{"id":"copyoptions-1","text":"copy.options","depth":3},{"id":"define-3","text":"define","depth":2},{"id":"dts-3","text":"dts","depth":2},{"id":"tsconfigpath-3","text":"tsconfigPath","depth":3},{"id":"distpath-3","text":"distPath","depth":3},{"id":"only-3","text":"only","depth":3},{"id":"externals-3","text":"externals","depth":2},{"id":"format-3","text":"format","depth":2},{"id":"input-3","text":"input","depth":2},{"id":"jsx-3","text":"jsx","depth":2},{"id":"metafile-3","text":"metafile","depth":2},{"id":"minify-3","text":"minify","depth":2},{"id":"outdir-3","text":"outDir","depth":2},{"id":"platform-3","text":"platform","depth":2},{"id":"sourcedir-7","text":"sourceDir","depth":2},{"id":"sourcemap-3","text":"sourceMap","depth":2},{"id":"splitting-3","text":"splitting","depth":2},{"id":"style-3","text":"style","depth":2},{"id":"less-7","text":"less","depth":3},{"id":"lessoptions-3","text":"lessOptions","depth":4},{"id":"additionaldata-6","text":"additionalData","depth":4},{"id":"implementation-6","text":"implementation","depth":4},{"id":"sass-3","text":"sass","depth":3},{"id":"sassoptions-3","text":"sassOptions","depth":4},{"id":"additionaldata-7","text":"additionalData","depth":4},{"id":"implementation-7","text":"implementation","depth":4},{"id":"postcss-3","text":"postcss","depth":3},{"id":"inject-3","text":"inject","depth":3},{"id":"automodules-3","text":"autoModules","depth":3},{"id":"modules-3","text":"modules","depth":3},{"id":"tailwindcss-7","text":"tailwindcss","depth":3},{"id":"target-3","text":"target","depth":2},{"id":"umdglobals-3","text":"umdGlobals","depth":2},{"id":"umdmodulename-3","text":"umdModuleName","depth":2}],"content":"BUILDCONFIG\n\n本章节描述了 Module Tools 关于构建的所有配置\n\n\nALIAS\n\n * 类型:Record<string, string> | Function\n * 默认值:{'@': 'src',}\n\n对于 TypeScript 项目,只需要在 tsconfig.json 中配置 compilerOptions.paths, Module Tools\n会自动识别 tsconfig.json 里的别名,因此不需要额外配置 alias 字段。\n\n\n\nexport default defineConfig({\n buildConfig: {\n alias: {\n '@common': './src/common',\n },\n },\n});\n\n\n以上配置完成后,如果在代码中引用 @common/Foo.tsx, 则会映射到 <root>/src/common/Foo.tsx 路径上。\n\nalias 的值定义为函数时,可以接受预设的 alias 对象,并对其进行修改。\n\n\n\nexport default defineConfig({\n buildConfig: {\n alias: alias => {\n alias['@common'] = './src/common';\n },\n },\n});\n\n\n也可以在函数中返回一个新对象作为最终结果,新对象会覆盖预设的 alias 对象。\n\n\n\nexport default defineConfig({\n buildConfig: {\n alias: alias => {\n return {\n '@common': './src/common',\n };\n },\n },\n});\n\n\n\nASSET\n\n\nPATH\n\n静态资源输出路径,会基于 outDir 进行输出。\n\n * 类型: string\n * 默认值: assets\n\n\nLIMIT\n\n打包时自动内联静态资源的阈值,小于 10KB 的资源会被自动内联进 bundle 产物中。\n\n * 类型: number\n * 默认值: 10 * 1024\n\n\nPUBLICPATH\n\n打包时给未内联资源的 CDN 前缀。\n\n * 类型: string\n * 默认值: undefined\n\n\n\nexport default defineConfig({\n buildConfig: {\n asset: {\n publicPath: 'https://xxx/',\n },\n },\n});\n\n\n此时,所有静态资源都会添加 https://xxx/ 前缀。\n\n\nSVGR\n\n打包时将 svg 作为一个 React 组件处理,options 参考 svgr,另外还支持了 include 和 exclude\n两个配置项,用于匹配需要处理的 svg 文件。\n\n * 类型: boolean | Object\n * 默认值: false\n\n开启 svgr 后,仍然使用 default export 导出 svg,所以你只能导入默认值。\n\n// true\n\n\n// false\n\n\n\nINCLUDE\n\n设定匹配的 svg 文件\n\n * 类型: string | RegExp | (string | RegExp)[]\n * 默认值: /\\.svg$/\n\nEXCLUDE\n\n设定不匹配的 svg 文件\n\n * 类型: string | RegExp | (string | RegExp)[]\n * 默认值: undefined\n\n\nAUTOEXTERNAL\n\n自动外置项目的 \"dependencies\" 和 \"peerDependencies\",不会将其打包到最终的 bundle 产物中。\n\n * 类型: boolean | Object\n * 默认值: true\n\n\nDEPENDENCIES\n\n是否需要外置项目的 \"dependencies\" 依赖。\n\n * 类型: boolean\n * 默认值: true\n\n\nPEERDEPENDENCIES\n\n是否需要外置项目的 \"peerDependencies\" 依赖。\n\n * 类型: boolean\n * 默认值: true\n\n\nBUILDTYPE\n\n构建类型,bundle 会打包你的代码,bundleless 只做代码的转换。\n\n * 类型: 'bundle' | 'bundleless'\n * 默认值: bundle\n\n\nCOPY\n\n将文件或目录拷贝到指定位置。\n\n * 类型: Object\n\n\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [{ from: './src/assets', to: '' }],\n },\n },\n});\n\n\n\nCOPY.PATTERNS\n\n * 类型: CopyPattern[]\n * 默认值: []\n\nexport interface CopyPattern {\n from: string;\n to?: string;\n context?: string;\n globOptions?: globby.GlobbyOptions;\n}\n\n\n\nCOPY.OPTIONS\n\n * 类型: Object\n * 默认值: { concurrency: 100, enableCopySync: false }\n\ntype Options = {\n concurrency?: number;\n enableCopySync?: boolean;\n};\n\n\n * concurrency: 指定并行执行多少个复制任务。\n * enableCopySync: 使用 fs.copySync,默认情况下 fs.copy。\n\n\nDEFINE\n\n定义全局变量,会被注入到代码中\n\n * 类型: Record<string, string>\n * 默认值: {}\n\n由于 define 功能是由全局文本替换实现的,所以需要保证全局变量值为字符串,更为安全的做法是将每个全局变量的值转化为字符串,使用\nJSON.stringify 进行转换,如下所示:\n\n\n\nexport default defineConfig({\n buildConfig: {\n define: {\n VERSION: JSON.stringify('1.0'),\n },\n },\n});\n\n\n为了防止全局替换替换过度,建议使用时遵循以下两个原则:\n\n * 全局常量使用大写\n * 自定义全局常量前缀后缀,确保独一无二\n\n\nDTS\n\n类型文件生成的相关配置,默认会生成。\n\n * 类型: false | Object\n * 默认值: {}\n\n\nTSCONFIGPATH\n\nTypeScript 配置文件的路径。\n\n * 类型: string\n * 默认值: ./tsconfig.json\n\n\nDISTPATH\n\n类型文件的输出路径,基于 outDir 进行输出。\n\n * 类型: string\n * 默认值: ./types\n\n\nONLY\n\n只生成类型文件,不生成 js 文件。\n\n * 类型: boolean\n * 默认值: false\n\n\nEXTERNALS\n\n配置外部依赖,不会被打包到最终的 bundle 中。\n\n * 类型: (string | RegExp)[]\n * 默认值: []\n\n\nFORMAT\n\njs 产物输出的格式,其中 iife 和 umd 只能在 buildType 为 bundle 时生效。\n\n * 类型: 'esm' | 'cjs' | 'iife' | 'umd'\n * 默认值: cjs\n\n\nINPUT\n\n指定构建的入口文件,数组形式可以指定目录。\n\n * 类型: string[] | Record<string, string>\n * 默认值: bundle 模式下默认为 ['src/index.ts'],bundleless 模式下默认为 ['src']\n\n\n\nexport default defineConfig({\n buildConfig: {\n input: ['src/index.ts', 'src/index2.ts'],\n },\n});\n\n\n\nJSX\n\n指定 jsx 的编译方式, 默认支持 React17 以上,自动注入 jsx 运行时代码。\n\n * 类型: automatic | classic\n * 默认值: automatic\n\n\nMETAFILE\n\nesbuild 以 JSON 格式生成有关构建的一些元数据,可以通过例如 bundle-buddy 的工具可视化\n\n * type: boolean\n * default: false\n\n\nMINIFY\n\n使用 esbuild 或者 terser 压缩代码,也可以传入 terserOptions。\n\n * 类型: 'terser' | 'esbuild' | false | Object\n * 默认值: false\n\n\n\nexport default defineConfig({\n buildConfig: {\n minify: {\n compress: {\n drop_console: true,\n },\n },\n },\n});\n\n\n\nOUTDIR\n\n指定构建的输出目录\n\n * 类型: string\n * 默认值: dist\n\n\nPLATFORM\n\n默认生成用于 Node.js 环境下的代码,你也可以指定为 browser,会生成用于浏览器环境的代码。\n\n * 类型: 'browser' | 'node'\n * 默认值: node\n\n\nSOURCEDIR\n\n指定构建的源码目录,默认为 src,用于在 bundleless 构建时基于源码目录结构生成对应的产物目录。\n\n * 类型: string\n * 默认值: src\n\n\nSOURCEMAP\n\n控制 sourceMap 如何生成。\n\n * 类型: boolean | 'inline' | 'external'\n * 默认值: false\n\n\nSPLITTING\n\n是否开启代码分割。\n\n * 类型: boolean\n * 默认值: false\n\n\nSTYLE\n\n配置样式相关的配置。\n\n\nLESS\n\nless 相关配置。\n\nLESSOPTIONS\n\n详细配置参考 less。\n\n * 类型: Object\n * 默认值: { javascriptEnabled: true }\n\nADDITIONALDATA\n\n在入口文件起始添加 Less 代码。\n\n * 类型: string\n * 默认值: undefined\n\n\n\nexport default defineConfig({\n buildConfig: {\n style: {\n less: {\n additionalData: `@base-color: #c6538c;`,\n },\n },\n },\n});\n\n\nIMPLEMENTATION\n\n配置 Less 使用的实现库,在不指定的情况下,使用的内置版本是 4.1.3。\n\n * 类型: string | Object\n * 默认值: undefined\n\nObject 类型时,指定 Less 的实现库\n\n\n\nexport default defineConfig({\n buildConfig: {\n style: {\n less: {\n implementation: require('less'),\n },\n },\n },\n});\n\n\nstring 类型时,指定 Less 的实现库的路径\n\n\n\nexport default defineConfig({\n buildConfig: {\n style: {\n less: {\n implementation: require.resolve('less'),\n },\n },\n },\n});\n\n\n\nSASS\n\nSass 相关配置。\n\nSASSOPTIONS\n\n详细配置参考 node-sass\n\n * 类型: Object\n * 默认值: {}\n\nADDITIONALDATA\n\n在入口文件起始添加 Sass 代码。\n\n * 类型: string | Function\n * 默认值: undefined\n\n\n\nexport default defineConfig({\n buildConfig: {\n style: {\n sass: {\n additionalData: `$base-color: #c6538c;\n $border-dark: rgba($base-color, 0.88);`,\n },\n },\n },\n});\n\n\nIMPLEMENTATION\n\n配置 Sass 使用的实现库,在不指定的情况下,使用的内置版本是 1.5.4。\n\n * 类型: string | Object\n * 默认值: undefined\n\nObject 类型时,指定 Sass 的实现库\n\n\n\nexport default defineConfig({\n buildConfig: {\n style: {\n sass: {\n implementation: require('sass'),\n },\n },\n },\n});\n\n\nstring 类型时,指定 Sass 的实现库的路径\n\n\n\nexport default defineConfig({\n buildConfig: {\n style: {\n sass: {\n implementation: require.resolve('sass'),\n },\n },\n },\n});\n\n\n\nPOSTCSS\n\n * plugins\n * processOptions\n\n详细配置查看 postcss。\n\n\nINJECT\n\n配置打包模式下是否将 style 插入到 js 中\n\n * 类型: boolean\n * 默认值: false\n\n\nAUTOMODULES\n\n根据文件名自动启用 CSS Modules。\n\n * 类型: boolean | RegExp\n * 默认值: true\n\ntrue : 为以 .module.css .module.less .module.scss .module.sass 文件名结尾的样式文件启用 CSS\nModules。\n\nfalse : 禁用 CSS Modules.\n\nRegExp : 为匹配正则条件的所有文件启用 CSS Modules.\n\n\nMODULES\n\nCSS Modules 配置\n\n * 类型: Object\n * 默认值: {}\n\n一个常用的配置是 localsConvention,它可以改变 CSS Modules 的类名生成规则。\n\n\n\nexport default defineConfig({\n buildConfig: {\n style: {\n modules: {\n localsConvention: 'camelCaseOnly',\n },\n },\n },\n});\n\n\n对于以下样式:\n\n.box-title {\n color: red;\n}\n\n\n你可以使用 styles.boxTitle 来访问\n\n详细配置查看 postcss-modules\n\n\nTAILWINDCSS\n\nTailwind CSS 相关配置。\n\n * 类型: Object | Function\n * 默认值: 见下方配置详情\n\nconst tailwind = {\n content: [\n './config/html/**/*.html',\n './config/html/**/*.ejs',\n './config/html/**/*.hbs',\n './src/**/*.js',\n './src/**/*.jsx',\n './src/**/*.ts',\n './src/**/*.tsx',\n './storybook/**/*',\n ],\n};\n\n\n值为 Object 类型时,与默认配置通过 Object.assign 合并。\n\n值为 Function 类型时,函数返回的对象与默认配置通过 Object.assign 合并。\n\n不允许出现 theme 属性,否则会构建失败, 使用 designSystem 作为 Tailwind CSS Theme 配置。\n\n其他的使用方式和 Tailwind CSS 一致: 快速传送门。\n\n\nTARGET\n\n指定构建的目标环境\n\n * 类型: 'es5' | 'es6' | 'es2015' | 'es2016' | 'es2017' | 'es2018' | 'es2019' |\n 'es2020' | 'es2021' | 'es2022' | 'esnext'\n * 默认值: 'es6'\n\n\nUMDGLOBALS\n\n指定 UMD 产物外部导入的全局变量。\n\n * 类型: Record<string, string>\n * 默认值: {}\n\n\n\nexport default defineConfig({\n buildConfig: {\n umdGlobals: {\n react: 'React',\n 'react-dom': 'ReactDOM',\n },\n },\n});\n\n\n此时,react 和 react-dom 会被看做是外部导入的全局变量,不会被打包进 UMD 产物中,而是通过 global.React 和\nglobal.ReactDOM 的方式进行访问。\n\n\nUMDMODULENAME\n\n指定 UMD 产物的模块名。\n\n * 类型: string | Function\n * 默认值: name => name\n\n\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdModuleName: 'myLib',\n },\n});\n\n\n此时 UMD 产物会去挂载到 global.myLib 上。\n\n * 需要遵守 UMD 规范,UMD 产物的模块名不能和全局变量名冲突\n * 模块名不能含有 -,@,/ 等特殊字符\n\n同时函数形式可以接收一个参数,为当前打包文件的输出路径\n\n\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdModuleName: path => {\n if (path.includes('index')) {\n return 'myLib';\n } else {\n return 'myLib2';\n }\n },\n },\n});\n","frontmatter":{"sidebar_position":1}},{"id":31,"title":"BuildPreset","routePath":"/module-tools/api/config/build-preset","toc":[{"id":"string-3","text":"string","depth":2},{"id":"npm-library-3","text":"'npm-library'","depth":3},{"id":"npm-library-with-umd-3","text":"'npm-library-with-umd'","depth":3},{"id":"npm-component-3","text":"'npm-component'","depth":3},{"id":"npm-component-with-umd-3","text":"'npm-component-with-umd'","depth":3},{"id":"关于预设值支持的-ecmascript-版本以及-es5esnext-1","text":"关于预设值支持的 ECMAScript 版本以及 {es5...esnext}","depth":3},{"id":"function-3","text":"Function","depth":2}],"content":"BUILDPRESET\n\n构建的预设字符串或者预设函数。提供开箱即用的构建配置。\n\n * type: string | Function\n * default: undefined\n\n\nSTRING\n\n字符串的形式可以让你直接使用内置的预设。\n\n\n\nexport default defineConfig({\n buildPreset: 'npm-library',\n});\n\n\n\n'NPM-LIBRARY'\n\n在类 NPM 包管理器下使用的 Library 通用模式,包含 esm 和 cjs 两种 Bundle 产物,并且包含一份类型文件。\n\n关于类 NPM 包管理器\n\n * npm\n * yarn\n * pnpm\n\n{\n \"main\": \"./dist/lib/index.js\",\n \"module\": \"./dist/es/index.js\",\n \"types\": \"./dist/types/index.d.ts\"\n}\n\n\n预设字符串对应的构建配置:\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundle',\n outDir: './lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundle',\n outDir: './es',\n },\n {\n buildType: 'bundle',\n outDir: './types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\n'NPM-LIBRARY-WITH-UMD'\n\n在类 NPM 包管理器下使用,并且 Library 支持类似 unpkg 的模式。在预设 'npm-library' 的基础上,额外提供 umd 产物。\n\n{\n \"main\": \"./dist/lib/index.js\",\n \"module\": \"./dist/es/index.js\",\n \"types\": \"./dist/types/index.d.ts\",\n \"unpkg\": \"./dist/umd/index.js\",\n};\n\n\n预设字符串对应的构建配置:\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundle',\n outDir: './lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundle',\n outDir: './es',\n },\n {\n format: 'umd',\n target: 'es6',\n buildType: 'bundle',\n outDir: './umd',\n },\n {\n buildType: 'bundle',\n outDir: './types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\n'NPM-COMPONENT'\n\n在类 NPM 包管理器下使用的 组件(库)通用模式。包含 esm 和 cjs 两种 Bundleless 产物(便于 Tree shaking\n优化),以及包含一份类型文件。\n\n对于源码中包含的样式文件,产物中提供样式的编译产物和样式的源文件。\n\n{\n \"main\": \"./dist/lib/index.js\", // bundleless type\n \"module\": \"./dist/es/index.js\", // bundleless type\n \"types\": \"./dist/types/index.d.ts\",\n};\n\n\n预设字符串对应的构建配置:\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './es',\n },\n {\n buildType: 'bundleless',\n outDir: './types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\n'NPM-COMPONENT-WITH-UMD'\n\n在类 NPM 包管理器下使用的组件(库),同时支持类 unpkg 的模式。 在预设 'npm-component' 的基础上,额外提供 umd 产物。\n\n{\n \"main\": \"./dist/lib/index.js\", // bundleless type\n \"module\": \"./dist/es/index.js\", // bundleless type\n \"types\": \"./dist/types/index.d.ts\",\n \"unpkg\": \"./dist/umd/index.js\",\n};\n\n\nexport const buildConfig = [\n {\n format: 'cjs',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './lib',\n },\n {\n format: 'esm',\n target: 'es6',\n buildType: 'bundleless',\n outDir: './es',\n },\n {\n format: 'umd',\n target: 'es6',\n buildType: 'bundle',\n outDir: './umd',\n },\n {\n buildType: 'bundleless',\n outDir: './types',\n dts: {\n only: true,\n },\n },\n];\n\n\n\n关于预设值支持的 ECMASCRIPT 版本以及 {ES5...ESNEXT}\n\n当想要使用支持其他 ECMAScript 版本的 buildPreset 预设的时候,可以直接在\n'npm-library'、'npm-library-with-umd'、'npm-component'、'npm-component-with-umd'\n这些预设值后面增加想要支持的版本。\n\n例如希望 'npm-library' 预设支持 'es2017',则可以按照如下方式配置:\n\n\n\nexport default defineConfig({\n buildPreset: 'npm-library-es2017',\n});\n\n\n\nFUNCTION\n\n函数的配置方式,可以通过 preset 参数获取到预设值,然后对里面的构建配置进行修改来自定义你的构建配置。\n以下是一个函数的配置方式的例子,它配置了压缩构建产物的功能:\n\n\n\nexport default defineConfig({\n buildPreset({ preset }) {\n const { NPM_LIBRARY } = preset;\n return NPM_LIBRARY.map(config => {\n config.minify = {\n compress: {\n drop_console: true,\n },\n };\n return config;\n });\n },\n});\n","frontmatter":{"sidebar_position":2}},{"id":32,"title":"DesignSystem","routePath":"/module-tools/api/config/design-system","toc":[{"id":"screens-3","text":"Screens","depth":2},{"id":"max-width-断点-1","text":"Max-width 断点","depth":3},{"id":"多个范围的断点-1","text":"多个范围的断点","depth":3},{"id":"自定义媒体查询-1","text":"自定义媒体查询","depth":3},{"id":"print-样式-1","text":"Print 样式","depth":3},{"id":"dark-mode-3","text":"Dark Mode","depth":3},{"id":"colors-3","text":"Colors","depth":2},{"id":"spacing-3","text":"Spacing","depth":2},{"id":"核心插件-1","text":"核心插件","depth":2},{"id":"自定义默认配置-1","text":"自定义默认配置","depth":2},{"id":"覆盖默认配置-1","text":"覆盖默认配置","depth":3},{"id":"扩展默认配置-1","text":"扩展默认配置","depth":3},{"id":"引用其他值-1","text":"引用其他值","depth":3},{"id":"禁用整个核心插件-1","text":"禁用整个核心插件","depth":3},{"id":"添加自己的-key-1","text":"添加自己的 key","depth":3},{"id":"配置引用-1","text":"配置引用","depth":2}],"content":"DESIGNSYSTEM\n\n本章描述了有关 designSystem 相关的配置\n\n需要先通过 pnpm run new 启用 Tailwind CSS 功能。\n\n * type: Object\n * default: 见下方配置详情。\n\nconst designSystem = {\n screens: {\n sm: '640px',\n md: '768px',\n lg: '1024px',\n xl: '1280px',\n },\n colors: {\n transparent: 'transparent',\n current: 'currentColor',\n\n black: '#000',\n white: '#fff',\n\n gray: {\n 100: '#f7fafc',\n 200: '#edf2f7',\n 300: '#e2e8f0',\n 400: '#cbd5e0',\n 500: '#a0aec0',\n 600: '#718096',\n 700: '#4a5568',\n 800: '#2d3748',\n 900: '#1a202c',\n },\n red: {\n 100: '#fff5f5',\n 200: '#fed7d7',\n 300: '#feb2b2',\n 400: '#fc8181',\n 500: '#f56565',\n 600: '#e53e3e',\n 700: '#c53030',\n 800: '#9b2c2c',\n 900: '#742a2a',\n },\n orange: {\n 100: '#fffaf0',\n 200: '#feebc8',\n 300: '#fbd38d',\n 400: '#f6ad55',\n 500: '#ed8936',\n 600: '#dd6b20',\n 700: '#c05621',\n 800: '#9c4221',\n 900: '#7b341e',\n },\n yellow: {\n 100: '#fffff0',\n 200: '#fefcbf',\n 300: '#faf089',\n 400: '#f6e05e',\n 500: '#ecc94b',\n 600: '#d69e2e',\n 700: '#b7791f',\n 800: '#975a16',\n 900: '#744210',\n },\n green: {\n 100: '#f0fff4',\n 200: '#c6f6d5',\n 300: '#9ae6b4',\n 400: '#68d391',\n 500: '#48bb78',\n 600: '#38a169',\n 700: '#2f855a',\n 800: '#276749',\n 900: '#22543d',\n },\n teal: {\n 100: '#e6fffa',\n 200: '#b2f5ea',\n 300: '#81e6d9',\n 400: '#4fd1c5',\n 500: '#38b2ac',\n 600: '#319795',\n 700: '#2c7a7b',\n 800: '#285e61',\n 900: '#234e52',\n },\n blue: {\n 100: '#ebf8ff',\n 200: '#bee3f8',\n 300: '#90cdf4',\n 400: '#63b3ed',\n 500: '#4299e1',\n 600: '#3182ce',\n 700: '#2b6cb0',\n 800: '#2c5282',\n 900: '#2a4365',\n },\n indigo: {\n 100: '#ebf4ff',\n 200: '#c3dafe',\n 300: '#a3bffa',\n 400: '#7f9cf5',\n 500: '#667eea',\n 600: '#5a67d8',\n 700: '#4c51bf',\n 800: '#434190',\n 900: '#3c366b',\n },\n purple: {\n 100: '#faf5ff',\n 200: '#e9d8fd',\n 300: '#d6bcfa',\n 400: '#b794f4',\n 500: '#9f7aea',\n 600: '#805ad5',\n 700: '#6b46c1',\n 800: '#553c9a',\n 900: '#44337a',\n },\n pink: {\n 100: '#fff5f7',\n 200: '#fed7e2',\n 300: '#fbb6ce',\n 400: '#f687b3',\n 500: '#ed64a6',\n 600: '#d53f8c',\n 700: '#b83280',\n 800: '#97266d',\n 900: '#702459',\n },\n },\n spacing: {\n px: '1px',\n 0: '0',\n 1: '0.25rem',\n 2: '0.5rem',\n 3: '0.75rem',\n 4: '1rem',\n 5: '1.25rem',\n 6: '1.5rem',\n 8: '2rem',\n 10: '2.5rem',\n 12: '3rem',\n 16: '4rem',\n 20: '5rem',\n 24: '6rem',\n 32: '8rem',\n 40: '10rem',\n 48: '12rem',\n 56: '14rem',\n 64: '16rem',\n },\n backgroundColor: theme => theme('colors'),\n backgroundOpacity: theme => theme('opacity'),\n backgroundPosition: {\n bottom: 'bottom',\n center: 'center',\n left: 'left',\n 'left-bottom': 'left bottom',\n 'left-top': 'left top',\n right: 'right',\n 'right-bottom': 'right bottom',\n 'right-top': 'right top',\n top: 'top',\n },\n backgroundSize: {\n auto: 'auto',\n cover: 'cover',\n contain: 'contain',\n },\n borderColor: theme => ({\n ...theme('colors'),\n default: theme('colors.gray.300', 'currentColor'),\n }),\n borderOpacity: theme => theme('opacity'),\n borderRadius: {\n none: '0',\n sm: '0.125rem',\n default: '0.25rem',\n md: '0.375rem',\n lg: '0.5rem',\n full: '9999px',\n },\n borderWidth: {\n default: '1px',\n 0: '0',\n 2: '2px',\n 4: '4px',\n 8: '8px',\n },\n boxShadow: {\n xs: '0 0 0 1px rgba(0, 0, 0, 0.05)',\n sm: '0 1px 2px 0 rgba(0, 0, 0, 0.05)',\n default: '0 1px 3px 0 rgba(0, 0, 0, 0.1), 0 1px 2px 0 rgba(0, 0, 0, 0.06)',\n md: '0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06)',\n lg: '0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05)',\n xl: '0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04)',\n '2xl': '0 25px 50px -12px rgba(0, 0, 0, 0.25)',\n inner: 'inset 0 2px 4px 0 rgba(0, 0, 0, 0.06)',\n outline: '0 0 0 3px rgba(66, 153, 225, 0.5)',\n none: 'none',\n },\n container: {},\n cursor: {\n auto: 'auto',\n default: 'default',\n pointer: 'pointer',\n wait: 'wait',\n text: 'text',\n move: 'move',\n 'not-allowed': 'not-allowed',\n },\n divideColor: theme => theme('borderColor'),\n divideOpacity: theme => theme('borderOpacity'),\n divideWidth: theme => theme('borderWidth'),\n fill: {\n current: 'currentColor',\n },\n flex: {\n 1: '1 1 0%',\n auto: '1 1 auto',\n initial: '0 1 auto',\n none: 'none',\n },\n flexGrow: {\n 0: '0',\n default: '1',\n },\n flexShrink: {\n 0: '0',\n default: '1',\n },\n fontFamily: {\n sans: [\n 'system-ui',\n '-apple-system',\n 'BlinkMacSystemFont',\n '\"Segoe UI\"',\n 'Roboto',\n '\"Helvetica Neue\"',\n 'Arial',\n '\"Noto Sans\"',\n 'sans-serif',\n '\"Apple Color Emoji\"',\n '\"Segoe UI Emoji\"',\n '\"Segoe UI Symbol\"',\n '\"Noto Color Emoji\"',\n ],\n serif: ['Georgia', 'Cambria', '\"Times New Roman\"', 'Times', 'serif'],\n mono: [\n 'Menlo',\n 'Monaco',\n 'Consolas',\n '\"Liberation Mono\"',\n '\"Courier New\"',\n 'monospace',\n ],\n },\n fontSize: {\n xs: '0.75rem',\n sm: '0.875rem',\n base: '1rem',\n lg: '1.125rem',\n xl: '1.25rem',\n '2xl': '1.5rem',\n '3xl': '1.875rem',\n '4xl': '2.25rem',\n '5xl': '3rem',\n '6xl': '4rem',\n },\n fontWeight: {\n hairline: '100',\n thin: '200',\n light: '300',\n normal: '400',\n medium: '500',\n semibold: '600',\n bold: '700',\n extrabold: '800',\n black: '900',\n },\n height: theme => ({\n auto: 'auto',\n ...theme('spacing'),\n full: '100%',\n screen: '100vh',\n }),\n inset: {\n 0: '0',\n auto: 'auto',\n },\n letterSpacing: {\n tighter: '-0.05em',\n tight: '-0.025em',\n normal: '0',\n wide: '0.025em',\n wider: '0.05em',\n widest: '0.1em',\n },\n lineHeight: {\n none: '1',\n tight: '1.25',\n snug: '1.375',\n normal: '1.5',\n relaxed: '1.625',\n loose: '2',\n 3: '.75rem',\n 4: '1rem',\n 5: '1.25rem',\n 6: '1.5rem',\n 7: '1.75rem',\n 8: '2rem',\n 9: '2.25rem',\n 10: '2.5rem',\n },\n listStyleType: {\n none: 'none',\n disc: 'disc',\n decimal: 'decimal',\n },\n margin: (theme, { negative }) => ({\n auto: 'auto',\n ...theme('spacing'),\n ...negative(theme('spacing')),\n }),\n maxHeight: {\n full: '100%',\n screen: '100vh',\n },\n maxWidth: (theme, { breakpoints }) => ({\n none: 'none',\n xs: '20rem',\n sm: '24rem',\n md: '28rem',\n lg: '32rem',\n xl: '36rem',\n '2xl': '42rem',\n '3xl': '48rem',\n '4xl': '56rem',\n '5xl': '64rem',\n '6xl': '72rem',\n full: '100%',\n ...breakpoints(theme('screens')),\n }),\n minHeight: {\n 0: '0',\n full: '100%',\n screen: '100vh',\n },\n minWidth: {\n 0: '0',\n full: '100%',\n },\n objectPosition: {\n bottom: 'bottom',\n center: 'center',\n left: 'left',\n 'left-bottom': 'left bottom',\n 'left-top': 'left top',\n right: 'right',\n 'right-bottom': 'right bottom',\n 'right-top': 'right top',\n top: 'top',\n },\n opacity: {\n 0: '0',\n 25: '0.25',\n 50: '0.5',\n 75: '0.75',\n 100: '1',\n },\n order: {\n first: '-9999',\n last: '9999',\n none: '0',\n 1: '1',\n 2: '2',\n 3: '3',\n 4: '4',\n 5: '5',\n 6: '6',\n 7: '7',\n 8: '8',\n 9: '9',\n 10: '10',\n 11: '11',\n 12: '12',\n },\n padding: theme => theme('spacing'),\n placeholderColor: theme => theme('colors'),\n placeholderOpacity: theme => theme('opacity'),\n space: (theme, { negative }) => ({\n ...theme('spacing'),\n ...negative(theme('spacing')),\n }),\n stroke: {\n current: 'currentColor',\n },\n strokeWidth: {\n 0: '0',\n 1: '1',\n 2: '2',\n },\n textColor: theme => theme('colors'),\n textOpacity: theme => theme('opacity'),\n width: theme => ({\n auto: 'auto',\n ...theme('spacing'),\n '1/2': '50%',\n '1/3': '33.333333%',\n '2/3': '66.666667%',\n '1/4': '25%',\n '2/4': '50%',\n '3/4': '75%',\n '1/5': '20%',\n '2/5': '40%',\n '3/5': '60%',\n '4/5': '80%',\n '1/6': '16.666667%',\n '2/6': '33.333333%',\n '3/6': '50%',\n '4/6': '66.666667%',\n '5/6': '83.333333%',\n '1/12': '8.333333%',\n '2/12': '16.666667%',\n '3/12': '25%',\n '4/12': '33.333333%',\n '5/12': '41.666667%',\n '6/12': '50%',\n '7/12': '58.333333%',\n '8/12': '66.666667%',\n '9/12': '75%',\n '10/12': '83.333333%',\n '11/12': '91.666667%',\n full: '100%',\n screen: '100vw',\n }),\n zIndex: {\n auto: 'auto',\n 0: '0',\n 10: '10',\n 20: '20',\n 30: '30',\n 40: '40',\n 50: '50',\n },\n gap: theme => theme('spacing'),\n gridTemplateColumns: {\n none: 'none',\n 1: 'repeat(1, minmax(0, 1fr))',\n 2: 'repeat(2, minmax(0, 1fr))',\n 3: 'repeat(3, minmax(0, 1fr))',\n 4: 'repeat(4, minmax(0, 1fr))',\n 5: 'repeat(5, minmax(0, 1fr))',\n 6: 'repeat(6, minmax(0, 1fr))',\n 7: 'repeat(7, minmax(0, 1fr))',\n 8: 'repeat(8, minmax(0, 1fr))',\n 9: 'repeat(9, minmax(0, 1fr))',\n 10: 'repeat(10, minmax(0, 1fr))',\n 11: 'repeat(11, minmax(0, 1fr))',\n 12: 'repeat(12, minmax(0, 1fr))',\n },\n gridColumn: {\n auto: 'auto',\n 'span-1': 'span 1 / span 1',\n 'span-2': 'span 2 / span 2',\n 'span-3': 'span 3 / span 3',\n 'span-4': 'span 4 / span 4',\n 'span-5': 'span 5 / span 5',\n 'span-6': 'span 6 / span 6',\n 'span-7': 'span 7 / span 7',\n 'span-8': 'span 8 / span 8',\n 'span-9': 'span 9 / span 9',\n 'span-10': 'span 10 / span 10',\n 'span-11': 'span 11 / span 11',\n 'span-12': 'span 12 / span 12',\n },\n gridColumnStart: {\n auto: 'auto',\n 1: '1',\n 2: '2',\n 3: '3',\n 4: '4',\n 5: '5',\n 6: '6',\n 7: '7',\n 8: '8',\n 9: '9',\n 10: '10',\n 11: '11',\n 12: '12',\n 13: '13',\n },\n gridColumnEnd: {\n auto: 'auto',\n 1: '1',\n 2: '2',\n 3: '3',\n 4: '4',\n 5: '5',\n 6: '6',\n 7: '7',\n 8: '8',\n 9: '9',\n 10: '10',\n 11: '11',\n 12: '12',\n 13: '13',\n },\n gridTemplateRows: {\n none: 'none',\n 1: 'repeat(1, minmax(0, 1fr))',\n 2: 'repeat(2, minmax(0, 1fr))',\n 3: 'repeat(3, minmax(0, 1fr))',\n 4: 'repeat(4, minmax(0, 1fr))',\n 5: 'repeat(5, minmax(0, 1fr))',\n 6: 'repeat(6, minmax(0, 1fr))',\n },\n gridRow: {\n auto: 'auto',\n 'span-1': 'span 1 / span 1',\n 'span-2': 'span 2 / span 2',\n 'span-3': 'span 3 / span 3',\n 'span-4': 'span 4 / span 4',\n 'span-5': 'span 5 / span 5',\n 'span-6': 'span 6 / span 6',\n },\n gridRowStart: {\n auto: 'auto',\n 1: '1',\n 2: '2',\n 3: '3',\n 4: '4',\n 5: '5',\n 6: '6',\n 7: '7',\n },\n gridRowEnd: {\n auto: 'auto',\n 1: '1',\n 2: '2',\n 3: '3',\n 4: '4',\n 5: '5',\n 6: '6',\n 7: '7',\n },\n transformOrigin: {\n center: 'center',\n top: 'top',\n 'top-right': 'top right',\n right: 'right',\n 'bottom-right': 'bottom right',\n bottom: 'bottom',\n 'bottom-left': 'bottom left',\n left: 'left',\n 'top-left': 'top left',\n },\n scale: {\n 0: '0',\n 50: '.5',\n 75: '.75',\n 90: '.9',\n 95: '.95',\n 100: '1',\n 105: '1.05',\n 110: '1.1',\n 125: '1.25',\n 150: '1.5',\n },\n rotate: {\n '-180': '-180deg',\n '-90': '-90deg',\n '-45': '-45deg',\n 0: '0',\n 45: '45deg',\n 90: '90deg',\n 180: '180deg',\n },\n translate: (theme, { negative }) => ({\n ...theme('spacing'),\n ...negative(theme('spacing')),\n '-full': '-100%',\n '-1/2': '-50%',\n '1/2': '50%',\n full: '100%',\n }),\n skew: {\n '-12': '-12deg',\n '-6': '-6deg',\n '-3': '-3deg',\n 0: '0',\n 3: '3deg',\n 6: '6deg',\n 12: '12deg',\n },\n transitionProperty: {\n none: 'none',\n all: 'all',\n default:\n 'background-color, border-color, color, fill, stroke, opacity, box-shadow, transform',\n colors: 'background-color, border-color, color, fill, stroke',\n opacity: 'opacity',\n shadow: 'box-shadow',\n transform: 'transform',\n },\n transitionTimingFunction: {\n linear: 'linear',\n in: 'cubic-bezier(0.4, 0, 1, 1)',\n out: 'cubic-bezier(0, 0, 0.2, 1)',\n 'in-out': 'cubic-bezier(0.4, 0, 0.2, 1)',\n },\n transitionDuration: {\n 75: '75ms',\n 100: '100ms',\n 150: '150ms',\n 200: '200ms',\n 300: '300ms',\n 500: '500ms',\n 700: '700ms',\n 1000: '1000ms',\n },\n transitionDelay: {\n 75: '75ms',\n 100: '100ms',\n 150: '150ms',\n 200: '200ms',\n 300: '300ms',\n 500: '500ms',\n 700: '700ms',\n 1000: '1000ms',\n },\n};\n\n\n更多关于TailwindCSS 配置\n\ndesignSystem 用于定义项目的调色板、排版比例(Typographic Scales 或者 Type\nScale)、字体列表、断点、边框圆角值等等。因为 Modern.js 借用了 Tailwind Theme 的设计方式,并且内部也集成了 Tailwind\nCSS,所以 designSystem 使用方式与 Tailwind CSS Theme 相同\n\ndesignSystem 对象包含 screens、colors 和 spacing 的属性,以及每个可自定义核心插件。\n\n\nSCREENS\n\n使用screens 可以自定义项目中的响应断点:\n\nconst designSystem = {\n screens: {\n sm: '640px',\n md: '768px',\n lg: '1024px',\n xl: '1280px',\n },\n};\n\n\n其中 screens 对象里的属性名是屏幕名称(用作 Tailwind CSS 生成的自适应实用程序变体的前缀,例如\nmd:text-center),值是该断点应在其开始的 min-width。\n\n默认断点受常见设备分辨率的启发:\n\nconst designSystem = {\n screens: {\n sm: '640px',\n // => @media (min-width: 640px) { ... }\n\n md: '768px',\n // => @media (min-width: 768px) { ... }\n\n lg: '1024px',\n // => @media (min-width: 1024px) { ... }\n\n xl: '1280px',\n // => @media (min-width: 1280px) { ... }\n },\n};\n\n\n你可以在你的项目中使用任意你喜欢的名称作为断点的属性:\n\nconst designSystem = {\n screens: {\n tablet: '640px',\n // => @media (min-width: 640px) { ... }\n\n laptop: '1024px',\n // => @media (min-width: 1024px) { ... }\n\n desktop: '1280px',\n // => @media (min-width: 1280px) { ... }\n },\n};\n\n\n这些屏幕名称反映在 utilities 中,因此 text-center 现在是这样的:\n\n.text-center {\n text-align: center;\n}\n\n@media (min-width: 640px) {\n .tablet\\:text-center {\n text-align: center;\n }\n}\n\n@media (min-width: 1024px) {\n .laptop\\:text-center {\n text-align: center;\n }\n}\n\n@media (min-width: 1280px) {\n .desktop\\:text-center {\n text-align: center;\n }\n}\n\n\n\nMAX-WIDTH 断点\n\n如果要使用 max-width 断点而不是 min-width,可以将屏幕指定为具有 max 属性的对象:\n\nconst designSystem = {\n screens: {\n xl: { max: '1279px' },\n // => @media (max-width: 1279px) { ... }\n\n lg: { max: '1023px' },\n // => @media (max-width: 1023px) { ... }\n\n md: { max: '767px' },\n // => @media (max-width: 767px) { ... }\n\n sm: { max: '639px' },\n // => @media (max-width: 639px) { ... }\n },\n};\n\n\n如有必要,以创建带有 min-width 和 max-width 定义的断点,例如:\n\nconst designSystem = {\n screens: {\n sm: { min: '640px', max: '767px' },\n md: { min: '768px', max: '1023px' },\n lg: { min: '1024px', max: '1279px' },\n xl: { min: '1280px' },\n },\n};\n\n\n\n多个范围的断点\n\n有时,将单个断点定义应用于多个范围会很有用。\n\n例如,假设您有一个 sidebar,并且希望断点基于内容区域宽度而不是整个视口。您可以模拟这种情况,当 sidebar\n可见并缩小内容区域时,断点的样式使用较小的断点样式:\n\nconst designSystem = {\n screens: {\n sm: '500px',\n md: [\n // Sidebar appears at 768px, so revert to `sm:` styles between 768px\n // and 868px, after which the main content area is wide enough again to\n // apply the `md:` styles.\n { min: '668px', max: '767px' },\n { min: '868px' },\n ],\n lg: '1100px',\n xl: '1400px',\n },\n};\n\n\n\n自定义媒体查询\n\n如果需要为断点提供完全自定义的媒体查询,则可以使用带有 raw 属性的对象:\n\nconst designSystem = {\n extend: {\n screens: {\n portrait: { raw: '(orientation: portrait)' },\n // => @media (orientation: portrait) { ... }\n },\n },\n};\n\n\n\nPRINT 样式\n\n如果需要为打印应用不同的样式,则 raw 选项可能特别有用。\n\n需要做的就是在 designSystem.extend.screens 下添加一个 print:\n\nconst designSystem = {\n extend: {\n screens: {\n print: { raw: 'print' },\n // => @media print { ... }\n },\n },\n};\n\n\n然后,可以使用诸如 print:text-black 之类的类来指定仅当某人尝试打印页面时才应用的样式:\n\n<div class=\"text-gray-700 print:text-black\">\n <!-- ... -->\n</div>\n\n\n\nDARK MODE\n\nraw 选项可以用于实现 “暗模式” 屏幕:\n\nconst designSystem = {\n extend: {\n screens: {\n dark: { raw: '(prefers-color-scheme: dark)' },\n // => @media (prefers-color-scheme: dark) { ... }\n },\n },\n};\n\n\n然后,您可以使用 dark: 前缀在暗模式下为元素设置不同的样式:\n\n<div class=\"text-gray-700 dark:text-gray-200\">\n <!-- ... -->\n</div>\n\n\n请注意,由于这些 screen variants 是在 Tailwind CSS 中实现的,因此无法使用这种方法将断点与暗模式结合使用 ,例如\nmd:dark:text-gray-300 将不起作用。\n\n\nCOLORS\n\ncolors 属性可让您自定义项目的全局调色板。\n\nconst designSystem = {\n colors: {\n transparent: 'transparent',\n black: '#000',\n white: '#fff',\n gray: {\n 100: '#f7fafc',\n // ...\n 900: '#1a202c',\n },\n\n // ...\n },\n};\n\n\n默认情况下,这些颜色由 backgroundColor,textColor 和 borderColor 核心插件继承。\n\n想了解更多,可以查看:Customizing Colors。\n\n\nSPACING\n\n使用 space 属性,可以自定义项目的全局间距和缩放比例:\n\nconst designSystem = {\n spacing: {\n px: '1px',\n 0: '0',\n 1: '0.25rem',\n 2: '0.5rem',\n 3: '0.75rem',\n 4: '1rem',\n 5: '1.25rem',\n 6: '1.5rem',\n 8: '2rem',\n 10: '2.5rem',\n 12: '3rem',\n 16: '4rem',\n 20: '5rem',\n 24: '6rem',\n 32: '8rem',\n 40: '10rem',\n 48: '12rem',\n 56: '14rem',\n 64: '16rem',\n },\n};\n\n\n默认情况下,这些值由 padding,margin,negativeMargin,width 和 height 核心插件继承。\n\n想要了解更多,看 Customizing Spacing。\n\n\n核心插件\n\n主题部分的其余部分用于配置每个核心插件可用的值。\n\n例如,borderRadius 属性可让您自定义将生成的圆角的 utilities:\n\nconst designSystem = {\n borderRadius: {\n none: '0',\n sm: '.125rem',\n default: '.25rem',\n lg: '.5rem',\n full: '9999px',\n },\n};\n\n\n属性名确定所生成类的后缀,值确定实际 CSS 声明的值。 上面的示例borderRadius配置将生成以下 CSS 类:\n\n.rounded-none {\n border-radius: 0;\n}\n.rounded-sm {\n border-radius: 0.125rem;\n}\n.rounded {\n border-radius: 0.25rem;\n}\n.rounded-lg {\n border-radius: 0.5rem;\n}\n.rounded-full {\n border-radius: 9999px;\n}\n\n\n会注意到,在主题配置中使用 default 属性创建了不带后缀的 rounded 类。这是许多(尽管不是全部)核心插件支持的 Tailwind CSS\n中的通用约定。\n\n要了解有关自定义特定核心插件的更多信息,请访问该插件的文档。\n\n\n自定义默认配置\n\n开箱即用,您的项目将自动从默认主题配置继承值。如果想自定义默认主题,则根据目标有几种不同的选择。\n\n\n覆盖默认配置\n\n要覆盖默认配置中的选项,请在 designSystem 中添加要覆盖的属性:\n\n\n\nconst designSystem = {\n // Replaces all of the default `opacity` values\n opacity: {\n 0: '0',\n 20: '0.2',\n 40: '0.4',\n 60: '0.6',\n 80: '0.8',\n 100: '1',\n },\n};\n\nexport default defineConfig({\n designSystem,\n});\n\n\n这将完全替换默认属性配置,因此在上面的示例中,不会生成默认的 opacity utilities。\n\n您未提供的任何属性都将从默认主题继承,因此在上面的示例中,将保留颜色,间距,边框圆角,背景位置等内容的默认主题配置。\n\n\n扩展默认配置\n\n如果您想保留主题选项的默认值,但又要添加新值,请在 designSystem.extend 属性下添加扩展的内容。\n\n例如,如果您想添加一个额外的断点但保留现有的断点,则可以扩展 screens 属性:\n\n\n\nconst designSystem = {\n extend: {\n // Adds a new breakpoint in addition to the default breakpoints\n screens: {\n '2xl': '1440px',\n },\n },\n};\n\nexport default defineConfig({\n designSystem,\n});\n\n\n您当然可以覆盖默认主题的某些部分,并在同一配置中扩展默认主题的其他部分:\n\n\n\nconst designSystem = {\n opacity: {\n 0: '0',\n 20: '0.2',\n 40: '0.4',\n 60: '0.6',\n 80: '0.8',\n 100: '1',\n },\n extend: {\n screens: {\n '2xl': '1440px',\n },\n },\n};\n\nexport default defineConfig({\n designSystem,\n});\n\n\n\n引用其他值\n\n如果需要在配置中引用另一个值,可以通过提供闭包函数而不是静态值来实现。函数将收到 theme() 函数作为参数,您可以使用该函数使用点表示法在配置中查找其他值。\n\n例如,您可以在 fill 配置上通过引用 theme('colors') 为调色板中的每种颜色生成 fill utilities。\n\n\n\nconst designSystem = {\n colors: {\n // ...\n },\n fill: theme => theme('colors'),\n};\n\nexport default defineConfig({\n designSystem,\n});\n\n\ntheme()函数尝试从已经完全合并的配置对象中找到您要查找的值,因此它可以引用您自己的自定义设置以及默认主题值。它也可以递归工作,因此只要链末尾有一个静态值,\n它就可以解析您要查找的值。\n\n引用默认配置\n\n如果出于任何原因想要引用默认配置中的值,则可以从 tailwindcss/defaultTheme\n导入它。一个有用的示例是,如果要将添加默认配置提供的字体中某一个字体:\n\n\n\nconst defaultTheme = require('tailwindcss/defaultTheme');\n\nconst designSystem = {\n extend: {\n fontFamily: {\n sans: ['Lato', ...defaultTheme.fontFamily.sans],\n },\n },\n};\n\nexport default defineConfig({\n designSystem,\n});\n\n\n\n禁用整个核心插件\n\n如果您不想为某个核心插件生成任何类,则最好在 corePlugins 配置中将该插件设置为 false,而不是在配置中为该属性提供一个空对象:\n\n// Don't assign an empty object in your theme configuration\n\nconst designSystem = {\n opacity: {},\n};\n\n// Do disable the plugin in your corePlugins configuration\nconst designSyttem = {\n corePlugins: {\n opacity: false,\n },\n};\n\n\n最终结果是相同的,但是由于许多核心插件未公开任何配置,因此无论如何只能使用 corePlugins 禁用它们,最好保持一致。\n\n\n添加自己的 KEY\n\n在很多情况下,将自己的属性添加到配置对象可能会很有用。\n\n其中一个示例是添加新属性为多个核心插件之间复用。例如,您可以提取一个 positions对象,backgroundPosition 和\nobjectPosition 插件都可以引用该对象:\n\nconst designSystem = {\n positions: {\n bottom: 'bottom',\n center: 'center',\n left: 'left',\n 'left-bottom': 'left bottom',\n 'left-top': 'left top',\n right: 'right',\n 'right-bottom': 'right bottom',\n 'right-top': 'right top',\n top: 'top',\n },\n backgroundPosition: theme => theme('positions'),\n objectPosition: theme => theme('positions'),\n};\n\n\n另一个示例是在自定义插件中添加新的属性以进行引用。例如,如果您为项目编写了渐变插件,则可以向该插件引用的主题对象添加渐变属性:\n\n\n\nconst designSystem = {\n gradients: theme => ({\n 'blue-green': [theme('colors.blue.500'), theme('colors.green.500')],\n 'purple-blue': [theme('colors.purple.500'), theme('colors.blue.500')],\n // ...\n }),\n};\n\nexport default defineConfig({\n designSystem,\n buildConfig: {\n style: {\n postcss: {\n plugins: [require('./plugins/gradients')],\n },\n },\n },\n});\n\n\n\n配置引用\n\n除了 screens,colors 和 spacing 外,配置对象中的所有属性都映射到 Tailwind CSS\n的核心插件上。由于许多插件负责仅接受静态值集(例如,例如float)的 CSS 属性,因此请注意,并非每个插件在主题对象中都有对应的属性。\n\n所有这些属性也可以在 designSystem.extend 属性下使用,以扩展默认主题。\n\n关于所有属性的作用,可以查看此 链接。","frontmatter":{"sidebar_position":3}},{"id":33,"title":"Plugins","routePath":"/module-tools/api/config/plugins","toc":[],"content":"PLUGINS\n\n本章介绍注册 module-tools 插件的配置。\n\n * type:Array<ModuleToolsPlugin>\n\n\nexport default defineConfig({\n plugins: [examplePlugin()],\n});\n\n\n关于如何编写插件,可以查看【插件编写指南】。","frontmatter":{"sidebar_position":4}},{"id":34,"title":"Testing","routePath":"/module-tools/api/config/testing","toc":[{"id":"jest-3","text":"jest","depth":2},{"id":"transformer-3","text":"transformer","depth":2}],"content":"TESTING\n\n本章描述了测试相关的配置。\n\n需要先通过 pnpm run new 启用 单元测试 功能。\n\n\nJEST\n\n * 类型: Object | Function\n * 默认值:{}\n\n对应 Jest 的配置,当为 Object 类型时,可以配置 Jest 所支持的所有底层配置 。\n\n\n\nexport default defineConfig({\n testing: {\n jest: {\n testTimeout: 10000,\n },\n },\n});\n\n\n值为 Function 类型时,默认配置作为第一个参数传入,需要返回新的 Jest 配置对象。\n\n\n\nexport default defineConfig({\n testing: {\n jest: options => {\n return {\n ...options,\n testTimeout: 10000,\n };\n },\n },\n});\n\n\n\nTRANSFORMER\n\n * 类型:'babel-jest' | 'ts-jest'\n * 默认值:'babel-jest'\n\n配置执行测试的时候对于源码的编译工具: babel-jest 或 ts-jest。默认使用 babel-jest。\n\nbabel-jest 也可以编译 TS 文件,但不会类型报错,如果你需要跑测试的时候对 TS 类型进行校验,那么请使用 ts-jest。","frontmatter":{"sidebar_position":5}},{"id":35,"title":"index","routePath":"/module-tools/api/","toc":[],"content":"INDEX","frontmatter":{"overview":true,"sidebar_label":"概览","sidebar_position":1}},{"id":36,"title":"Plugin Hooks","routePath":"/module-tools/api/plugin-api/plugin-hooks","toc":[{"id":"构建钩子-1","text":"构建钩子","depth":2},{"id":"beforebuild-3","text":"beforeBuild","depth":3},{"id":"beforebuildtask-3","text":"beforeBuildTask","depth":3},{"id":"afterbuildtask-3","text":"afterBuildTask","depth":3},{"id":"afterbuild-3","text":"afterBuild","depth":3},{"id":"buildplatform-钩子-1","text":"buildPlatform 钩子","depth":2},{"id":"registerbuildplatform-3","text":"registerBuildPlatform","depth":3},{"id":"beforebuildplatform-3","text":"beforeBuildPlatform","depth":3},{"id":"buildplatform-3","text":"buildPlatform","depth":3},{"id":"afterbuildplatform-3","text":"afterBuildPlatform","depth":3},{"id":"调试钩子-1","text":"调试钩子","depth":2},{"id":"registerdev-3","text":"registerDev","depth":3},{"id":"beforedev-3","text":"beforeDev","depth":3},{"id":"beforeafterdevmenu-3","text":"(before|after)DevMenu","depth":3},{"id":"beforedevtask-3","text":"beforeDevTask","depth":3},{"id":"afterdev-3","text":"afterDev","depth":3}],"content":"PLUGIN HOOKS\n\n本章介绍关于 module-tools 支持的生命周期钩子。\n\n目前主要包含两类生命周期钩子:\n\n * 构建钩子:仅在执行 build 命令构建源码产物时触发。\n * buildPlatform 钩子:仅在执行 build --platform 命令生成其他构建产物时触发。\n * 调试钩子:运行 dev 命令时会触发的钩子。\n\n\n构建钩子\n\n在执行 build 命令的时候,会按照顺序触发以下 Hooks:\n\n * beforeBuild\n * beforeBuildTask\n * afterBuildTask\n * afterBuild\n\n\nBEFOREBUILD\n\n执行整体构建流程之前触发。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuild(options: Options): Return {\n return options.config;\n },\n };\n },\n});\n\n\n参数和返回值类型:\n\ntype Options = {\n options: { config: BuildConfig; cliOptions: BuildCommandOptions };\n};\n\nexport interface BuildCommandOptions {\n config: string;\n clear?: boolean;\n dts?: boolean;\n platform?: boolean | string[];\n tsconfig: string;\n watch?: boolean;\n}\n\ntype Return = BuildConfig;\n\n\n> BuildConfig 类型参考 API 配置\n\n\nBEFOREBUILDTASK\n\n根据构建配置,Module Tools 会将整体构建分成多个子构建任务。该 Hook 将会在每一个构建子任务之前触发。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuildTask(config: BaseBuildConfig): BaseBuildConfig {\n return config;\n },\n };\n },\n});\n\n\n参数和返回值类型:\n\nBaseBuildConfig 类型参考 API 配置。\n\n\nAFTERBUILDTASK\n\n每一个构建子任务结束之后触发。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuildTask(options: BuildTaskResult): void {\n // ...\n },\n };\n },\n});\n\n\n参数和返回值类型:\n\nexport interface BuildTaskResult {\n status: 'success' | 'fail';\n message?: string;\n config: BaseBuildConfig;\n}\n\n\n\nAFTERBUILD\n\n整体构建流程结束之后触发。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuild(options: BuildResult): void {\n // ...\n },\n };\n },\n});\n\n\n参数和返回值类型:\n\nexport interface BuildResult {\n status: 'success' | 'fail';\n message?: string;\n config: BuildConfig;\n commandOptions: BuildCommandOptions;\n totalDuration: number;\n}\n\n\n\nBUILDPLATFORM 钩子\n\nmodule-tools 还提供了 build --platform 命令来执行特定的构建任务。\n\n例如在安装了 Storybook 插件后,就可以执行 build --platform 或者 build --platform storybook 来执行\nStorybook 的构建任务。因为 Storybook 插件基于 buildPlatform Hooks 实现了该功能。\n\n在执行 build --platform 后会按照以下顺序触发 Hooks:\n\n * registerBuildPlatform\n * beforeBuildPlatform\n * buildPlatform\n * afterBuildPlatform\n\n\nREGISTERBUILDPLATFORM\n\n获取在执行 build --platform 命令时候需要运行的任务信息。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n registerBuildPlatform(): RegisterBuildPlatformResult {\n // ...\n return {\n platform: 'stroybook',\n build() {\n // run storybook logic\n },\n };\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface RegisterBuildPlatformResult {\n platform: string | string[];\n build: (\n currentPlatform: string, // 当前运行的 platform 构建任务\n context: { isTsProject: boolean },\n ) => void | Promise<void>;\n}\n\n\n\nBEFOREBUILDPLATFORM\n\n当执行 build --platform 命令的时候,会触发所有已注册的构建任务。beforeBuildPlatform 会在执行整体的构建任务之前触发。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeBuildPlatform(platforms: RegisterBuildPlatformResult[]): void {\n console.info(`have ${platforms.length} platform tasks`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface RegisterBuildPlatformResult {\n platform: string | string[];\n build: (\n currentPlatform: string, // 当前运行的 platform 构建任务\n context: { isTsProject: boolean },\n ) => void | Promise<void>;\n}\n\n\n\nBUILDPLATFORM\n\n当执行 build --platform 命令的时候,会触发所有已注册的构建任务。buildPlatform 会在每个构建任务执行之前触发。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n buildPlatform({ platform }: Options): void {\n console.info(`current task is ${platform}`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface Options {\n platform: string;\n}\n\n\n\nAFTERBUILDPLATFORM\n\n当执行 build --platform 命令的时候,会触发所有已注册的构建任务。afterBuildPlatform 会在整体 platform\n构建任务结束后触发。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterBuildPlatform(result: BuildPlatformResult): void {\n if (result.status === 'success') {\n console.info(`all platform build task success`);\n } else {\n console.error(result.message);\n }\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface BuildPlatformResult {\n status: 'success' | 'fail';\n message: string | Error | null;\n}\n\n\n\n调试钩子\n\n在执行 dev 命令的时候,会按照顺序触发以下 Hooks:\n\n * registerDev: 在获取调试功能信息的时候触发。\n * beforeDev: 开始执行调试整体流程之前触发。\n * beforeDevMenu: 出现调试列表/菜单之前触发。\n * afterDevMenu: 选择调试列表/菜单选项后触发。\n * beforeDevTask: 执行调试任务之前触发。\n * afterDev: 执行 dev 整体流程最后触发。\n\n\nREGISTERDEV\n\n注册调试工具相关的数据。主要包含:\n\n * 调试工具的名称\n * 显示在菜单列表中的项目名称以及对应的值。\n * dev 子命令的定义。\n * 是否在运行调试任务之前执行源码构建\n * 执行调试任务的函数。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n registerDev() {\n return {\n // 调试工具名称\n name: 'storybook',\n // 菜单显示内容\n menuItem: {\n name: 'Storybook',\n value: 'storybook',\n },\n // 定义的 dev 子命令\n subCommands: ['storybook', 'story'],\n async action() {\n // dev logic\n },\n };\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n // 在 dev 命令执行之前,是否关闭源码构建\n disableRunBuild?: boolean;\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise<void>;\n}\n\n\n在调试项目的时候,如果仅需要对代码功能进行调试的话,也许可以设置 disableRunBuild: true 来关闭对于源码执行(监听模式下的)构建任务。\n\n目前支持的 Storybook 调试支持将源码产物作为调试对象,因此在 Storybook 插件中 disableRunBuild: false。\n\n\nBEFOREDEV\n\n在收集完所有调试工具元数据后,执行 dev 任务之前触发。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDev(metas: DevToolData[]) {\n console.info(`have ${metas.length} dev tools`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n // 在 dev 命令执行之前,是否关闭源码构建\n disableRunBuild?: boolean;\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise<void>;\n}\n\n\n\n(BEFORE|AFTER)DEVMENU\n\nbeforeDevMenu 在出现调试列表/菜单之前触发。接收 inquirer question 作为参数。默认值为:\n\nconst question = [\n {\n name: 'choiceDevTool',\n message: '选择调试工具',\n type: 'list',\n // 注册的调试信息\n choices,\n },\n];\n\n\nafterDevMenu 选择调试列表/菜单选项后触发。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDevMenu(questions) {\n questions[0].message += '!';\n return questions; // required\n },\n afterDevMenu(options: Options) {\n console.info(`choise ${options.result.choiceDevTool} dev tools`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport type { QuestionCollection } from 'inquirer';\n\nexport interface Options {\n result: PromptResult;\n devTools: DevToolData[];\n}\n\nexport type PromptResult = { choiceDevTool: string };\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n // 在 dev 命令执行之前,是否关闭源码构建\n disableRunBuild?: boolean;\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise<void>;\n}\n\n\n\nBEFOREDEVTASK\n\n执行调试任务之前触发。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n beforeDevTask(currentDevData: DevToolData) {\n console.info(`${currentDevData.name} running`);\n },\n };\n },\n});\n\n\n入参和返回的参数类型:\n\nexport interface DevToolData {\n name: string;\n subCommands?: string[];\n menuItem?: {\n name: string;\n value: string;\n };\n // 在 dev 命令执行之前,是否关闭源码构建\n disableRunBuild?: boolean;\n action: (\n options: { port?: string },\n context: { isTsProject?: boolean },\n ) => void | Promise<void>;\n}\n\n\n\nAFTERDEV\n\n在中断调试任务进程时触发。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n return {\n afterDev() {\n console.info(`exit!`);\n },\n };\n },\n});\n","frontmatter":{}},{"id":37,"title":"处理静态资源文件","routePath":"/module-tools/guide/advance/asset","toc":[{"id":"默认行为-1","text":"默认行为","depth":2},{"id":"设置-cdn-前缀-1","text":"设置 CDN 前缀","depth":2}],"content":"处理静态资源文件\n\n模块工程会对代码中使用的静态资源进行处理。如果需要配置,则可以使用 buildConfig.asset API。\n\n\n默认行为\n\n默认情况下,模块工程对于以下静态资源会进行处理:\n\n * '.svg'、'.png'、'.jpg'、'.jpeg'、'.gif'、'.webp'\n * '.ttf'、'.otf'、'.woff'、'.woff2'、'.eot'\n * '.mp3'、'.mp4'、'.webm'、'.ogg'、'.wav'、'.flac'、'.aac'、'.mov'\n\n对于静态文件的处理,模块工程目前支持的功能有:\n\n * 设置静态资源路径为 ./assets。\n * 对于超过 10kb 的文件会内联到代码中。\n\n让我们看下面的例子:\n\n<CH.Spotlight>\n\n\n//...\n\n\n--------------------------------------------------------------------------------\n\n项目源代码。\n\n\n//...\n\n\n--------------------------------------------------------------------------------\n\n如果 bg.png 的大小小于 10 kb,则此时产物目录结构和产物内容为。\n\n<CH.Code>\n\n./dist\n└── asset.js\n\n\n--------------------------------------------------------------------------------\n\nvar bg_default = 'data:image/png;base64,';\nconsole.info(bg_default);\n\n\n</CH.Code>\n\n如果 bg.png 的大小大于 10 kb,则此时产物目录结构和产物内容为。\n\n<CH.Code>\n\n./dist\n├── asset.js\n└── assets\n └── bg.13e2aba2.png\n\n\n--------------------------------------------------------------------------------\n\nvar bg_default = 'assets/bg.13e2aba2.png';\nconsole.info(bg_default);\n\n\n</CH.Code>\n\n</CH.Spotlight>\n\n当想要修改默认行为的时候,可以使用以下 API:\n\n * asset.path:修改静态资源文件输出路径。\n * asset.limit:修改内联静态资源文件的阈值。\n\n\n设置 CDN 前缀\n\n如果项目运行的环境是在浏览器下,我们有可能需要静态资源托管至 CDN,然后在生产环境使用。\n\n那么此时默认生成的构建产物中,我们需要在静态资源文件的路径前面增加 CDN 的基础路径。还是看一个例子:\n\n<CH.Spotlight>\n\n\n//...\n\n\n--------------------------------------------------------------------------------\n\n项目源代码。\n\n\n\n--------------------------------------------------------------------------------\n\nmodern.config 配置为。\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n asset: {\n publicPath: 'https://cdn/',\n },\n },\n});\n\n\n--------------------------------------------------------------------------------\n\n如果 bg.png 的大小大于 10 kb,则此时产物内容为。\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory();\n else if (typeof define === 'function' && define.amd) define([], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory();\n})(this, function () {\n 'use strict';\n var bg_default = 'http://cdn/assets/bg.13e2aba2.png';\n // src/asset.tsx\n console.info(bg_default);\n});\n\n\n</CH.Spotlight>","frontmatter":{"sidebar_position":7}},{"id":38,"title":"构建 umd 产物","routePath":"/module-tools/guide/advance/build-umd","toc":[{"id":"umd-产物的第三方依赖处理-1","text":"umd 产物的第三方依赖处理","depth":2},{"id":"更改项目的全局变量名称-1","text":"更改项目的全局变量名称","depth":2}],"content":"构建 UMD 产物\n\numd 全称为 Universal Module Definition,这种格式的 JS 文件可以运行在多个运行环境:\n\n * 浏览器环境:基于 AMD 规范进行模块加载\n * Node.js 环境:基于 CommonJS 进行模块加载\n * 其他情况:将模块挂载在全局对象上。\n\n因此我们可以通过下面的方式,将项目的构建产物指定为 umd 产物:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n },\n});\n\n\n\nUMD 产物的第三方依赖处理\n\n在 【如何处理第三方依赖】 章节中,我们知道可以通过 autoExternals 和 externals API 来控制项目是否对第三方依赖打包。 因此在构建\numd 产物的过程中,我们也可以这样使用:\n\n<CH.Spotlight>\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n //...other dependencies\n }\n}\n\n\n--------------------------------------------------------------------------------\n\n如果项目依赖了 react。\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n //...other dependencies\n }\n}\n\n\n--------------------------------------------------------------------------------\n\nmodern.config.ts 配置。\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n autoExternal: false,\n externals: ['react'],\n },\n});\n\n\n--------------------------------------------------------------------------------\n\n当源码中使用了 react 依赖。\n\n\nconsole.info(React);\n\n\n--------------------------------------------------------------------------------\n\n此时产物中不会将 react 代码打包到产物中。\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports, require('react'));\n else if (typeof define === 'function' && define.amd)\n define(['exports', 'react'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.index = {}), global.react);\n})(this, function (exports, _react) {\n 'use strict';\n Object.defineProperty(exports, '__esModule', {\n value: true,\n });\n _react = /*#__PURE__*/ _interopRequireDefault(_react);\n function _interopRequireDefault(obj) {\n return obj && obj.__esModule\n ? obj\n : {\n default: obj,\n };\n }\n console.info(_react.default);\n});\n\n\n</CH.Spotlight>\n\n通过上面的例子我们知道,当使用 autoExternal 和 externals API 后:\n\n * 在 Node.js 环境下,可以通过 require('react') 获取 react 依赖。\n * 在 浏览器环境下,可以通过 global.react 获取 react 依赖。\n\n然而在浏览器环境下,获取第三方依赖的时候,全局变量名称不一定与依赖名称完全相同,此时就要使用 buildConfig.umdGlobals API。\n\n还是使用之前的例子,当 react 依赖以 windows.React 或者 global.React 全局变量的形式存在于浏览器环境下,那么此时:\n\n<CH.Spotlight>\n\n{\n \"devDependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\n--------------------------------------------------------------------------------\n\n如果项目依赖了 react。\n\n{\n \"devDependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\n--------------------------------------------------------------------------------\n\nmodern.config.ts 配置。\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdGlobals: {\n react: 'React',\n },\n },\n});\n\n\n--------------------------------------------------------------------------------\n\n当源码中使用了 react 依赖。\n\n\nconsole.info(React);\n\n\n--------------------------------------------------------------------------------\n\n此时我们会看到这样的产物代码。\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory();\n else if (typeof define === 'function' && define.amd) define([], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory();\n})(this, function () {\n // ...\n // libuild:globals:react\n var require_react = __commonJS({\n 'libuild:globals:react'(exports, module1) {\n module1.exports = Function('return this')()['React'];\n },\n });\n // src/index.ts\n var import_react = __toESM(require_react());\n console.info(import_react.default);\n});\n\n\n</CH.Spotlight>\n\n此时项目就可以运行在浏览器中,并使用存在于全局对象上的 React 变量了。\n\n\n更改项目的全局变量名称\n\n当我们将下面的代码打包成 umd 产物并运行在浏览器的时候,我们可以通过 window.index 来使用该模块。\n\nexport default () => {\n console.info('hello world');\n};\n\n\n默认情况下,以源码文件名称作为该模块在浏览器里全局变量的名称。对于上面的例子,其产物内容如下:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports);\n else if (typeof define === 'function' && define.amd)\n define(['exports'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.index = {}));\n})(this, function (exports) {\n //...\n});\n\n\n如果需要修改它,则需要使用 buildConfig.umdModuleName API。\n\n当使用该 API 后:\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n umdModuleName: 'myLib',\n },\n});\n\n\n此时构建产物的内容为:\n\n(function (global, factory) {\n if (typeof module === 'object' && typeof module.exports === 'object')\n factory(exports);\n else if (typeof define === 'function' && define.amd)\n define(['exports'], factory);\n else if (\n (global = typeof globalThis !== 'undefined' ? globalThis : global || self)\n )\n factory((global.myLib = {}));\n})(this, function (exports) {\n //...\n});\n","frontmatter":{"sidebar_position":5}},{"id":39,"title":"使用 Copy 工具","routePath":"/module-tools/guide/advance/copy","toc":[{"id":"了解-copy-api-1","text":"了解 Copy API","depth":2},{"id":"api-详解-1","text":"API 详解","depth":2},{"id":"不同场景使用示例-3","text":"不同场景使用示例","depth":2},{"id":"将文件复制文件-3","text":"将文件复制文件","depth":3},{"id":"将文件复制到目录-3","text":"将文件复制到目录","depth":3},{"id":"从目录复制到目录-3","text":"从目录复制到目录","depth":3},{"id":"从目录到文件-3","text":"从目录到文件","depth":3},{"id":"使用-glob-3","text":"使用 Glob","depth":3}],"content":"使用 COPY 工具\n\n模块工程提供了 Copy 工具用于将已经存在的单个文件或整个目录复制到产物目录中。接下来我们学习如何使用它。\n\n\n了解 COPY API\n\n我们可以通过 buildConfig.copy API 来使用 Copy 工具,它包含以下两个主要配置:\n\n * patterns\n * options\n\n在开始学习之前可以先花一些时间了解它们。\n\n\nAPI 详解\n\ncopy.patterns 用于寻找复制的文件以及配置输出的路径。\n\n其中 patterns.from 用于指定要复制的文件或者目录。它接收 Glob 形式字符串或具体路径。Glob 形式字符串是指 fast-glob\npattern-syntax。因此我们可以按照如下两种方式使用它:\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n { from: './index.html', to: '' },\n { from: './*.html', to: '' },\n ],\n },\n },\n});\n\n\npatterns.context 一般和 patterns.from 配合使用,默认情况下它的值与 buildConfig.sourceDir\n相同,因此我们可以按照如下方式指定 src/data.json 文件为要复制的文件:\n\n> 默认情况下,buildConfig.sourceDir 为 src\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n { from: './data.json' to: ''},\n ],\n },\n },\n});\n\n\n当指定的文件不在源码目录的时候,可以修改 context 配置。例如指定项目目录下的 temp/index.html 为要复制的文件:\n\n\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [\n {\n from: './index.html',\n context: path.join(__dirname, './temp')\n to: '',\n }\n ],\n },\n },\n});\n\n\npatterns.to 用于指定复制文件的输出路径,默认情况下它的值为 buildConfig.outDir对应的值。因此我们按照如下方式将\nsrc/index.html 复制到 dist 目录下:\n\nexport default defineConfig({\n buildConfig: {\n copy: {\n patterns: [{ from: './index.html' }],\n },\n },\n});\n\n\n当我们配置了 patterns.to 的时候:\n\n * 如果是相对路径,则该路径会相对于 buildConfig.outDir 计算出复制文件输出的绝对路径。\n * 如果是绝对路径,则会直接使用该值。\n\n最后 patterns.globOptions 用于配置寻找复制文件 globby 对象,其配置可参考:\n\n * globby.options\n\n\n不同场景使用示例\n\n\n将文件复制文件\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy file to file\n */\n {\n from: './temp-1/a.png',\n context: __dirname,\n to: './temp-1/b.png',\n },\n ],\n },\n },\n ],\n});\n\n\n\n将文件复制到目录\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy file to dir\n */\n {\n from: './temp-2/a.png',\n context: __dirname,\n to: './temp-2',\n },\n ],\n },\n },\n ],\n});\n\n\n\n从目录复制到目录\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy dir to dir\n */\n {\n from: './temp-3/',\n to: './temp-3',\n context: __dirname,\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n\n\n\n从目录到文件\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy dir to file\n */\n {\n from: './temp-4/',\n context: __dirname,\n to: './temp-4/_index.html',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n\n\n\n使用 GLOB\n\nexport default defineConfig({\n buildConfig: [\n {\n outDir: 'dist',\n copy: {\n patterns: [\n /**\n * copy glob to dir\n */\n {\n from: './*.html',\n to: './temp-5',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n {\n copy: {\n patterns: [\n /**\n * copy glob to file\n */\n {\n from: './*.html',\n to: './temp-6/index.html',\n },\n ],\n options: {\n enableCopySync: true,\n },\n },\n },\n ],\n});\n","frontmatter":{"sidebar_position":3}},{"id":40,"title":"如何处理第三方依赖","routePath":"/module-tools/guide/advance/external-dependency","toc":[{"id":"第三方依赖的默认处理-1","text":"第三方依赖的默认处理","depth":2},{"id":"打包第三方依赖-1","text":"打包第三方依赖","depth":2},{"id":"关闭默认行为-1","text":"关闭默认行为","depth":3},{"id":"排除指定第三方依赖-1","text":"排除指定第三方依赖","depth":3}],"content":"如何处理第三方依赖\n\n一般来说,项目所需要的第三方依赖可以通过包管理器的 install 命令安装,在安装第三方依赖成功后,这些第三方依赖一般会出现在项目 package.json\n的 dependencies 和 devDependencies 下。\n\n{\n \"dependencies\": {},\n \"devDependencies\": {}\n}\n\n\n而 \"dependencies\" 下的依赖通常来说是和项目代码以及构建相关的,如果这些第三方依赖声明在 \"devDependencies\"\n下,那么在生产环境下就会出现缺失依赖的问题。\n\n除了 \"dependencies\" 以外,\"peerDependencies\" 也可以声明在生产环境下需要的依赖,不过它更强调项目在运行环境下存在\n\"peerDependencies\" 声明的这些依赖,这类似于插件这样的机制。\n\n\n第三方依赖的默认处理\n\n在模块工程里,默认情况下不会对\"dependencies\" 以及 \"peerDependencies\" 下的第三方依赖进行打包处理,因此:\n\n<CH.Spotlight>\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n },\n // or\n \"peerDependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\n--------------------------------------------------------------------------------\n\n如果项目依赖了 react。\n\n{\n \"dependencies\": {\n \"react\": \"^17\"\n },\n // or\n \"peerDependencies\": {\n \"react\": \"^17\"\n }\n}\n\n\n--------------------------------------------------------------------------------\n\n当源码中使用了 react 依赖。\n\n\nconsole.info(React);\n\n\n--------------------------------------------------------------------------------\n\n此时产物中不会将 react 代码打包到产物中。\n\n\nconsole.info(React);\n\n\n</CH.Spotlight>\n\n\n打包第三方依赖\n\n不过也有一些情况希望将这些第三方依赖打包到产物。将第三方依赖打包到产物的好处是:减少下载第三方依赖所花费的时间。\n\n这种处理第三方依赖的方式一般在开发命令行工具中比较常见,这可以提升命令行工具的加载速度,给使用者带来更好的使用体验。\n\n那么如何在模块工程中开启对于第三方依赖的打包处理呢?\n\n在构建配置中提供了以下 API 来处理第三方依赖:\n\n * buildConfig.autoExternal\n * buildConfig.externals\n\n\n关闭默认行为\n\n当我们希望关闭对于第三方依赖的默认处理行为时候,可以通过以下方式来实现:\n\nexport default defineConfig({\n buildConfig: {\n autoExternal: false,\n },\n});\n\n\n这样对于 \"dependencies\" 和 \"peerDependencies\" 下面的依赖都会进行打包处理。如果只想要关闭其中某个下面的依赖处理,则可以使用\nbuildConfig.autoExternal 的对象形式:\n\nexport default defineConfig({\n buildConfig: {\n autoExternal: {\n dependencies: false,\n peerDependencies: false,\n },\n },\n});\n\n\n\n排除指定第三方依赖\n\n而除了 buildConfig.autoExternal API 以外,buildConfig.externals\n也可以控制哪些第三方依赖要进行处理。我们可以组合这两个 API 对项目的依赖进行更细微的处理。\n\n例如当我们需要仅对某些依赖不进行打包处理的时候,可以按照如下方式进行配置:\n\n> 一般这种情况,可能是某些依赖不适合进行打包处理。如果遇到这种情况,则可以按照下面的方式进行处理。\n\nepxort default defineConfig({\n buildConfig: {\n autoExternal: false,\n externals: ['pkg-1', /pkg-2/],\n }\n});\n","frontmatter":{"sidebar_position":4}},{"id":41,"title":"深入理解构建","routePath":"/module-tools/guide/advance/in-depth-about-build","toc":[{"id":"深入理解-buildconfig-4","text":"深入理解 buildConfig","depth":2},{"id":"bundle-和-bundleless-4","text":"Bundle 和 Bundleless","depth":3},{"id":"input-与-sourcedir-的关系-4","text":"input 与 sourceDir 的关系","depth":3},{"id":"input-的对象模式-1","text":"input 的对象模式","depth":4},{"id":"sourcedir-6","text":"sourceDir","depth":4},{"id":"类型文件-1","text":"类型文件","depth":3},{"id":"关闭类型生成-1","text":"关闭类型生成","depth":4},{"id":"打包类型文件-1","text":"打包类型文件","depth":4},{"id":"别名转换-1","text":"别名转换","depth":4},{"id":"一些-dts-的使用示例-1","text":"一些 dts 的使用示例","depth":4},{"id":"buildconfigdefine-不同场景的使用方式-1","text":"buildConfig.define 不同场景的使用方式","depth":3},{"id":"环境变量替换-1","text":"环境变量替换","depth":4},{"id":"全局变量替换-1","text":"全局变量替换","depth":4},{"id":"构建过程-4","text":"构建过程","depth":2},{"id":"构建报错-1","text":"构建报错","depth":2}],"content":"深入理解构建\n\n在【基础使用】的部分,我们已经知道可以通过 buildConfig 配置对项目的输出产物进行修改。buildConfig\n不仅描述了产物的一些特性,同时还为构建产物提供了一些功能。\n\n如果你还不清楚 buildConfig 是什么,建议花一些时间通过下面的链接了解一下:\n\n * 【修改输出产物】\n\n而在本章里我们将要深入理解某些构建配置的使用以及了解执行 modern build 命令的时候发生了什么。\n\n\n深入理解 BUILDCONFIG\n\n\nBUNDLE 和 BUNDLELESS\n\n那么首先我们来了解一下 Bundle 和 Bundleless。\n\n所谓 Bundle 是指对构建产物进行打包,构建产物可能是一个文件,也有可能是基于一定的代码拆分策略得到的多个文件。\n\n而 Bundleless 则是指对每个源文件单独进行编译构建,但是并不将它们打包在一起。每一个产物文件都可以找到与之相对应的源码文件。Bundleless\n构建的过程,也可以理解为仅对源文件进行代码转换的过程。\n\n在 buildConfig 中可以通过 buildConfig.buildType 来指定当前构建任务是 Bundle 还是 Bundleless。\n\n\nINPUT 与 SOURCEDIR 的关系\n\nbuildConfig.input 用于指定读取源码的文件路径或者目录路径,其默认值在 Bundle 和 Bundleless 构建过程中有所不同:\n\n * 当 buildType: 'bundle' 的时候,input 默认值为 ['src/index.ts']\n * 当 buildType: 'bundleless' 的时候,input 默认值为 ['src']\n \n > 实际上,在 buildType: 'bundle' 的时候,构建工具会检测是否存在符合 src/index.(j|t)sx?\n > 这个名称规则的文件,并将其作为入口文件。\n\n:::warning {title=注意} 建议不要在 Bundleless 构建过程中指定多个源码文件目录,可能出现不符合预期的结果。目前多个源码目录的\nBundleless 构建还处于不稳定阶段。 :::\n\n从默认值上我们可以知道:Bundle 构建一般可以指定文件路径作为构建的入口,而 Bundleless 构建则更期望使用目录路径寻找源文件。\n\nINPUT 的对象模式\n\n在 Bundle 构建过程中,除了将 input\n设置为一个数组,也可以将它设置为一个对象。通过使用对象的形式,我们可以修改构建产物输出的文件名称。那么对于下面的例子,./src/index.ts\n对应的构建产物文件路径为 ./dist/main.js。\n\n\n\nexport default defineConfig({\n buildConfig: {\n input: {\n main: ['./src/index.ts'],\n },\n outDir: './dist',\n },\n});\n\n\n而在 Bundleless 构建过程中,虽然同样支持这样的使用方式,但是并不推荐。\n\nSOURCEDIR\n\nsourceDir 用于指定源码目录,它主要与以下两个内容有关系:\n\n * 类型文件生成\n * 指定构建过程中的 outbase\n\n一般来说:\n\n * 在 Bundleless 构建过程中,sourceDir 与 input 的值要保持一致,它们的默认值都是 src。\n * 在 Bundle 构建过程中,很少需要使用 sourceDir。\n\n\n类型文件\n\nbuildConfig.dts 配置主要用于类型文件的生成。\n\n关闭类型生成\n\n默认情况下类型生成功能是开启的,如果需要关闭的话,可以按照如下配置:\n\n\n\nexport default defineConfig({\n buildConfig: {\n dts: false,\n },\n});\n\n\n关闭类型文件后,一般来说构建速度会有所提升。\n\n打包类型文件\n\n在 buildType: 'bundleless' 的时候,类型文件的生成是使用项目的 tsc 命令来完成生产。\n\n模块工程解决方案同时还支持对类型文件进行打包,不过使用该功能的时候需要注意:\n\n * 一些第三方依赖存在错误的语法会导致打包过程失败。因此对于这种情况,需要手动通过 buildConfig.externals 将这类第三方包排除。\n * 对于第三方依赖的类型文件指向的是一个 .ts 文件的情况,目前无法处理。比如第三方依赖的 package.json 中存在这样的内容: {\"types\":\n \"./src/index.ts\"}。\n\n别名转换\n\n在 Bundleless 构建过程中,如果源代码中出现了别名,例如:\n\n\n\n正常来说,使用 tsc 生成的产物类型文件也会包含这些别名。不过 Module Tools 会对 tsc 生成的类型文件里的别名进行转换处理:\n\n * 对于类似 `` 这样形式的代码可以进行别名转换。\n * 对于类似 export { utils } from '@common/utils' 这样形式的代码可以进行别名转换。\n\n然而也存在一些情况,目前还无法处理:\n\n * 对于类似 Promise<import('@common/utils')> 这样形式的输出类型目前无法进行转换。\n\n一些 DTS 的使用示例\n\n一般使用方式:\n\n\n\nexport default defineConfig({\n // 此时打包的类型文件输出路径为 `./dist/types`\n buildConfig: {\n buildType: 'bundle',\n dts: {\n tsconfigPath: './other-tsconfig.json',\n distPath: './types',\n },\n outDir: './dist',\n },\n});\n\n\n使用 dts.only 的情况:\n\n\n\nexport default defineConfig({\n // 此时类型文件没有进行打包,输出路径为 `./dist/types`\n buildConfig: [\n {\n buildType: 'bundle',\n dts: false,\n outDir: './dist',\n },\n {\n buildType: 'bundleless',\n dts: {\n only: true,\n },\n outDir: './dist/types',\n },\n ],\n});\n\n\n\nBUILDCONFIG.DEFINE 不同场景的使用方式\n\nbuildConfig.define 功能有些类似 webpack.DefinePlugin。这里介绍几个使用场景:\n\n环境变量替换\n\n\nexport default defineConfig({\n buildConfig: {\n define: {\n 'process.env.VERSION': JSON.stringify(process.env.VERSION || '0.0.0'),\n },\n },\n});\n\n\n通过上面的配置,我们就可以将下面这段代码:\n\n// 编译前代码\nconsole.log(process.env.VERSION);\n\n\n在执行 VERSION=1.0.0 modern build 的时候,转换为:\n\n// 编译后代码\nconsole.log('1.0.0');\n\n\n全局变量替换\n\n\nexport default defineConfig({\n buildConfig: {\n define: {\n VERSION: JSON.stringify(require('./package.json').version || '0.0.0'),\n },\n },\n});\n\n\n通过上面的配置,我们就可以将下面这段代码:\n\n// 编译前代码\nconsole.log(VERSION);\n\n\n转换为:\n\n// 编译后代码\nconsole.log('1.0.0');\n\n\n不过要注意:如果项目是一个 TypeScript 项目,那么你可能需要在项目源代码目录下的 .d.ts 文件里增加以下内容:\n\n> 如果不存在 d.ts 文件,则可以手动创建。\n\ndeclare const YOUR_ADD_GLOBAL_VAR;\n\n\n\n构建过程\n\n当执行 modern build 命令的时候,会发生\n\n * 根据 buildConfig.outDir 清理产物目录。\n * 编译 js/ts 源代码生成 Bundle/Bundleless 的 JS 构建产物。\n * 使用 tsc 生成 Bundle/Bundleless 的类型文件。\n * 处理 Copy 任务。\n\n\n构建报错\n\n当发生构建报错的时候,基于以上了解到的信息,可以很容易的明白在终端出现的报错内容:\n\njs 或者 ts 构建的报错:\n\nerror ModuleBuildError:\n\n╭───────────────────────╮\n│ bundle failed: │\n│ - format is \"cjs\" │\n│ - target is \"esnext\" │\n╰───────────────────────╯\n\nDetailed Information:\n\n\n类型文件生成过程的报错:\n\nerror ModuleBuildError:\n\nbundle DTS failed:\n\n\n对于 js/ts 构建错误,我们可以从报错信息中知道:\n\n * 通过 'bundle failed:' 来判断报错的是 Bundle 构建还是 Bundleless 构建?\n * 构建过程的 format 是什么?\n * 构建过程的 target 是什么?\n * 具体的报错信息。","frontmatter":{"sidebar_position":1}},{"id":42,"title":"深入理解 dev 命令","routePath":"/module-tools/guide/advance/in-depth-about-dev-command","toc":[{"id":"深入理解-buildconfig-5","text":"深入理解 buildConfig","depth":2},{"id":"bundle-和-bundleless-5","text":"Bundle 和 Bundleless","depth":3},{"id":"input-与-sourcedir-的关系-5","text":"input 与 sourceDir 的关系","depth":3},{"id":"构建过程-5","text":"构建过程","depth":2}],"content":"深入理解 DEV 命令\n\n在【基础使用】的部分,我们已经知道可以通过 buildConfig 配置对项目的输出产物进行修改。buildConfig\n不仅描述了产物的一些特性,同时还为构建产物提供了一些功能。\n\n如果你还不清楚 buildConfig 是什么,建议花一些时间通过下面的链接了解一下:\n\n * 【修改输出产物】\n\n而在本章里我们将要深入理解某些构建配置的使用以及了解执行 modern build 命令的时候发生了什么。\n\n\n深入理解 BUILDCONFIG\n\n\nBUNDLE 和 BUNDLELESS\n\n那么首先我们来理解一下 Bundle 和 Bundleless。\n\n所谓 Bundle 是指对构建产物进行打包,构建产物可能是一个文件,也有可能是基于一定的代码拆分策略得到的多个文件。\n\n而 Bundleless 则是指对每个源文件进行编译构建,但是并不将它们打包在一起。每一个产物文件都可以找到与之相对应的源码文件。\n\n\nINPUT 与 SOURCEDIR 的关系\n\n\n构建过程","frontmatter":{"sidebar_position":2}},{"id":43,"title":"主题配置","routePath":"/module-tools/guide/advance/theme-config","toc":[{"id":"动机和原理-1","text":"动机和原理","depth":2},{"id":"使用示例-1","text":"使用示例","depth":2},{"id":"tailwindcss-6","text":"tailwindcss","depth":3},{"id":"html-类名-2","text":"HTML 类名。","depth":4},{"id":"apply-指令-1","text":"@apply 指令","depth":4}],"content":"主题配置\n\n模块工程通过 designSystem API,提供了配置主题的能力。\n\n\n动机和原理\n\n主题配置有些类似组件库中的定制主题功能,主要用于样式开发中使用。我们可以通过 designSystem 配置在不同的样式开发环境下使用由它生成的\ndesignToken。\n\n所谓 designToken 在不同的样式开发环境下对应不同的东西:\n\n * tailwindcss: 以 designSystem 作为 tailwindcss 的 theme 配置。因此可以使用:\n * tailwindcss 支持的 HTML 类名。\n * 在 css/less/sass 下通过 @apply 自定义指令使用与 tailwindcss 支持的 HTML 类名同名的字符串。\n * css/less/scss: 通过 designSystem 生成全局的样式变量。\n\ndesignSystem API 的数据结构借鉴了 tailwindcss 配置对象中的 theme API,因此存在默认的一套\ndesignToken。关于默认值,可以查看 designSystem API。\n\n目前暂时还未支持 css/less/sass 全局变量。\n\n\n使用示例\n\n\nTAILWINDCSS\n\n在使用 tailwindcss 的时候,可以通过 designSystem 来设置它的 theme 配置。\n\n例如在下面的配置中扩展了原有的颜色配置:\n\nexport default {\n designSystem: {\n extend: {\n colors: {\n primary: '#1677ff',\n },\n },\n },\n};\n\n\n我们可以在代码中有两种使用 tailwindcss 的方式。\n\nHTML 类名。\n\nimport 'tailwindcss/utilities.css';\n\nexport default () => {\n return <div className=\"bg-primary\"></div>;\n};\n\n\n@APPLY 指令\n\n关于 @apply。\n\n<CH.Code>\n\nimport './index.css';\n\nexport default () => {\n return <div className=\"btn-primary\"></div>;\n};\n\n\n.btn-primary {\n @apply bg-primary;\n}\n\n\n</CH.Code>","frontmatter":{"sidebar_position":6}},{"id":44,"title":"开始之前","routePath":"/module-tools/guide/basic/before-getting-started","toc":[{"id":"环境准备-1","text":"环境准备","depth":2},{"id":"初识-npm-1","text":"初识 npm","depth":2},{"id":"npm-包类型项目-1","text":"npm 包类型项目","depth":2},{"id":"使用第三方-npm-包-1","text":"使用第三方 npm 包","depth":2},{"id":"还需要了解的-npm-零碎知识-1","text":"还需要了解的 npm 零碎知识","depth":2},{"id":"npm-包的程序入口-1","text":"npm 包的程序入口","depth":3},{"id":"scripts-3","text":"\"scripts\"","depth":3},{"id":"npm-install-3","text":"npm install","depth":4},{"id":"npm-publish-3","text":"npm publish","depth":4},{"id":"peerdependencies-6","text":"peerDependencies","depth":3},{"id":"npm-包管理器-1","text":"npm 包管理器","depth":2},{"id":"module-tools-配置文件-1","text":"Module Tools 配置文件","depth":2}],"content":"开始之前\n\n\n环境准备\n\n为了使用 Modern.js 模块工程解决方案,首先需要 NodeJS,我们推荐最新的长期维护版本,并确保 Node 版本大于等于 14.18.0。因为非稳定的\nNodeJS 时常有一些 Bug,你可以使用 nvm-windows 和 nvm(Mac/linux)安装,这样你就可以方便地切换到不同的 NodeJS\n版本,这些版本可能会用于不同的项目。\n\n\n初识 NPM\n\n当 NodeJS 被安装后,你不仅可以在命令行中访问 node 可执行程序,同时你也可以执行 npm 命令。\n\nnpm 是 NodeJS 的标准软件包管理器。它一开始的用途是用于下载和管理 NodeJS 包的依赖关系,但后来它逐渐变成为一个用于前端 JavaScript\n的工具。\n\n如果你已经对 npm 和 npm 包的使用方式有所了解,那么可以直接跳到【npm 包管理器】部分。\n\n\nNPM 包类型项目\n\n那么什么是 npm 包类型的项目呢?当我们在一个空的项目目录下执行 npm init 命令的时候,它会在当前目录下面创建一个文件名为 package.json\n的 JSON 文件。在创建过程中,我们需要填写包括但不限于 npm 包的名称、版本号、描述等等内容,这些填写的内容都会在生成的 package.json\n文件中找到:\n\n{\n \"name\": \"npm-demo\",\n \"version\": \"1.0.0\",\n \"description\": \"\",\n \"main\": \"index.js\",\n \"scripts\": {\n \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n },\n \"author\": \"\",\n \"license\": \"ISC\"\n}\n\n\n此时这个包含了初始化后的 package.json 文件的项目就是一个 npm 包类型的项目,你可以执行 npm publish 命令将这个项目发布到 npm\nRegistry。\n\nnpm Registry 是一个 npm 包存储的地方,开发者们不仅可以将他们自己的 npm 包发布到 npm Registry,还可以通过 npm\nRegistry 使用其他开发者发布的 npm 包。\n\n优质的 npm 包会有更多的人去使用,因为它不仅节省了很多代码实现的工作,同时也不容易让项目出现问题。\n\n\n使用第三方 NPM 包\n\n当要为初始化的项目增加第三方的 npm 包的时候,我们可以把这一过程叫做“为项目安装依赖”或是“为项目增加依赖”。在增加依赖之前,首先我们要特别了解一件事情\n—— npm 依赖的软件包类型:\n\n * \"dependencies\":一种是你的应用程序在生产环境中需要的软件包。\n * \"devDependencies\":另一种是仅在本地开发和测试中需要的软件包。\n \n > 软件包可以理解为是第三方的 npm 包。\n\n你可以通过执行 npm install npm-package-name 或者 npm add npm-package-name\n的方式来安装在生产环境中需要的软件包,或者也可以在 package.json 文件中手动的将需要安装的包和对应的语义化版本写在 \"dependencies\"\n里,并执行 npm install 命令:\n\n{\n \"name\": \"your-npm-project\",\n \"dependencies\": {\n \"npm-package-name\": \"0.1.0\"\n }\n}\n\n\n同理,你也可以执行 npm install npm-package-name --save-dev 或 npm add npm-package-name\n--save-dev 的方式来安装仅在本地开发和测试中需要的软件包,或者也可以在 package.json 文件中手动的将需要安装的包和对应的语义化版本写在\n\"devDependencies\" 里,并执行 npm install 命令:\n\n{\n \"name\": \"your-npm-project\",\n \"devDependencies\": {\n \"npm-package-name\": \"0.1.0\"\n }\n}\n\n\n在安装或者使用第三方 npm 包的时候一定要确定它们的用途,以及通过区分它们的类型确定好它们应该放在 \"dependencies\" 还是\n\"devDependencies\" 中。\n\n一般来说,需要在源代码中使用到的包都属于 dependencies 依赖。除非你通过打包的方式将依赖的代码输出到本地,那么这种情况可以将它作为\ndevDependencies 依赖。\n\n\n还需要了解的 NPM 零碎知识\n\n\nNPM 包的程序入口\n\n在 package.json 中存在一个 \"main\" 属性,它对应的值是一个模块 ID,或者更直观的说是一个 NodeJS 文件路径,它是你程序的主要入口。\n\n例如你的包名为 foo,并且用户安装了它,然后执行 require(\"foo\") 代码,那么 foo 这个 npm 包的 \"main\"\n字段对应的文件将会被导出。\n\n推荐在你的 npm 包里一定要设置 \"main\" 字段。如果没有设置 \"main\",则默认入口为包的根目录下的 index.js 文件。\n\n除了需要设置 \"main\" 属性以外,一般还会设置 \"module\" 属性。它与 \"main\" 属性的用途类似,它主要是用于在 webpack\n场景下使用。webpack 在大多数情况下,会以 \"module\" -> \"main\" 这个顺序读取 npm 包的入口(文件)。\n\n> 想要了解关于 webpack 如何做这件事,可以查看这个链接。\n\n\n\"SCRIPTS\"\n\npackage.json 文件的 \"scripts\" 属性支持一些内置的脚本和 npm 预设的生命周期事件,以及任意的脚本。\n\n这些都可以通过运行 npm run-script <stage> 或简称 npm run <stage> 来执行。\n\n名称匹配的前置命令和后置命令也会被运行(例如 premyscript、myscript、postmyscript)。\n\n{\n \"scripts\": {\n \"premyscript\": \"\",\n \"myscript\": \"\",\n \"postmyscript\": \"\"\n }\n}\n\n\n当执行 npm run myscripts 的时候,premyscripts 对应的脚本会在它之前执行,postmyscripts 对应的脚本会在它之后执行。\n\n来自依赖的脚本命令可以用 npm explore <pkg> -- npm run <stage> 运行。\n\n还有一些特殊的生命周期脚本(Life Scripts),只在某些情况下发生。这里介绍几个通常需要了解的情况。\n\nNPM INSTALL\n\n当你运行 npm install -g <pkg-name> 时,以下脚本会运行。\n\n * preinstall\n * install\n * postinstall\n * prepublish\n * preprepare\n * prepare\n * postprepare\n\n如果你的软件包根目录有一个 binding.gyp 文件,而你没有定义 install 或 preinstall 脚本,那么 npm 将以 node-gyp\nrebuild 作为默认的 install 命令,使用 node-gyp 进行编译。\n\nNPM PUBLISH\n\n当发布项目的时候,执行该命令会触发以下脚本:\n\n * prepublishOnly\n * prepack\n * prepare\n * postpack\n * publish\n * postpublish\n\n当以 --dry-run 模式运行的时候,prepare 对应的脚本将不会执行。\n\n\nPEERDEPENDENCIES\n\n在某些情况下,你的 npm 项目与它的宿主工具或者库之间存在某种兼容关系(例如一个 webpack 插件项目和 webpack),同时你的 npm\n项目不想将宿主作为必要的依赖,这个时候通常说明你的项目可能是这个宿主工具或者库的插件。你的 npm\n项目会对宿主包的版本有一定的要求,因为只有在特定的版本下才会暴露出 npm 项目所需要的 API。\n\n关于更多 peerDependencies 的解释,可以通过下面的链接了解 npm、pnpm、Yarn 对于它的不同处理方式:\n\n * npm 对 peerDependencies 的解释\n * pnpm vs npm VS Yarn\n\n\nNPM 包管理器\n\n除了 npm 这种标准的包管理器以外,目前主流的还有 pnpm 和 Yarn,它们都是不错的 npm cli 替代品。\n\n推荐使用 pnpm 来管理项目依赖,可以通过下面的方式安装它:\n\nnpm install -g pnpm\n\n\n\nMODULE TOOLS 配置文件\n\n通过@modern-js/create创建的模块工程项目目录下提供了 Module Tools 的配置文件 —— modern.config.(j|t)s。但\nmodern.config 配置文件不是必须存在的。\n\n默认情况下,生成的配置文件的内容如下:\n\n// modern.config.ts\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n});\n\n\n// modern.config.js\n\n\nexport default {\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n};\n\n\n我们推荐使用 defineConfig 函数,不过并不强制使用它。因此你也可以在配置文件中直接返回一个对象:\n\n// modern.config.ts\nexport default {};\n\n\n// modern.config.js\nexport default {};\n","frontmatter":{"sidebar_position":1}},{"id":45,"title":"命令预览","routePath":"/module-tools/guide/basic/command-preview","toc":[{"id":"modern-build-3","text":"modern build","depth":2},{"id":"modern-new-3","text":"modern new","depth":2},{"id":"modern-dev-3","text":"modern dev","depth":2},{"id":"modern-test-3","text":"modern test","depth":2},{"id":"modern-lint-3","text":"modern lint","depth":2},{"id":"modern-change-1","text":"modern change","depth":2},{"id":"modern-pre-3","text":"modern pre","depth":2},{"id":"modern-bump-3","text":"modern bump","depth":2},{"id":"modern-release-3","text":"modern release","depth":2},{"id":"modern-gen-release-note-3","text":"modern gen-release-note","depth":2},{"id":"modern-upgrade-3","text":"modern upgrade","depth":2}],"content":"命令预览\n\n模块工程项目可以使用的命令:\n\n\nMODERN BUILD\n\nUsage: modern build [options]\n\n构建模块命令\n\nOptions:\n -w, --watch 使用监听模式构建代码\n --tsconfig [tsconfig] 指定 tsconfig.json 文件的路径 (default:\n \"./tsconfig.json\")\n --platform [platform] 构建所有或者指定平台的产物\n --no-dts 关闭 DTS 类型文件生成和类型检查\n --no-clear 关闭自动清除产物输出目录的行为\n -h, --help 展示当前命令的信息\n\n\n当想要启动项目构建的时候,可以执行 modern build 命令。在使用这个命令的时候,我们可以:\n\n * 当想要以观察模式启动构建时,使用 --watch 选项。\n * 当想要指定项目编译读取的 TypeScript 配置文件的路径时,使用 build --tsconfig ./path/config.json\n 选项。使用该选项后,会覆盖所有 buildConfig 里 dts.tsconfigPath 配置。\n * 当需要关闭项目的 DTS 类型文件生成和类型检查行为时,可以使用 --no-dts\n 选项。注意:类型文件的生成依赖类型检查的结果。如果关闭了类型检查,那么类型文件也不会生成。\n * 当需要关闭自动清除产物输出目录的行为时,可以使用 --no-clear 选项。\n\n除了以上,模块工程还支持 platform 构建模式,可以用于执行其他工具的构建任务。例如,目前官方支持在安装了\n@modern-js/plugin-storybook 插件后,可以通过执行 modern build --platform 或者 modern build\n--platform storybook 命令启动 Storybook 构建任务生成 Storybook 产物。\n\n在执行 Storybook 构建的时候,它需要读取项目的构建产物。因此在执行 modern build --platform 命令启动 Storybook\n构建的时候,要先执行一次 modern build 确保源码构建产物的存在。\n\n\nMODERN NEW\n\nUsage: modern new [options]\n\n模块化工程方案中执行生成器\n\nOptions:\n -d, --debug 开启 Debug 模式,打印调试日志信息 (default: false)\n -c, --config <config> 生成器运行默认配置(JSON 字符串)\n --dist-tag <tag> 生成器使用特殊的 npm Tag 版本\n --registry 生成器运行过程中定制 npm Registry\n -h, --help display help for command\n\n\nmodern new 命令用于启动微生成器功能,它可以为项目启用默认没有提供的功能。\n\n目前可以开启的功能有:\n\n * Test 测试\n * Storybook 调试\n * Tailwind CSS 支持\n * Modern.js Runtime API\n\n关于这些功能,可以通过【使用微生成器】 章节了解更多。\n\n\nMODERN DEV\n\nUsage: modern dev [options]\n\n本地开发命令\n\nOptions:\n -h, --help display help for command\n\nCommands:\n[dev-tools-subCommand]\n\n\n模块工程解决方案提供了使用调试工具的能力,可以通过 modern dev 命令来启动。不过要注意的是,默认情况下是没有提供调试相关的插件,因此此时执行\nmodern dev 会提示: \"No dev tools found available\"。\n\n目前官方支持的调试工具有 Storybook,因此在你执行 modern new 命令开启它后,就可以执行 modern dev 或者 modern dev\nstorybook 执行它。\n\n\nMODERN TEST\n\nUsage: modern test [options]\n\nOptions:\n -h, --help display help for command\n\n\n需要先执行 modern new 开启测试功能,然后才可以执行 modern test 命令。 modern test 命令会自动将\nsrc/tests/*.test.(js|ts|jsx|tsx) 文件当做测试用例运行。\n\n\nMODERN LINT\n\nUsage: modern lint [options] [...files]\n\nlint and fix source files\n\nOptions:\n --no-fix disable auto fix source file\n -h, --help display help for command\n\n\n运行 ESLint 检查代码语法情况。通常情况下,我们只需要在 git commit 阶段通过 lint-staged 检查本次提交修改的部分代码。\n\n * --no-fix 参数设置后可以关闭自动修复 lint 错误代码的能力。\n\n\nMODERN CHANGE\n\nUsage: modern change [options]\n\n创建变更集\n\nOptions:\n --empty 创建空变更集 (default: false)\n --open 使用编辑器中打开创建的变更集 (default: false)\n -h, --help display help for command\n\n\nmodern change 命令用于生成 changesets 需要的 Markdown 文件。\n\n\nMODERN PRE\n\nUsage: modern pre [options] <enter|exit> [tag]\n\n进入和退出预发布模式\n\nOptions:\n -h, --help display help for command\n\n\n可以使用 modern pre 命令在正式发布前预发布一个版本。\n\n\nMODERN BUMP\n\nUsage: modern bump [options]\n\n使用变更集自动更新发布版本和变更日志\n\nOptions:\n --canary 创建一个预发布版本进行测试 (default: false)\n --preid <tag> 在对预发布版本进行版本控制时指定标识符 (default: \"next\")\n --snapshot 创建一个特殊版本进行测试 (default: false)\n -h, --help display help for command\n\n\n按照 changesets 生成的变更记录的 Markdown 文件修改 package.json 中的版本号, 同时生成 CHANGELOG.md 文件。\n\n\nMODERN RELEASE\n\nUsage: modern release [options]\n\n发布 npm 包\n\nOptions:\n --tag <tag> 发布 npm 包使用特定的 tag (default: \"\")\n --ignore-scripts 发布时忽略 package.json 中的 scripts 命令,仅支持在 pnpm monorepo\n 中使用 (default: \"\")\n -h, --help display help for command\n\n\nmodern release 命令可以将模块发布到 npm Registry 上。\n\n * --tag 参数可以指定发布时具体的 dist tags。\n\n\nMODERN GEN-RELEASE-NOTE\n\nUsage: modern gen-release-note [options]\n\n根据当前仓库 changeset 信息生成 Release Note\n\nOptions:\n --repo <repo> 仓库名称,用于生成 Pull Request 链接, 例如: modern-js-dev/modern.js\n --custom <cumtom> 自定义 Release Note 生成函数\n -h, --help display help for command\n\n\n根据当前仓库的 changeset 信息自动生成 Release Note。\n\n需要在 bump 命令之前执行。\n\n\nMODERN UPGRADE\n\nUsage: modern upgrade [options]\n\n升级 Modern.js 到最新版本\n\nOptions:\n --registry <registry> 定制 npm registry (default: \"\")\n -d,--debug 开启 Debug 模式,打印调试日志信息 (default: false)\n --cwd <cwd> 项目路径 (default: \"\")\n -h, --help display help for command\n\n\nmodern upgrade 命令,用于升级项目 Modern.js 相关依赖至最新版本。\n\n在项目根目录下执行命令 npx modern upgrade,会默认将当前执行命令项目的 package.json 中的 Modern.js\n相关依赖更新至最新版本。","frontmatter":{"sidebar_position":2}},{"id":46,"title":"修改输出产物","routePath":"/module-tools/guide/basic/modify-output-product","toc":[{"id":"默认输出产物-1","text":"默认输出产物","depth":2},{"id":"构建预设-1","text":"构建预设","depth":2},{"id":"构建预设的字符串形式-1","text":"构建预设的字符串形式","depth":3},{"id":"构建预设的函数形式-1","text":"构建预设的函数形式","depth":3},{"id":"构建配置对象-1","text":"构建配置(对象)","depth":2},{"id":"什么时候使用-buildconfig-1","text":"什么时候使用 buildConfig","depth":2}],"content":"修改输出产物\n\n\n默认输出产物\n\n当在初始化的项目里使用 modern build 命令的时候,会根据 Module Tools 默认支持的配置生成相应的产物。默认支持的配置具体如下:\n\n\n\nexport default defineConfig({\n plugins: [moduleTools()],\n buildPreset: 'npm-library',\n});\n\n\n默认生成产物具有以下特点:\n\n * 会生成CommonJS和ESM两份产物。\n * 代码语法支持到 ES6 ,更高级的语法将会被转换。\n * 所有的代码经过打包变成了一个文件,即进行了 bundle 处理。\n * 产物输出根目录为项目下的 dist 目录,类型文件输出的目录为 dist/types。\n\n看到这里你可能会有以下疑问:\n\n 1. buildPreset 是什么?\n 2. 产物的这些特点是由什么决定的?\n\n那么接下来首先解释一下 buildPreset。\n\n\n构建预设\n\nbuildPreset 代表着提前准备好的一组或者多组构建相关的配置,只需要使用 buildPreset\n对应的预设值,就可以省去麻烦且复杂的配置工作,得到符合预期的产物。\n\n\n构建预设的字符串形式\n\n构建预设的值可以是字符串形式,因此这样形式的构建预设叫做预设字符串。\n\n模块工程解决方案根据 npm 包使用的通用场景,提供了通用的构建预设字符串以及相应的变体。目前支持的所有预设字符串可以通过 BuildPreset API\n查看。这里讲解一下关于通用的预设字符串与变体之间的关系。\n\n在通用的预设字符串中,\"npm-library\" 可以用于在开发库类型的 npm 包的场景下使用,它适合大多数普通的模块类型项目。当设置\n\"npm-library\" 的时候,项目的输出产物会有以下特点:\n\n * 在 dist/lib 目录下会得到代码格式为 cjs、语法支持到 es6 且经过打包处理后的产物。\n * 在 dist/es 目录下会得到代码格式为 esm、语法支持为 es6 且经过打包处理后的产物。\n * 在 dist/types 目录下会得到类型文件。如果不是 TypeScript 项目,则没有该目录。\n\n而预设字符串 \"npm-library\" 对应的变体则是在原本产物的基础上修改了代码语法支持这一特点,同时在字符串命名上也变为了\n\"npm-library-[es5 | es2016...es2020 | esnext]\" 这样的形式。\n\n例如,如果在预设字符串 \"npm-library\" 对应的输出产物基础上,让产物代码支持的语法变为 es5 的话,那么只需要将 \"npm-library\"\n改变为 \"npm-library-es5\" 就可以了。\n\n\n构建预设的函数形式\n\n除了字符串形式以外,构建预设的值也可以是函数形式,在函数中可以打印或者修改某个预设值对应的具体配置。\n\n例如,如果使用预设函数的形式达到预设字符串 \"npm-library-es5\" 同样的效果,可以按照如下的方式:\n\n\n\nexport default defineConfig({\n buildPreset({ preset }) {\n return preset.NPM_LIBRARY.map(config => {\n return { ...config, target: 'es5' };\n });\n },\n});\n\n\n在上面的代码实现中,preset.NPM_LIBRARY 与预设字符串 \"npm-library\" 是相对应的,它代表着 \"npm-library\"\n等价的多组构建相关的配置。我们通过 map 方法遍历了 NPM_LIBRARY 这个数组,在这个数组中包含了多个 buildConfig 对象。我们将原本的\nbuildConfig 对象进行了浅拷贝并修改了浅拷贝后得到 buildConfig.target,将它指定为 es5。\n\n> 关于 preset.NPM_LIBRARY 具体对应的值,可以通过 BuildPreset API 查看。在 preset 对象下不仅包含了\n> NPM_LIBRARY,还包含了其他类似的常量。\n\n那么这里的 buildConfig 对象是什么呢?之前提到的构建产物特点又是根据什么呢?\n\n接下来我们解释一下。\n\n\n构建配置(对象)\n\nbuildConfig 是一个用来描述如何编译、生成构建产物的配置对象。在最开始提到的关于“构建产物的特点”,其实都是 buildConfig\n所支持的属性。目前所支持的属性覆盖了大部分模块类型项目在构建产物时的需求,buildConfig\n不仅包含一些产物所具备的属性,也包含了构建产物所需要的一些特性功能。接下来从分类的角度简单罗列一下:\n\n构建产物的基本属性包括:\n\n * 产物是否被打包:对应的 API 是 buildConfig.buildType。\n * 产物对于语法的支持:对应的 API 是 buildConfig.target。\n * 产物格式:对应的 API 是 buildConfig.format。\n * 产物类型文件如何处理,对应的 API 是 buildConfig.dts。\n * 产物的 sourceMap 如何处理:对应的 API 是 buildConfig.sourceMap。\n * 产物对应的输入(或者是源文件):对应的 API 是 buildConfig.input。\n * 产物输出的目录:对应的 API 是 buildConfig.outDir。\n * 构建的源码目录:对应的 API 是 buildConfig.sourceDir。\n\n构建产物所需的常用功能包括:\n\n * 别名:对应的 API 是 buildConfig.alias。\n * 静态资源处理:对应的 API 是 buildConfig.asset。\n * 第三方依赖处理:对应的 API 有:\n * buildConfig.autoExternal。\n * buildConfig.externals。\n * 拷贝:对应的 API 是 buildConfig.copy。\n * 全局变量替换:对应的 API 是 buildConfig.define。\n * 指定 JSX 编译方式,对应的 API 是 buildConfig.jsx。\n\n一些高级属性或者使用频率不高的功能:\n\n * 产物代码压缩:对应的 API 是 buildConfig.minify。\n * 代码分割:buildConfig.spitting\n * 指定构建产物用于 NodeJS 环境还是浏览器环境:对应的 API 是 buildConfig.platform。\n * umd 产物相关:\n * 指定 umd 产物外部导入的全局变量:对应的 API 是 buildConfig.umdGlobals。\n * 指定 umd 产物的模块名:对应的 API 是 buildConfig.umdModuleName。\n\n除了以上分类以外,关于这些 API 的常见问题和最佳实践可以通过下面的链接来了解\n\n * 什么是 bundle 和 bundleless?\n * input 与 sourceDir 的关系。\n * 产物中类型文件的多种生成方式。\n * buildConfig.define 不同场景的使用方式。\n * 如何处理第三方依赖?\n * 如何使用拷贝?\n * 如何构建 umd 产物?\n * 静态资源目前所支持的能力。\n\n\n什么时候使用 BUILDCONFIG\n\nbuildConfig 是用于修改产物的方式之一,当与 buildPreset 配置同时存在的时候,只有 buildConfig\n才会生效。因此如果按照如下方式配置:\n\n\n\nexport default defineConfig({\n buildConfig: {\n format: 'umd',\n },\n buildPreset: 'npm-library',\n});\n\n\n那么此时就会看到如下提示:\n\n因为同时出现 'buildConfig' 和 'buildPreset' 配置,因此仅 'buildConfig' 配置生效\n\n\nbuildPreset 代表的一组或者多组构建相关的配置都是由 buildConfig 组成,当使用 buildPreset\n无法满足当前项目需求的时候,就可以使用 buildConfig 来自定义输出产物。\n\n在使用 buildConfig 的过程,就是对获得怎样的构建产物的思考过程。","frontmatter":{"sidebar_position":3}},{"id":47,"title":"版本管理与发布","routePath":"/module-tools/guide/basic/publish-your-project","toc":[{"id":"跟踪变更-1","text":"跟踪变更","depth":2},{"id":"版本更新-1","text":"版本更新","depth":2},{"id":"发布-1","text":"发布","depth":2},{"id":"预发布-1","text":"预发布","depth":2}],"content":"版本管理与发布\n\n一个 npm 类型的模块项目发布流程包含了两个阶段:\n\n * 第一阶段是在开发期间,开发者需要提供一个变更文件来记录需要发布的变动;\n * 第二阶段是在发布期间,Module Tools 可以收集所有的变更文件来更新版本、更新发布日志,并发布新的包到 npm Registry 上。\n\n\n跟踪变更\n\n当项目发生变化的时候需要将变化的内容记录下来。项目发生的变化一般是指:\n\n * 新功能\n * 修复问题\n * 配置文件修改\n * ...\n\n当这些变化一旦完成后,需要通过以下命令来对当前的变化进行记录:\n\n * modern change\n\n执行 modern change 命令后会向开发者提出几个问题,并根据开发者的回答生成变更记录。变更记录文件包含了版本变化的类型和其描述,该文件会被提交到\ngit 仓库中。\n\n$ npx modern change\n🦋 What kind of change is this for module-example? (current version is 0.1.0) · patch\n🦋 Please enter a summary for this change (this will be in the changelogs). Submit empty line to open external editor\n🦋 Summary · publish test\n🦋 === Releasing the following packages ===\n🦋 [Patch]\n🦋 module\n🦋 Is this your desired changeset? (Y/n) · true\n🦋 Changeset added! - you can now commit it\n🦋\n🦋 If you want to modify or expand on the changeset summary, you can find it here\n🦋 info /xxxxxx/module/.changeset/brave-dryers-agree.md\n\n\n当执行成功后,生成的包含变更记录的 Markdown 文件会保存在项目的 .changeset 目录下面。其内容类似下面这样:\n\n---\n'module-example': patch\n---\n\npublish test\n\n\n\n版本更新\n\n当需要更新项目版本的时候,执行以下命令:\n\n * modern bump\n\n执行 modern bump 将会基于 .changeset/ 目录下记录了变更的 Markdown 文件内容来修改 package.json\n中的版本号,同时生成 CHANGELOG.md 文件。而当版本更新完成后,这些记录变更的 Markdown 文件也会被删除,也可说这些 Markdown\n文件被“消耗”掉了。\n\n# module\n\n## 0.1.1\n\n### Patch Changes\n\n- publish test\n\n\n\n发布\n\n发布项目可以执行以下命令:\n\n * modern publish\n\nmodern release 命令可以将项目发布到 npm Registry。\n\n此时发布的是 latest 版本,也可以说是正式版本。如果想要修改 dist-tag,可以通过 modern release --tag 命令来指定。例如:\n\nmodern release --tag beta\n\n\n但是如果希望将当前项目的版本号也修改为预发布的版本号,则需要使用 modern pre 命令。\n\n> 所谓 dist-tag,可以理解:为当前发布的版本打标签。一般来说,默认发布的版本对应的 dist-tag 为 latest,因此可以把 latest\n> 认为是正式版本的 dist-tag。\n\n\n预发布\n\n当需要在正式发布之前进行预发布,则需要执行以下命令:\n\n * modern pre\n\n首先 modern pre enter <tag> 进入预发布模式,<tag> 可以与发布项目的时候使用 modern release --tag 命令指定的\ntag 一致。\n\n$ npx modern pre enter next\n🦋 success Entered pre mode with tag next\n🦋 info Run `changeset version` to version packages with prerelease versions\n✨ Done in 5.30s.\n\n\n接着可以使用 modern bump 命令更新具体的版本号,此时不会真正的“消耗”记录变更的 Markdown 文件:\n\n$ npx modern bump\n🦋 warn ===============================IMPORTANT!===============================\n🦋 warn You are in prerelease mode\n🦋 warn If you meant to do a normal release you should revert these changes and run `changeset pre exit`\n🦋 warn You can then run `changeset version` again to do a normal release\n🦋 warn ----------------------------------------------------------------------\n🦋 All files have been updated. Review them and commit at your leisure\n\n\n然后可以看到 package.json 中更新的版本号会类似这样:0.1.2-next.0。\n\n最后,如果不需要再进行预发布,则一定要执行 modern pre exit 命令,这样可以退出预发布状态,并且当再次执行 modern bump\n命令的时候,就可以发布正式的版本。","frontmatter":{"sidebar_position":7}},{"id":48,"title":"测试项目","routePath":"/module-tools/guide/basic/test-your-project","toc":[{"id":"先决条件和约定-1","text":"先决条件和约定","depth":2},{"id":"运行测试-1","text":"运行测试","depth":2},{"id":"使用配置-1","text":"使用配置","depth":2},{"id":"测试示例-1","text":"测试示例","depth":2},{"id":"普通模块-1","text":"普通模块","depth":3},{"id":"组件-1","text":"组件","depth":3}],"content":"测试项目\n\n本章将要介绍如何测试可复用模块。\n\n\n先决条件和约定\n\n想要使用项目的测试功能,需要确保项目中包含依赖:\"@modern-js/plugin-testing\" ,可以通过modern new来完成。\n\n在模块工程方案中,对于测试用例或者说编写测试的文件有如下约定:\n\n * 项目目录下的 tests 目录为测试用例和测试文件的目录,不支持更改运行测试用例的目录。\n * 默认会自动将后缀为 .test.[tj]sx? 的文件识别为测试文件。\n * 其他的 .[tj]sx? 后缀的文件被识别为普通的文件,可以用于测试的 utils 文件或者其他用途。\n\n\n运行测试\n\n当准备好了依赖以及了解了测试用例在哪里编写后,我们可以通过以下命令来执行测试:\n\nmodern test\n\n// 更新 snapshot\nmodern test --updateSnapshot\n\n\n执行之后,会看到测试的结果:\n\n\n\n\n使用配置\n\n/obj/eden-cn/uhbfnupenuhf/test-result.png 模块工程方案对测试提供了以下配置:\n\n * testing\n\n可以在 modern.config.(j|t)s 中增加它。\n\n\n测试示例\n\n\n普通模块\n\n对于普通的模块,我们可以按照如下方式使用测试功能:\n\n<CH.Spotlight>\n\nexport default function () {\n return 'hello world';\n}\n\n\n--------------------------------------------------------------------------------\n\n首先是模块的代码。\n\nexport default function () {\n return 'hello world';\n}\n\n\n--------------------------------------------------------------------------------\n\n然后在测试文件中,我们可以这样。\n\n其中 @ 指向了源码目录,在初始化项目的 tests/tsconfig.json 中定义了。\n\n\n\ndescribe('默认值 cases', () => {\n test('Have returns', () => {\n const drink = jest.fn(main);\n drink();\n expect(drink).toHaveReturned();\n });\n});\n\n\n--------------------------------------------------------------------------------\n\n最后我们可以执行 modern test。\n\npnpm test\n## or\nyarn test\n## or\nnpm run test\n\n\n</CH.Spotlight>\n\n\n组件\n\n{/* 链接待补充 */}\n\n对于组件,Modern.js 的 Runtime API 提供了用于测试 UI 组件的功能,其功能由 @modern-js/runtime/testing\n提供。\n\n如果需要使用 Runtime API,那么可以通过 微生成器 开启。\n\n<CH.Spotlight>\n\nexport const default () {\n return (\n <div>This is a UI Component</div>\n );\n}\n\n\n--------------------------------------------------------------------------------\n\n首先是组件的代码。\n\nexport const default () {\n return (\n <div>This is a UI Component</div>\n );\n}\n\n\n--------------------------------------------------------------------------------\n\n然后在测试文件中,我们可以这样。\n\n其中 @ 指向了源码目录,在初始化项目的 tests/tsconfig.json 中定义了。\n\n\n\n\n\ndescribe('默认值 cases', () => {\n test('Rendered', () => {\n render(<Component />);\n expect(screen.getByText('This is a UI Component')).toBeInTheDocument();\n });\n});\n\n\n--------------------------------------------------------------------------------\n\n最后我们可以执行 modern test。\n\npnpm test\n## or\nyarn test\n## or\nnpm run test\n\n\n</CH.Spotlight>","frontmatter":{"sidebar_position":6}},{"id":49,"title":"使用微生成器","routePath":"/module-tools/guide/basic/use-micro-generator","toc":[{"id":"test-测试-1","text":"Test 测试","depth":2},{"id":"storybook-调试-1","text":"Storybook 调试","depth":2},{"id":"tailwind-css-支持-1","text":"Tailwind CSS 支持","depth":2},{"id":"启动-modernjs-runtime-api-1","text":"启动 Modern.js Runtime API","depth":2}],"content":"使用微生成器\n\n模块工程解决方案提供了微生成器工具,它可以为当前项目:\n\n * 新增目录和文件\n * 修改 package.json 文件内容\n * 执行命令\n\n因此通过这些能力,微生成器可以为项目开启额外的特性功能。\n\n可以通过 modern new 启动微生成器。目前模块工程方案支持的微生成器功能有:\n\n\nTEST 测试\n\n当我们想要对一些模块进行测试的时候,可以启用 test 测试功能。启动该功能后,会在项目目录下创建 tests 目录以及相关文件,在 package.json\n中新增 \"@modern-js/plugin-testing\" 依赖。\n\n\nSTORYBOOK 调试\n\n当我们想要对组件或者普通模块进行调试的时候,可以启用 Storybook 调试功能。启动该功能后,会在项目目录下创建 stories 目录以及相关文件,在\npackage.json 中新增 \"@modern-js/plugin-storybook\" 依赖。\n\n关于如何启动 Storybook 以及如何使用 Storybook,可以查看下面的链接:\n\n * modern dev\n * 使用 Storybook\n\n\nTAILWIND CSS 支持\n\n当我们想要为项目增加 Tailwind CSS 支持的时候,可以启动这个功能。Tailwind CSS 是一个 CSS 库,提供开箱即用的样式。\n\n关于如何在模块工程里使用 Tailwind CSS,可以查看:\n\n * 使用 Tailwind CSS\n\n\n启动 MODERN.JS RUNTIME API\n\nModern.js 提供了 Runtime API 能力,这些 API 只能在 Modern.js 的应用项目环境中使用。如果你需要开发一个 Modern.js\n应用环境中使用的组件,那么你可以开启该特性,微生成器会增加 \"@modern-js/runtime\"依赖。\n\n另外,Storybook 调试工具也会通过检测项目的依赖确定项目是否需要使用 Runtime API,并且提供与 Modern.js 应用项目一样的\nRuntime API 运行环境。","frontmatter":{"sidebar_position":4}},{"id":50,"title":"使用 Storybook","routePath":"/module-tools/guide/basic/using-storybook","toc":[{"id":"调试代码-1","text":"调试代码","depth":2},{"id":"引用组件产物-1","text":"引用组件产物","depth":3},{"id":"引用组件源码-1","text":"引用组件源码","depth":3},{"id":"配置-storybook-1","text":"配置 Storybook","depth":2},{"id":"构建-storybook-产物-1","text":"构建 Storybook 产物","depth":2}],"content":"使用 STORYBOOK\n\n首先如果没有看过以下内容的话,可以先花几分钟先了解一下:\n\n * 使用微生成器开启 Storybook 调试\n * modern dev\n\nStorybook 是一个专门用于组件调试的工具,围绕着组件开发提供了:\n\n * 丰富多样的调试能力\n * 可与一些测试工具结合使用\n * 可重复使用的文档内容\n * 可分享能力\n * 工作流程自动化\n\n因此它是一个复杂且功能强大的工具。\n\n模块工程解决方案集成了 Storybook ,因此你几乎可以按照 Storybook 官方文档的内容进行使用。不过依然有一些地方需要注意,接下来讲解一下:\n\n\n调试代码\n\n在调试代码过程中需要引入组件代码,目前可以通过两种方式引入组件代码:\n\n * 引用组件产物\n * 引用组件源码\n\n我们更推荐使用第一种“引用组件产物”的方式。因为它几乎接近真实的使用场景,不仅可以对组件功能进行调试,同时也对构建产物的正确性进行了验证。\n\n接下来我们分别讲一下这两种方式具体如何使用。\n\n\n引用组件产物\n\n假如存在 TypeScript 项目 foo:\n\n<CH.Spotlight>\n\n{\n \"name\": \"foo\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/types/index.d.ts\"\n}\n\n\n--------------------------------------------------------------------------------\n\n确保 package.json 的 main 和 types 的值为真实的路径。\n\n{\n \"name\": \"foo\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./dist/types/index.d.ts\"\n}\n\n\n--------------------------------------------------------------------------------\n\nfoo 项目的源码。\n\nexport const content = 'hello world';\n\n\n--------------------------------------------------------------------------------\n\n确保在 stories/tsconfig.json 中设置了指向项目根目录的 paths 配置。 paths 的 key 与项目名称相同。\n\n{\n \"extends\": \"../tsconfig.json\",\n \"compilerOptions\": {\n \"baseUrl\": \"../\",\n \"paths\": {\n \"foo\": [\".\"]\n }\n },\n \"include\": [\n \"**/*\"\n ]\n}\n\n\n--------------------------------------------------------------------------------\n\n最后在 Story 代码中直接以项目名称的方式引用。\n\n\n\nconst Component = () => <div>this is a Story Component {content}</div>;\n\nexport const YourStory = () => <Component />;\n\nexport default {\n title: 'Your Stories',\n};\n\n\n</CH.Spotlight>\n\n如果在开发过程中,遇到无法实时获得类型定义的情况,此时:\n\n对于 pnpm 的项目,可以按照下面的内容对 package.json 进行修改:\n\n{\n \"name\": \"foo\",\n \"main\": \"./dist/index.js\",\n \"types\": \"./src/index.ts\",\n \"publishConfig\": {\n \"types\": \"./dist/index.d.ts\",\n }\n}\n\n\n> 关于 pnpm 的 publishConfig 的使用,可以阅读下面这个链接。\n\n而对于 npm 和 Yarn 的项目,则只能通过手动的方式在开发阶段和发布阶段对 package.json 的 types 的值进行修改。\n\n那么为什么可以直接引用产物呢?\n\n 1. 在执行 modern dev storybook 命令之前,会自动执行 modern build 命令,保证项目构建产物的存在。\n 2. 在 Storybook 内部增加了以项目名称作为别名的处理,保证能够根据 package.json 解析出项目的产物路径。\n\n\n引用组件源码\n\n引用组件的源码可以通过相对路径的方式:\n\n\n\nconst Component = () => <div>this is a Story Component {content}</div>;\n\nexport const YourStory = () => <Component />;\n\nexport default {\n title: 'Your Stories',\n};\n\n\n那么为什么不推荐使用源码的方式呢?\n\n不仅仅是因为使用组件源码无法验证组件产物是否正确,同时模块工程对于构建产物支持的一些配置无法完全转换为 Storybook\n内部的配置。如果某些配置无法进行相互转换的话,就会在 Storybook 调试过程中出现不符合预期的结果。\n\n\n配置 STORYBOOK\n\nStorybook 官方通过一个名为 .storybook 的文件夹来进行项目配置,其中包含各种配置文件。在模块工程方案中,可以在项目的\nconfig/storybook 目录下增加 Storybook 配置文件。\n\n关于 Storybook 各种配置文件的使用方式,可以查看下面的链接:\n\n * Configure Storybook\n\n不过在模块项目里进行 Storybook 存在一些限制:\n\n * 目前不能修改 Story 文件存放的位置,即无法在 main.js 文件里修改 stories 配置。\n * 目前不能修改 Webpack 和 Babel 相关的配置,即无法在 main.js 文件里修改 webpackFinal 和 babel 配置。\n\n在未来我们会考虑这些配置是否可以允许修改,不过目前为了减少不可预知的问题暂时限制使用这些配置。\n\n\n构建 STORYBOOK 产物\n\n除了可以对组件或者普通的模块进行 Storybook 调试,还可以通过下面的命令来执行 Storybook 的构建任务。\n\nmodern build --platform storybook\n\n\n关于 modern build --platform 命令可以查看:\n\n * modern build\n\n构建完成后,可以在 dist/storybook-static 目录看到构建产物文件。","frontmatter":{"sidebar_position":5}},{"id":51,"title":"开发组件","routePath":"/module-tools/guide/best-practices/components","toc":[{"id":"初始化项目-1","text":"初始化项目","depth":2},{"id":"使用-storybook-调试代码-1","text":"使用 Storybook 调试代码","depth":2},{"id":"开发样式-1","text":"开发样式","depth":2},{"id":"csspostcss-3","text":"CSS/PostCSS","depth":3},{"id":"less-6","text":"Less","depth":3},{"id":"sassscss-3","text":"Sass/Scss","depth":3},{"id":"tailwind-css-3","text":"Tailwind CSS","depth":3},{"id":"html-类名-3","text":"HTML 类名","depth":4},{"id":"apply-3","text":"@apply","depth":4},{"id":"推荐方式-1","text":"推荐方式","depth":4},{"id":"bundle-和-bundleless-构建产物区别-1","text":"bundle 和 bundleless 构建产物区别","depth":4},{"id":"css-modules-3","text":"CSS Modules","depth":3},{"id":"配置构建产物-1","text":"配置构建产物","depth":2},{"id":"测试组件-1","text":"测试组件","depth":2},{"id":"发布组件-1","text":"发布组件","depth":2}],"content":"开发组件\n\n本章将要介绍如何使用模块工程解决方案开发组件项目。\n\n\n初始化项目\n\n<CH.Spotlight>\n\nnpx @modern-js/create components-project\n\n? 请选择你想创建的工程类型 模块\n? 请填写项目名称 components-demo\n? 请选择开发语言 TS\n? 请选择包管理工具 pnpm\n\n\n--------------------------------------------------------------------------------\n\n推荐使用 @modern-js/create 命令来初始化一个 npm 项目。\n\nnpx @modern-js/create components-project\n\n? 请选择你想创建的工程类型 模块\n? 请填写项目名称 components-demo\n? 请选择开发语言 TS\n? 请选择包管理工具 pnpm\n\n\n--------------------------------------------------------------------------------\n\n初始化的目录结构。\n\n.\n├── README.md\n├── node_modules/\n├── dist/\n├── modern.config.ts\n├── package.json\n├── pnpm-lock.yaml\n├── src\n│ ├── index.ts\n│ └── modern-app-env.d.ts\n└── tsconfig.json\n\n\n--------------------------------------------------------------------------------\n\n修改 ./src/index.ts 文件后缀和内容。\n\n此时就初始化了一个组件项目。\n\nexport default () => {\n return <div>hello world</div>;\n};\n\n\n</CH.Spotlight>\n\n\n使用 STORYBOOK 调试代码\n\n<CH.Spotlight>\n\npnpm run new\n\n? 请选择你想要的操作 启用可选功能\n? 启用可选功能 启用「Storybook」\n\n\n--------------------------------------------------------------------------------\n\n在项目根目录下执行 new 命令,可以开启 Storybook 功能。\n\npnpm run new\n\n? 请选择你想要的操作 启用可选功能\n? 启用可选功能 启用「Storybook」\n\n\n--------------------------------------------------------------------------------\n\n成功开启后,会看到 package.json 中新增了依赖。同时创建了 stories 目录和相关的初始化文件。\n\n<CH.Code>\n\n{\n \"name\": \"components-demo\",\n \"devDependencies\": {\n \"@modern-js/plugin-storybook\": \"x.y.z\",\n \"@modern-js/runtime\": \"x.y.z\",\n \"react\": \"^17\",\n \"react-dom\": \"^17\"\n }\n}\n\n\n.\n├── src\n│ ├── index.ts\n│ └── modern-app-env.d.ts\n├── stories\n│ ├── .eslintrc.js\n│ ├── index.stories.tsx\n│ └── tsconfig.json\n\n\n</CH.Code>\n\n--------------------------------------------------------------------------------\n\n初始化后,在 ./stories 目录下的 tsconfig.json 文件中默认设置了与项目同名的 paths 配置。\n\n{\n \"extends\": \"../tsconfig.json\",\n \"compilerOptions\": {\n \"baseUrl\": \"../\",\n \"paths\": {\n \"components-demo\": [\"./\"],\n \"components-demo/*\": [\"./*\"]\n }\n },\n \"include\": [\"**/*\"]\n}\n\n\n--------------------------------------------------------------------------------\n\n这样的配置可以让你在 Story 代码中直接使用项目的名称引入代码。\n\n<CH.Code>\n\n\n\nexport const YourStory = () => <Component />;\n\nexport default {\n title: 'Your Stories',\n};\n\n\n--------------------------------------------------------------------------------\n\nexport default () => {\n return <div>hello world</div>;\n};\n\n\n</CH.Code>\n\n--------------------------------------------------------------------------------\n\n此时 Storybook 会根据项目的 package.json 文件中的 main、exports 这样的字段确认导入代码的入口; 根据 types\n字段确定类型文件的位置。\n\n{\n \"name\": \"components-demo\",\n \"main\": \"./dist/esm/index.js\",\n \"types\": \"./dist/types/index.d.ts\"\n}\n\n\n--------------------------------------------------------------------------------\n\n虽然也支持导入源代码进行调试,不过使用项目产物调试更加可靠。\n\n使用源代码调试存在局限性:某些配置无法在 Storybook 和原本构建支持的配置等价使用。\n\n因此更推荐使用产物进行调试。\n\n\n\nexport const YourStory = () => <Component />;\n\nexport default {\n title: 'Your Stories',\n};\n\n\n</CH.Spotlight>\n\n\n开发样式\n\n接下来我们可以给组件添加样式。\n\n目前支持开发样式的能力有:\n\n * CSS/PostCSS\n * Less\n * Scss/Sass\n * Tailwind CSS\n * CSS Modules\n\n\nCSS/POSTCSS\n\n模块工程支持 PostCSS,并且内置了以下 postcss 插件:\n\n * flexbugs-fixes\n * custom-properties\n * initial\n * page-break\n * font-variant\n * media-minmax\n * nesting\n\n因此我们可以在项目中创建 .css 文件,并且可以直接在 css 文件中使用这些插件提供的语法支持和能力。\n\n<CH.Spotlight>\n\na,\nb {\n color: red;\n\n /* \"&\" comes first */\n & c,\n & d {\n color: white;\n }\n\n /* \"&\" comes later, requiring \"@nest\" */\n @nest e & {\n color: yellow;\n }\n}\n\n\n--------------------------------------------------------------------------------\n\n源代码。\n\n\n\n--------------------------------------------------------------------------------\n\ncss 产物。\n\na,\nb {\n color: red;\n}\na c,\nb c,\na d,\nb d {\n color: white;\n}\ne a,\ne b {\n color: yellow;\n}\n\n\n</CH.Spotlight>\n\n\nLESS\n\n模块工程支持使用 Less 开发样式。\n\n> 目前支持的版本为 4.1.3\n\n<CH.Spotlight>\n\n@bg: black;\n@bg-light: boolean(luma(@bg) > 50%);\n\ndiv {\n background: @bg;\n color: if(@bg-light, black, white);\n}\n\n\n--------------------------------------------------------------------------------\n\n源代码。\n\n\n\n--------------------------------------------------------------------------------\n\nLess 产物。\n\ndiv {\n background: black;\n color: white;\n}\n\n\n</CH.Spotlight>\n\n\nSASS/SCSS\n\n模块工程支持使用 Scss/Sass 开发样式。\n\n> 目前支持的版本为 1.54.4\n\n<CH.Spotlight>\n\n$font-stack: Helvetica, sans-serif;\n$primary-color: #333;\n\nbody {\n font: 100% $font-stack;\n color: $primary-color;\n}\n\n\n--------------------------------------------------------------------------------\n\n源代码。\n\n\n\n--------------------------------------------------------------------------------\n\nLess 产物。\n\nbody {\n font: 100% Helvetica, sans-serif;\n color: #333;\n}\n\n\n</CH.Spotlight>\n\n\nTAILWIND CSS\n\n模块工程支持使用 Tailwind CSS 开发组件样式。\n\n默认情况下,模块工程没有开启该功能,需要按照下面的方式开启它。\n\n<CH.Spotlight>\n\npnpm run new\n\n? 请选择你想要的操作 启用可选功能\n? 启用可选功能 启用「Storybook」\n\n\n--------------------------------------------------------------------------------\n\n在项目根目录下执行 new 命令,可以开启 Tailwind CSS 功能。\n\npnpm run new\n\n? 请选择你想要的操作 启用可选功能\n? 启用可选功能 启用 Tailwind CSS 支持\n\n\n--------------------------------------------------------------------------------\n\n成功开启后,会看到 package.json 中新增了依赖。\n\n{\n \"devDependencies\": {\n \"@modern-js/plugin-tailwindcss\": \"x.y.z\"\n }\n}\n\n\n</CH.Spotlight>\n\nTailwind CSS 提供了两种使用方式:\n\nHTML 类名\n\n<CH.Spotlight>\n\nimport 'tailwindcss/utilities.css';\n\nexport default () => {\n return <div className=\"bg-black text-white\">hello world</div>;\n};\n\n\n--------------------------------------------------------------------------------\n\nTailwind CSS 支持在 HTML 标签上使用类名的方式增加样式。\n\n\n\n--------------------------------------------------------------------------------\n\n当使用 HTML 类名的时候,一定要注意导入 Tailwind CSS 相应的 css 文件。\n\n\n\n--------------------------------------------------------------------------------\n\n样式产物。\n\n> 此时是 bundle 构建。\n\n/* ../../node_modules/.pnpm/tailwindcss@2.2.19/node_modules/tailwindcss/utilities.css */\n.table {\n display: table;\n}\n@keyframes spin {\n to {\n transform: rotate(360deg);\n }\n}\n@keyframes ping {\n 75%,\n 100% {\n transform: scale(2);\n opacity: 0;\n }\n}\n@keyframes pulse {\n 50% {\n opacity: 0.5;\n }\n}\n@keyframes bounce {\n 0%,\n 100% {\n transform: translateY(-25%);\n animation-timing-function: cubic-bezier(0.8, 0, 1, 1);\n }\n 50% {\n transform: none;\n animation-timing-function: cubic-bezier(0, 0, 0.2, 1);\n }\n}\n.bg-black {\n --tw-bg-opacity: 1;\n background-color: rgba(0, 0, 0, var(--tw-bg-opacity));\n}\n.text-white {\n --tw-text-opacity: 1;\n color: rgba(255, 255, 255, var(--tw-text-opacity));\n}\n*,\n::before,\n::after {\n --tw-shadow: 0 0 #0000;\n}\n*,\n::before,\n::after {\n --tw-ring-inset: var(--tw-empty);\n --tw-ring-offset-width: 0px;\n --tw-ring-offset-color: #fff;\n --tw-ring-color: rgba(59, 130, 246, 0.5);\n --tw-ring-offset-shadow: 0 0 #0000;\n --tw-ring-shadow: 0 0 #0000;\n}\n@media (min-width: 640px) {\n}\n@media (min-width: 768px) {\n}\n@media (min-width: 1024px) {\n}\n@media (min-width: 1280px) {\n}\n@media (min-width: 1536px) {\n}\n\n\n</CH.Spotlight>\n\n@APPLY\n\nTailwind CSS 提供了 @apply 指令,可以通过它将 Tailwind CSS 提供的样式内联到我们编写的样式中。\n\n@apply 可以用于 CSS、Less、Sass 中。\n\n.btn {\n @apply font-bold py-2 px-4 rounded;\n}\n\n\n但是使用过程中,对于 Less 和 Sass 有些情况需要注意:\n\nSASS\n\n当将 Tailwind 与 Sass 一起使用时,@apply 后面存在 !important 的时候,需要使用插值来让 Sass 正确编译。\n\n<CH.Spotlight>\n\n.alert {\n @apply bg-red-500 !important;\n}\n\n\n--------------------------------------------------------------------------------\n\n不能正常工作。\n\n\n\n--------------------------------------------------------------------------------\n\n能够正常工作。\n\n.alert {\n @apply bg-red-500 #{!important};\n}\n\n\n</CH.Spotlight>\n\nLESS\n\n在与 Less 一起使用 Tailwind 时,你不能嵌套 Tailwind 的 @screen 指令。\n\n<CH.Spotlight>\n\n.card {\n @apply rounded-none;\n\n @screen sm {\n @apply rounded-lg;\n }\n}\n\n\n--------------------------------------------------------------------------------\n\n不能正常工作。\n\n\n\n--------------------------------------------------------------------------------\n\n相反,使用常规的媒体查询和 theme() 函数来引用你的屏幕尺寸,或者干脆不要嵌套你的 @screen 指令。\n\n<CH.Code>\n\n// Use a regular media query and theme()\n.card {\n @apply rounded-none;\n\n @media (min-width: theme('screens.sm')) {\n @apply rounded-lg;\n }\n}\n\n\n--------------------------------------------------------------------------------\n\n// Use the @screen directive at the top-level\n.card {\n @apply rounded-none;\n\n @media (min-width: theme('screens.sm')) {\n @apply rounded-lg;\n }\n}\n\n\n</CH.Code>\n\n</CH.Spotlight>\n\n推荐方式\n\n推荐使用 @apply 指定的方式开发样式,这样在样式产物中仅包含通过指令内联的样式。\n\n当使用 HTML 类名的方式添加样式的时候,默认情况下 Tailwind\n不仅会将本身类名对应的样式加入产物中,同时还会有额外的样式代码存在,虽然这些代码可能不会对本身的样式产生影响。\n\nBUNDLE 和 BUNDLELESS 构建产物区别\n\n对于以下代码,在 bundle 和 bundleless 两种模式下,构建产物会有很大区别。\n\n> 所谓 bundle 和 bundleless 可以查看 【Bundle 和 Bundleless】\n\nimport 'tailwindcss/utilities.css';\n\nexport default () => {\n return <div className=\"bg-black text-white\">hello world11</div>;\n};\n\n\nBundle 模式下,会将第三方依赖打包进来。\n\n对于样式则会生成一份单独的产物文件,并且在 Js 产物文件中并不会存在导入样式的相关代码。\n\n如果需要将样式注入 Js 产物中,可以开启 style.inject API。\n\n<CH.Code>\n\n/* ../../node_modules/.pnpm/tailwindcss@2.2.19/node_modules/tailwindcss/utilities.css */\n.table {\n display: table;\n}\n@keyframes spin {\n to {\n transform: rotate(360deg);\n }\n}\n@keyframes ping {\n 75%, 100% {\n transform: scale(2);\n opacity: 0;\n }\n}\n@keyframes pulse {\n 50% {\n opacity: .5;\n }\n}\n@keyframes bounce {\n 0%, 100% {\n transform: translateY(-25%);\n animation-timing-function: cubic-bezier(0.8, 0, 1, 1);\n }\n 50% {\n transform: none;\n animation-timing-function: cubic-bezier(0, 0, 0.2, 1);\n }\n}\n.bg-black {\n --tw-bg-opacity: 1;\n background-color: rgba(0, 0, 0, var(--tw-bg-opacity));\n}\n.text-white {\n --tw-text-opacity: 1;\n color: rgba(255, 255, 255, var(--tw-text-opacity));\n}\n*,\n::before,\n::after {\n --tw-shadow: 0 0 #0000 ;\n}\n*,\n::before,\n::after {\n --tw-ring-inset: var(--tw-empty, );\n --tw-ring-offset-width: 0px;\n --tw-ring-offset-color: #fff;\n --tw-ring-color: rgba(59, 130, 246, 0.5);\n --tw-ring-offset-shadow: 0 0 #0000;\n --tw-ring-shadow: 0 0 #0000 ;\n}\n@media (min-width: 640px) {\n}\n@media (min-width: 768px) {\n}\n@media (min-width: 1024px) {\n}\n@media (min-width: 1280px) {\n}\n@media (min-width: 1536px) {\n}\n\n\n--------------------------------------------------------------------------------\n\n// src/index.tsx\n\nvar src_default = () => {\n return /* @__PURE__ */ jsx(\"div\", {\n className: \"bg-black text-white\",\n children: \"hello world11\"\n });\n};\nexport {\n src_default as default\n};\n\n\n</CH.Code>\n\nBundleless 模式下,并不会将第三方依赖打包进来,此时不会有样式产物生成。\n\n\nimport 'tailwindcss/utilities.css';\nvar src_default = () => {\n return /* @__PURE__ */ jsx('div', {\n className: 'bg-black text-white',\n children: 'hello world11',\n });\n};\nexport { src_default as default };\n\n\n\nCSS MODULES\n\n模块工程支持使用 CSS Module 开发样式。默认情况下会将以下文件识别为 CSS Module 文件:\n\n * .module.css\n * .module.less\n * .module.scss\n * .module.sass\n\n如果需要对 CSS Modules 进行配置,可以查看一下 API:\n\n * autoModules\n * modules\n\n下面是一个代码示例:\n\n<CH.Code>\n\n\n\nexport default () => {\n return <div className={style.btn}>hello world</div>;\n};\n\n\n.btn {\n color: blue;\n}\n\n\n</CH.Code>\n\n\n配置构建产物\n\n根据组件项目使用的多数场景,推荐使用 npm-component 构建预设。该预设得到的产物目录结构为:\n\n.\n├── dist\n│ ├── es\n│ ├── lib\n│ └── types\n\n\n * ./dist/es: 包含了支持 es6 语法的 ES modules 格式的 bundleless 产物。\n * ./dist/lib: 包含了支持 es6 语法的 CommonJS 格式的 bundleless 产物。\n * ./dist/types: 包含了类型文件。\n\n如果对使用语法支持有要求,可以手动配置 buildPreset,并且支持在 npm-component 基础上增加后缀的方式修改支持的语法:\n\nexport default defineConfig({\n buildPreset: 'npm-component-es2019',\n});\n\n\n如果对构建产物目录结构有特殊需求,则可以使用 buildConfig API,可以通过以下文档来了解使用方式:\n\n * 修改输出产物\n * 深入理解构建\n\n\n测试组件\n\n关于如何对组件进行测试,可以参考 【测试项目】。\n\n\n发布组件\n\n推荐使用模块工程提供版本发布功能,可以参考 【版本管理与发布】。","frontmatter":{"sidebar_position":1}},{"id":52,"title":"快速开始","routePath":"/module-tools/guide/intro/getting-started","toc":[{"id":"三分钟快速上手-1","text":"三分钟快速上手","depth":2},{"id":"让我们开始吧-1","text":"让我们开始吧","depth":2}],"content":"快速开始\n\n\n三分钟快速上手\n\n想要实际体验 Module Tools?首先需要安装 Node.js LTS,并确保 Node 版本大于等于 14.18.0。\n\n然后在你的项目里安装以下依赖:\n\n * @modern-js/module-tools\n * @modern-js/plugin-testing\n\n> 如果是一个 TypeScript 项目,则需要增加 \"typescript\" 依赖。\n\nnpm install -D @modern-js/module-tools @modern-js/plugin-testing\n\n\n> 对于使用 pnpm 或者 Yarn 包管理器的项目,只需要替换 npm 就可以了。推荐使用 pnpm。\n\n接着在项目的 package.json 文件里增加命令 \"build\": \"modern build\":\n\n{\n \"scripts\": {\n \"build\": \"modern build\"\n }\n}\n\n\n如果你的项目存在 src/index.(js|jsx) 文件或者同时存在 src/index.(ts|tsx) 和 tsconfig.json\n文件,那么恭喜你可以运行直接运行 npm run build 来使用 Module Tools 构建你的项目了。\n\n如果你想要看看使用了模块工程方案的真实项目,可以执行以下命令:\n\ngit clone https://github.com/modern-js-dev/module-tools-examples\ncd module-tools-example\n\n## 执行构建:\npnpm build\n\n## 监听模式执行构建:\npnpm build --watch\n\n## 启动 Storybook\npnpm dev storybook\n\n## 测试\npnpm test\n\n\n> 上面的链接对应的内容待补充\n\n如果你想要创建一个完整的模块工程项目,可以执行以下命令:\n\nnpx @modern-js/create your-project-dir-name\n\n\n接着在问题交互中,按照如下选择:\n\n? 请选择你想创建的工程类型 模块\n? 请填写项目名称 library\n? 请选择开发语言 TS\n? 请选择包管理工具 pnpm\n\n\n> 项目名称为 package.json 中的 \"name\" 字段值。\n\n接着就会开始初始化项目的流程。在项目目录和文件生成以及依赖安装完毕后,此时就创建了一个完整的模块工程项目。\n\n我们可以直接执行 pnpm build 命令启动项目的构建,执行 pnpm build --watch 命令开启构建的观察模式。\n\n\n让我们开始吧\n\n选择适合你的教程:\n\n * 我是初学者,需要学习 Module Tools 的基础使用。\n * 我已经初步掌握了 Module Tools 的使用,可以学习 Module Tools 的高级使用。\n * 我是项目的维护者,需要学习如何开发 Module Tools 的插件以及了解更多关于 Module Tools 进阶的内容。","frontmatter":{"sidebar_position":3}},{"id":53,"title":"欢迎使用","routePath":"/module-tools/guide/intro/welcome","toc":[],"content":"欢迎使用\n\nModule Tools 是 Modern.js\n的模块工程解决方案,同时也是核心依赖。它可以让开发者更轻松地构建、调试、发布模块类型的项目。模块类型的项目大多数情况可以认为是 npm\n包类型的项目,它可能是一个组件、组件库或者工具库项目。\n\n如果你正打算开发一个 npm 包类型的项目,那么你就来对地方了!Modern.js 提供了专业的模块工程解决方案。它带来了:\n\n * 简单的项目初始化:仅需执行 npx @modern-js/create project-dir\n 命令,然后进行几个交互问题,就可以创建一个完整的模块类型项目。创建的项目还支持选择 pnpm、Yarn 两种包管理器。\n * 代码格式化:在模块工程项目中,你可以执行 modern lint 来对代码进行格式化。同时初始化的模块工程项目里包含了 Modern.js 的\n ESLint 规则集,可以满足大部分场景下的需求。\n * 全面的构建能力和更快的构建速度:Module Tools 基于 esbuild 和 SWC\n 提供了高性能的构建能力,并且为不同构建模块的场景提供了丰富的配置。\n * Storybook 调试工具:Module Tools 为调试模块项目提供了 Storybook 调试工具。在安装了 Module Tools 的\n Storybook 插件后,你可以使用 modern dev storybook 命令来启动它。你不仅可以使用 Storybook\n 对组件进行调试,也可以使用在其他类型的模块上。\n * 集成 Jest 的测试能力:在需要对模块测试的时候,可以使用 Module Tools 的 modern test 命令。Module Tools\n 不仅集成了 Jest,同时也提供了配置 Jest 的 API。\n * 基于 Changesets 实现的版本管理:当需要对项目记录变更内容的时候,可以使用 modern change 命令生成包含变更内容的 Markdown\n 文件;当需要对项目进行版本升级的时候,可以使用 modern bump 命令通过 Markdown 文件分析并升级版本;当需要发布项目的时候,可以使用\n modern release 命令对项目进行发布。Module Tools 基于 Changesets 实现了这些命令。\n * 可扩展性的插件机制:想要为项目集成其他的调试工具?又或者是想要在构建过程中做一些额外处理?Module Tools\n 提供了插件机制和插件钩子,插件钩子覆盖了 dev 命令和 build 命令两个流程。你可以通过它们为项目进行能力的扩展。\n * 还有更多:Module Tools\n 在未来还会不断的在构建、调试功能上进行优化。如果在模块项目构建上存在需要解决的重要问题,又或者是某个主流的模块项目调试工具、模式出现的时候,那么它们很可能\n 成为 Module Tools 将要支持功能。","frontmatter":{"sidebar_position":1}},{"id":54,"title":"为什么需要模块工程解决方案","routePath":"/module-tools/guide/intro/why-module-engineering-solution","toc":[],"content":"为什么需要模块工程解决方案\n\n大家可能都经历过:从零开始开发一个组件库或者工具库的过程中,我们不仅要考虑项目本身的代码逻辑如何编写,还要考虑项目的构建、调试、测试、代码格式化等等和代码逻辑无\n关的事情。\n\n比如说,当我们考虑构建模块项目的代码是使用什么构建工具的时候,在之前我们可能会考虑使用 webpack 还是 Rollup,然而现在的话,也许还会考虑是使用\nesbuild 还是 SWC。\n\n无论选择哪个构建工具,这对于没有熟练掌握这些构建工具使用方式的开发者来说,是需要一定的成本去学习的。即使想要快速使用,也会需要花费大量的时间和精力。\n\n而除了构建这件事情以外,像为项目提供调试工具、支持测试能力、增加代码格式校验等等,对于一个新手来说都有可能需要花费很长的时间和精力了解或者掌握它们,并且真正的服\n务于当前的项目中。\n\n而为了保证代码质量以及项目的完整性,我们往往是需要做这些与代码逻辑实现无关的事情。然而这些事情很有可能会影响整体的项目开发进度,降低开发者的开发体验,会让开发者\n感觉模块项目的开发门槛很高。\n\n如果说每次开发一个模块类型的项目都需要经历一遍这些工作准备的话,那么基本上刚开始开发的时间会大部分花费在这些与代码实现无关的事情上。如果能够提供一个模块工程解决\n方案,它能够帮助开发者解决项目工程上的事情,让开发者可以更专注于代码的实现上,那么这将会大大提升模块类型项目的开发体验。\n\n\n\nModern.js 为了让开发模块类型的项目更简单,为了解决上述提到的问题提供了模块工程解决方案,并且使用 Module Tools\n提供了主要的功能。Module-tools 可以理解为是一个专门用于模块类型项目开发的工具。","frontmatter":{"sidebar_position":2}},{"id":55,"title":"index","routePath":"/module-tools/","toc":[],"content":"INDEX","frontmatter":{"pageType":"home","hero":{"name":"Module Tools","text":"模块工程解决方案","tagline":"简单、强大、高性能的现代化npm包开发方案","actions":[{"theme":"brand","text":"欢迎使用","link":"/guide/intro/welcome"}]},"features":[{"title":"Esbuild: 高性能的JS Bundler","details":"基于 Esbuild 构建,构建速度极快,带给你极致的开发体验。","icon":"🚀"},{"title":"Storybook: 社区流行的UI开发工具","details":"集成了Storybook,你可以使用它调试UI。","icon":"📦"},{"title":"transform + bundle","details":"支持bundle和bundleless两种构建模式。","icon":"✨"},{"title":"零配置","details":"无需任何配置即可开发你的npm包,内置预设覆盖多种场景。","icon":"🛠️"},{"title":"扩展性强: 提供强大的插件机制","details":"通过其插件扩展机制,你可以轻松的扩展Module tools的各项能力。","icon":"🎨"}]}},{"id":56,"title":"快速开始","routePath":"/module-tools/plugins/guide/getting-started","toc":[],"content":"快速开始\n\n模块工程解决方案不仅提供了丰富的功能,同时也支持通过插件的方式为当前项目扩展能力。\n\n我们可以通过下面的例子来快速了解如果编写一个 module-tools 插件:\n\n<CH.Spotlight>\n\n./\n├── plugins\n│ └── example.ts\n├── src/\n└── modern.config.ts\n\n\n--------------------------------------------------------------------------------\n\n首先我们在初始化的项目下创建 ./plugins/example.ts 文件。\n\n\n\n--------------------------------------------------------------------------------\n\n接着在 example.ts 文件中增加插件的代码。\n\n\n\nexport const ExamplePlugin = (): CliPlugin<ModuleTools> => {\n return {\n name: 'example',\n setup() {\n console.info('this is example plugin');\n return {\n // use hooks\n afterBuild() {\n console.info('build over');\n }\n };\n };\n };\n};\n\n\n--------------------------------------------------------------------------------\n\n然后我们通过 plugins API,将刚刚写好的插件进行注册。\n\n\nexport default defineConfig({\n plugins: [examplePlugin()],\n});\n\n\n--------------------------------------------------------------------------------\n\n最后运行 modern build,就可以看到。\n\nthis is example plugin\nBuild succeed: 510.684ms\nbuild over\n\n\n</CH.Spotlight>\n\n通过上面这个例子,我们了解到了下面几件事:\n\n * 推荐的插件目录结构\n * 插件的初始化代码\n * 插件的注册\n\n除了以上内容以外,我们还需要了解:\n\n * 插件对象、类型定义与推荐配置项\n * setup 函数、api 对象参数、生命周期钩子","frontmatter":{"sidebar_position":1}},{"id":57,"title":"插件对象","routePath":"/module-tools/plugins/guide/plugin-object","toc":[{"id":"插件类型定义-1","text":"插件类型定义","depth":2},{"id":"插件配置项-1","text":"插件配置项","depth":2}],"content":"插件对象\n\nModule-tools 插件是一个对象,对象包含以下属性:\n\n * name:插件的名称,唯一标识符。\n * setup:插件初始化函数,只会执行一次。setup 函数可以返回一个 Hooks 对象,module-tools 会在特定的时机执行 Hooks\n 对象上定义的 Hook 对应的函数。\n\n例如在下面的插件代码示例中,在项目开始执行构建任务之前会触发 beforeBuild 函数的执行,并打印 build start 的 log 内容。\n\n<CH.Code>\n\n\n\nconst myPlugin: CliPlugin<ModuleTools> = {\n name: 'my-plugin',\n\n setup() {\n return {\n // this is hook\n beforeBuild: () => {\n console.info('build start');\n },\n };\n },\n};\n\n\n--------------------------------------------------------------------------------\n\n\nexport default {\n plugins: [myPlugin()],\n};\n\n\n</CH.Code>\n\n\n插件类型定义\n\n使用 TypeScript 时,可以引入内置的 CliPlugin 和 ModuleTools 类型,为插件提供正确的类型推导:\n\n\n\nconst myPlugin: CliPlugin<ModuleTools> = {\n name: 'my-plugin',\n\n setup() {\n const foo = '1';\n\n return {\n // this is hook\n afterBuild: () => {\n //...\n },\n };\n },\n};\n\n\n\n插件配置项\n\n建议将插件写成函数的形式,使插件能通过函数入参来接收配置项:\n\n\n\ntype MyPluginOptions = {\n foo: string;\n};\n\nconst myPlugin = (options: MyPluginOptions): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup() {\n console.log(options.foo);\n },\n});\n","frontmatter":{"sidebar_position":2}},{"id":58,"title":"Setup 函数","routePath":"/module-tools/plugins/guide/setup-function","toc":[{"id":"插件-api-对象-1","text":"插件 API 对象","depth":2},{"id":"apiuseappcontext-2","text":"api.useAppContext","depth":3},{"id":"apiuseresolvedconfigcontext-2","text":"api.useResolvedConfigContext","depth":3},{"id":"apiusehookrunners-2","text":"api.useHookRunners","depth":3},{"id":"异步-setup-1","text":"异步 setup","depth":2},{"id":"生命周期钩子-1","text":"生命周期钩子","depth":2}],"content":"SETUP 函数\n\n在【插件对象】 部分我们知道插件对象包含了一个 setup 函数,该函数不仅包含了一个 api 对象参数,同时还可以返回一个 Hooks 对象。\n\n\n插件 API 对象\n\n插件的 setup 函数会提供一个 api 对象参数,你可以调用该对象上提供的一些方法来获取到配置、项目上下文等信息。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n setup(api) {\n // 获取应用原始配置\n const config = api.useConfigContext();\n // 获取应用运行上下文\n const appContext = api.useAppContext();\n // 获取解析之后的最终配置\n const resolvedConfig = api.useResolvedConfigContext();\n },\n});\n\n\n\nAPI.USEAPPCONTEXT\n\n用于获取项目上下文信息。\n\nconst useAppContext: () => IAppContext;\n\ninterface IAppContext {\n appDirectory: string;\n configFile: string | false;\n packageName: string;\n nodeModulesDirectory: string;\n internalDirectory: string;\n plugins: {\n cli?: any;\n server?: any;\n }[];\n}\n\n\n通过实际的类型文件我们可以看到还存在着其他的字段,不过目前对于模块工程有意义的字段只有以上内容。api 对象其他的方法也是如此。\n\n\nAPI.USERESOLVEDCONFIGCONTEXT\n\n用于获取解析之后的最终配置。\n\n如果需要获取构建相关的最终配置,需要使用 beforeBuild Hook。\n\nconst useResolvedConfigContext: () => NormalizedConfig;\n\ninterface NormalizedConfig {\n buildConfig: PartialBuildConfig;\n buildPreset: BuildPreset;\n designSystem?: Record<string, any>;\n dev: Dev;\n plugins: PluginConfig;\n runtime: RuntimeConfig;\n runtimeByEntries?: RuntimeByEntriesConfig;\n _raw: UserConfig;\n}\n\n\n\nAPI.USEHOOKRUNNERS\n\n用于获取 Hooks 的执行器,并触发特定的 Hook 执行。\n\n\n\nexport default (): CliPlugin => ({\n name: 'my-plugin',\n\n async setup(api) {\n const hookRunners = api.useHookRunners();\n // 触发 afterBuild Hook\n await hookRunners.afterBuild();\n },\n});\n\n\n\n异步 SETUP\n\nCLI 插件的 setup 可以是一个异步函数,在初始化过程中执行异步逻辑。\n\nexport default (): CliPlugin<ModuleTools> => ({\n name: 'my-plugin',\n\n async setup(api) {\n await doSomething();\n },\n});\n\n\n\n生命周期钩子\n\n我们知道 setup 函数会返回一个 Hooks 对象,所谓 Hooks 对象也可以理解是具有 module-tools 生命周期钩子的对象。\n\n目前主要包含两类钩子:\n\n * 构建钩子:仅在执行 build 命令构建源码产物时触发。\n * buildPlatform 钩子:仅在执行 build --platform 命令生成其他构建产物时触发。\n * 调试钩子:运行 dev 命令时会触发的钩子。\n\n关于生命周期钩子的完整列表参考 API 文档。","frontmatter":{"sidebar_position":3}},{"id":59,"title":"总览","routePath":"/module-tools/plugins/official-list/overview","toc":[{"id":"官方插件-1","text":"官方插件","depth":2}],"content":"总览\n\n\n官方插件\n\n(建设中)","frontmatter":{}}]