@modern-js/main-doc 0.0.0-next-20221116121040

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 (531) hide show
  1. package/.eslintrc.js +12 -0
  2. package/CHANGELOG.md +15 -0
  3. package/LICENSE +144 -0
  4. package/en/configure/app/dev/asset-prefix.md +13 -0
  5. package/en/configure/app/dev/hmr.md +13 -0
  6. package/en/configure/app/dev/https.md +13 -0
  7. package/en/configure/app/dev/port.md +13 -0
  8. package/en/configure/app/dev/progress-bar.md +13 -0
  9. package/en/configure/app/dev/start-url.md +13 -0
  10. package/en/configure/app/html/app-icon.md +13 -0
  11. package/en/configure/app/html/crossorigin.md +13 -0
  12. package/en/configure/app/html/disable-html-folder.md +13 -0
  13. package/en/configure/app/html/favicon-by-entries.md +13 -0
  14. package/en/configure/app/html/favicon.md +13 -0
  15. package/en/configure/app/html/inject-by-entries.md +13 -0
  16. package/en/configure/app/html/inject.md +13 -0
  17. package/en/configure/app/html/meta-by-entries.md +13 -0
  18. package/en/configure/app/html/meta.md +13 -0
  19. package/en/configure/app/html/mount-id.md +13 -0
  20. package/en/configure/app/html/template-by-entries.md +13 -0
  21. package/en/configure/app/html/template-parameters-by-entries.md +13 -0
  22. package/en/configure/app/html/template-parameters.md +13 -0
  23. package/en/configure/app/html/template.md +13 -0
  24. package/en/configure/app/html/title-by-entries.md +13 -0
  25. package/en/configure/app/html/title.md +13 -0
  26. package/en/configure/app/output/asset-prefix.md +13 -0
  27. package/en/configure/app/output/assets-retry.md +13 -0
  28. package/en/configure/app/output/charset.md +13 -0
  29. package/en/configure/app/output/clean-dist-path.md +13 -0
  30. package/en/configure/app/output/convert-to-rem.md +13 -0
  31. package/en/configure/app/output/copy.md +13 -0
  32. package/en/configure/app/output/css-module-local-ident-name.md +13 -0
  33. package/en/configure/app/output/data-uri-limit.md +13 -0
  34. package/en/configure/app/output/disable-css-module-extension.md +13 -0
  35. package/en/configure/app/output/disable-filename-hash.md +13 -0
  36. package/en/configure/app/output/disable-inline-runtime-chunk.md +13 -0
  37. package/en/configure/app/output/disable-minimize.md +13 -0
  38. package/en/configure/app/output/disable-source-map.md +13 -0
  39. package/en/configure/app/output/dist-path.md +13 -0
  40. package/en/configure/app/output/enable-asset-fallback.md +13 -0
  41. package/en/configure/app/output/enable-asset-manifest.md +13 -0
  42. package/en/configure/app/output/enable-css-module-tsdeclaration.md +13 -0
  43. package/en/configure/app/output/enable-inline-scripts.md +13 -0
  44. package/en/configure/app/output/enable-inline-styles.md +13 -0
  45. package/en/configure/app/output/enable-latest-decorators.md +13 -0
  46. package/en/configure/app/output/externals.md +13 -0
  47. package/en/configure/app/output/filename.md +13 -0
  48. package/en/configure/app/output/legal-comments.md +13 -0
  49. package/en/configure/app/output/override-browserslist.md +13 -0
  50. package/en/configure/app/output/polyfill.md +13 -0
  51. package/en/configure/app/output/svg-default-export.md +13 -0
  52. package/en/configure/app/performance/build-cache.md +13 -0
  53. package/en/configure/app/performance/bundle-analyze.md +13 -0
  54. package/en/configure/app/performance/chunk-split.md +13 -0
  55. package/en/configure/app/performance/print-file-size.md +13 -0
  56. package/en/configure/app/performance/profile.md +13 -0
  57. package/en/configure/app/performance/remove-console.md +13 -0
  58. package/en/configure/app/performance/remove-moment-locale.md +13 -0
  59. package/en/configure/app/security/sri.md +13 -0
  60. package/en/configure/app/source/alias.md +13 -0
  61. package/en/configure/app/source/compile-js-data-uri.md +13 -0
  62. package/en/configure/app/source/define.md +13 -0
  63. package/en/configure/app/source/global-vars.md +13 -0
  64. package/en/configure/app/source/include.md +13 -0
  65. package/en/configure/app/source/module-scopes.md +13 -0
  66. package/en/configure/app/source/pre-entry.md +13 -0
  67. package/en/configure/app/source/resolve-extension-prefix.md +13 -0
  68. package/en/configure/app/source/resolve-main-fields.md +13 -0
  69. package/en/configure/app/tools/autoprefixer.md +13 -0
  70. package/en/configure/app/tools/babel.md +13 -0
  71. package/en/configure/app/tools/css-extract.md +13 -0
  72. package/en/configure/app/tools/css-loader.md +13 -0
  73. package/en/configure/app/tools/dev-server.md +13 -0
  74. package/en/configure/app/tools/html-plugin.md +13 -0
  75. package/en/configure/app/tools/inspector.md +13 -0
  76. package/en/configure/app/tools/less.md +13 -0
  77. package/en/configure/app/tools/minify-css.md +13 -0
  78. package/en/configure/app/tools/postcss.md +13 -0
  79. package/en/configure/app/tools/pug.md +13 -0
  80. package/en/configure/app/tools/sass.md +13 -0
  81. package/en/configure/app/tools/style-loader.md +13 -0
  82. package/en/configure/app/tools/styled-components.md +13 -0
  83. package/en/configure/app/tools/terser.md +13 -0
  84. package/en/configure/app/tools/ts-checker.md +13 -0
  85. package/en/configure/app/tools/ts-loader.md +13 -0
  86. package/en/configure/app/tools/webpack-chain.md +13 -0
  87. package/en/configure/app/tools/webpack.md +13 -0
  88. package/en/tutorials/foundations/_category_.json +5 -0
  89. package/en/tutorials/foundations/basic.md +8 -0
  90. package/en/tutorials/foundations/introduction.md +43 -0
  91. package/package.json +30 -0
  92. package/scripts/gen-config.ts +60 -0
  93. package/scripts/sync.ts +36 -0
  94. package/tsconfig.json +7 -0
  95. package/zh/apis/app/commands/_category_.json +8 -0
  96. package/zh/apis/app/commands/build.md +44 -0
  97. package/zh/apis/app/commands/dev.md +31 -0
  98. package/zh/apis/app/commands/index.md +12 -0
  99. package/zh/apis/app/commands/inspect.md +39 -0
  100. package/zh/apis/app/commands/lint.md +22 -0
  101. package/zh/apis/app/commands/new.md +59 -0
  102. package/zh/apis/app/commands/start.md +32 -0
  103. package/zh/apis/app/commands/test.md +36 -0
  104. package/zh/apis/app/commands/upgrade.md +23 -0
  105. package/zh/apis/app/hooks/_category_.json +8 -0
  106. package/zh/apis/app/hooks/api/_category_.json +4 -0
  107. package/zh/apis/app/hooks/api/framework/_category_.json +4 -0
  108. package/zh/apis/app/hooks/api/framework/app.md +100 -0
  109. package/zh/apis/app/hooks/api/framework/lambda.md +79 -0
  110. package/zh/apis/app/hooks/api/functions/_category_.json +4 -0
  111. package/zh/apis/app/hooks/api/functions/api.md +50 -0
  112. package/zh/apis/app/hooks/api/functions/app.md +10 -0
  113. package/zh/apis/app/hooks/api/functions/common.md +10 -0
  114. package/zh/apis/app/hooks/api/test.md +12 -0
  115. package/zh/apis/app/hooks/config/_category_.json +4 -0
  116. package/zh/apis/app/hooks/config/html.md +10 -0
  117. package/zh/apis/app/hooks/config/icon.md +17 -0
  118. package/zh/apis/app/hooks/config/mock.md +12 -0
  119. package/zh/apis/app/hooks/config/public.md +30 -0
  120. package/zh/apis/app/hooks/config/storybook.md +14 -0
  121. package/zh/apis/app/hooks/config/upload.md +48 -0
  122. package/zh/apis/app/hooks/index.md +12 -0
  123. package/zh/apis/app/hooks/modern-config.md +10 -0
  124. package/zh/apis/app/hooks/server/_category_.json +4 -0
  125. package/zh/apis/app/hooks/server/index.md +14 -0
  126. package/zh/apis/app/hooks/server/test.md +12 -0
  127. package/zh/apis/app/hooks/shared.md +8 -0
  128. package/zh/apis/app/hooks/src/_category_.json +4 -0
  129. package/zh/apis/app/hooks/src/app.md +41 -0
  130. package/zh/apis/app/hooks/src/error.md +10 -0
  131. package/zh/apis/app/hooks/src/eslint.md +9 -0
  132. package/zh/apis/app/hooks/src/index.md +35 -0
  133. package/zh/apis/app/hooks/src/pages.md +183 -0
  134. package/zh/apis/app/hooks/src/stories.md +14 -0
  135. package/zh/apis/app/hooks/src/test.md +12 -0
  136. package/zh/apis/app/overview.md +11 -0
  137. package/zh/apis/app/runtime/_category_.json +9 -0
  138. package/zh/apis/app/runtime/app/_category_.json +4 -0
  139. package/zh/apis/app/runtime/app/bootstrap.md +83 -0
  140. package/zh/apis/app/runtime/app/create-app.md +47 -0
  141. package/zh/apis/app/runtime/app/define-config.md +57 -0
  142. package/zh/apis/app/runtime/app/head.md +43 -0
  143. package/zh/apis/app/runtime/app/no-ssr.md +41 -0
  144. package/zh/apis/app/runtime/app/pre-render.md +77 -0
  145. package/zh/apis/app/runtime/app/use-module-app.md +60 -0
  146. package/zh/apis/app/runtime/app/use-module-apps.md +64 -0
  147. package/zh/apis/app/runtime/app/use-runtime-context.md +39 -0
  148. package/zh/apis/app/runtime/bff-server/_category_.json +4 -0
  149. package/zh/apis/app/runtime/bff-server/after-lambda-registed.md +35 -0
  150. package/zh/apis/app/runtime/bff-server/hook.md +120 -0
  151. package/zh/apis/app/runtime/bff-server/use-context.md +70 -0
  152. package/zh/apis/app/runtime/container/_category_.json +4 -0
  153. package/zh/apis/app/runtime/container/router.md +492 -0
  154. package/zh/apis/app/runtime/container/use-loader.md +64 -0
  155. package/zh/apis/app/runtime/default-alias.md +26 -0
  156. package/zh/apis/app/runtime/env.md +68 -0
  157. package/zh/apis/app/runtime/index.md +12 -0
  158. package/zh/apis/app/runtime/model/Provider.md +36 -0
  159. package/zh/apis/app/runtime/model/_category_.json +4 -0
  160. package/zh/apis/app/runtime/model/auto-actions.md +121 -0
  161. package/zh/apis/app/runtime/model/connect.md +134 -0
  162. package/zh/apis/app/runtime/model/create-app.md +74 -0
  163. package/zh/apis/app/runtime/model/create-store.md +60 -0
  164. package/zh/apis/app/runtime/model/handle-effect.md +106 -0
  165. package/zh/apis/app/runtime/model/model_.md +199 -0
  166. package/zh/apis/app/runtime/model/use-local-model.md +28 -0
  167. package/zh/apis/app/runtime/model/use-model.md +87 -0
  168. package/zh/apis/app/runtime/model/use-static-model.md +47 -0
  169. package/zh/apis/app/runtime/model/use-store.md +48 -0
  170. package/zh/apis/app/runtime/plugin/_category_.json +4 -0
  171. package/zh/apis/app/runtime/plugin/abstract.md +26 -0
  172. package/zh/apis/app/runtime/plugin/hook-api.md +896 -0
  173. package/zh/apis/app/runtime/plugin/hook.md +170 -0
  174. package/zh/apis/app/runtime/plugin/plugin-api.md +117 -0
  175. package/zh/apis/app/runtime/testing/_category_.json +4 -0
  176. package/zh/apis/app/runtime/testing/act.md +34 -0
  177. package/zh/apis/app/runtime/testing/cleanup.md +37 -0
  178. package/zh/apis/app/runtime/testing/render.md +52 -0
  179. package/zh/apis/app/runtime/testing/renderApp.md +31 -0
  180. package/zh/apis/app/runtime/utility/_category_.json +4 -0
  181. package/zh/apis/app/runtime/utility/css-in-js.md +60 -0
  182. package/zh/apis/app/runtime/utility/loadable/_category_.json +4 -0
  183. package/zh/apis/app/runtime/utility/loadable/lazy.md +29 -0
  184. package/zh/apis/app/runtime/utility/loadable/loadable-component.md +61 -0
  185. package/zh/apis/app/runtime/utility/loadable/loadable-library.md +67 -0
  186. package/zh/apis/app/runtime/utility/loadable/loadable_.md +110 -0
  187. package/zh/apis/app/runtime/web-server/_category_.json +4 -0
  188. package/zh/apis/app/runtime/web-server/hook.md +121 -0
  189. package/zh/apis/generator/overview.md +32 -0
  190. package/zh/apis/generator/plugin/_category_.json +4 -0
  191. package/zh/apis/generator/plugin/file/_category_.json +4 -0
  192. package/zh/apis/generator/plugin/file/addFile.md +52 -0
  193. package/zh/apis/generator/plugin/file/addHelper.md +26 -0
  194. package/zh/apis/generator/plugin/file/addManyFile.md +55 -0
  195. package/zh/apis/generator/plugin/file/addPartial.md +26 -0
  196. package/zh/apis/generator/plugin/file/introduce.md +37 -0
  197. package/zh/apis/generator/plugin/file/rmDir.md +24 -0
  198. package/zh/apis/generator/plugin/file/rmFile.md +24 -0
  199. package/zh/apis/generator/plugin/file/updateJSONFile.md +52 -0
  200. package/zh/apis/generator/plugin/file/updateModernConfig.md +26 -0
  201. package/zh/apis/generator/plugin/file/updateTextRawFile.md +33 -0
  202. package/zh/apis/generator/plugin/git/_category_.json +4 -0
  203. package/zh/apis/generator/plugin/git/gitAddAndCommit.md +20 -0
  204. package/zh/apis/generator/plugin/git/initGitRepo.md +16 -0
  205. package/zh/apis/generator/plugin/git/isInGitRepo.md +16 -0
  206. package/zh/apis/generator/plugin/hook/_category_.json +4 -0
  207. package/zh/apis/generator/plugin/hook/afterForged.md +35 -0
  208. package/zh/apis/generator/plugin/hook/onForged.md +35 -0
  209. package/zh/apis/generator/plugin/info/_category_.json +4 -0
  210. package/zh/apis/generator/plugin/info/isFileExit.md +22 -0
  211. package/zh/apis/generator/plugin/info/locale.md +17 -0
  212. package/zh/apis/generator/plugin/info/readDir.md +22 -0
  213. package/zh/apis/generator/plugin/input/_category_.json +4 -0
  214. package/zh/apis/generator/plugin/input/addInputAfter.md +48 -0
  215. package/zh/apis/generator/plugin/input/addInputBefore.md +48 -0
  216. package/zh/apis/generator/plugin/input/addOptionAfter.md +45 -0
  217. package/zh/apis/generator/plugin/input/addOptionBefore.md +45 -0
  218. package/zh/apis/generator/plugin/input/setInput.md +42 -0
  219. package/zh/apis/generator/plugin/input/setInputValue.md +28 -0
  220. package/zh/apis/generator/plugin/input/type.md +101 -0
  221. package/zh/apis/generator/plugin/introduce.md +93 -0
  222. package/zh/apis/generator/plugin/new/_category_.json +4 -0
  223. package/zh/apis/generator/plugin/new/createElement.md +33 -0
  224. package/zh/apis/generator/plugin/new/createSubProject.md +35 -0
  225. package/zh/apis/generator/plugin/new/enableFunc.md +46 -0
  226. package/zh/apis/generator/plugin/new/introduce.md +15 -0
  227. package/zh/apis/generator/plugin/npm/_category_.json +4 -0
  228. package/zh/apis/generator/plugin/npm/install.md +16 -0
  229. package/zh/apis/monorepo/commands/_category_.json +8 -0
  230. package/zh/apis/monorepo/commands/bump.md +42 -0
  231. package/zh/apis/monorepo/commands/change.md +58 -0
  232. package/zh/apis/monorepo/commands/clear.md +27 -0
  233. package/zh/apis/monorepo/commands/deploy.md +39 -0
  234. package/zh/apis/monorepo/commands/gen-release-note.md +35 -0
  235. package/zh/apis/monorepo/commands/index.md +12 -0
  236. package/zh/apis/monorepo/commands/lint.md +21 -0
  237. package/zh/apis/monorepo/commands/new.md +41 -0
  238. package/zh/apis/monorepo/commands/pre.md +68 -0
  239. package/zh/apis/monorepo/commands/release.md +20 -0
  240. package/zh/apis/monorepo/commands/upgrade.md +23 -0
  241. package/zh/apis/monorepo/hooks/_category_.json +8 -0
  242. package/zh/apis/monorepo/hooks/apps.md +12 -0
  243. package/zh/apis/monorepo/hooks/code-workspace.md +10 -0
  244. package/zh/apis/monorepo/hooks/examples.md +14 -0
  245. package/zh/apis/monorepo/hooks/features.md +14 -0
  246. package/zh/apis/monorepo/hooks/index.md +12 -0
  247. package/zh/apis/monorepo/hooks/packages.md +14 -0
  248. package/zh/apis/monorepo/hooks/pnpm-workspace.md +10 -0
  249. package/zh/apis/monorepo/hooks/pnpmfile.md +10 -0
  250. package/zh/apis/monorepo/overview.md +11 -0
  251. package/zh/community/index.md +3 -0
  252. package/zh/components/command-tip.md +57 -0
  253. package/zh/components/deploy.md +60 -0
  254. package/zh/components/dev-ide.md +1 -0
  255. package/zh/components/entry-name.md +15 -0
  256. package/zh/components/env-prepare.md +1 -0
  257. package/zh/components/launch-bff-choices.md +6 -0
  258. package/zh/components/reduck-tip.md +5 -0
  259. package/zh/configure/app/bff/_category_.json +4 -0
  260. package/zh/configure/app/bff/fetcher.md +32 -0
  261. package/zh/configure/app/bff/prefix.md +38 -0
  262. package/zh/configure/app/bff/proxy.md +76 -0
  263. package/zh/configure/app/dev/_category_.json +4 -0
  264. package/zh/configure/app/dev/asset-prefix.md +13 -0
  265. package/zh/configure/app/dev/hmr.md +13 -0
  266. package/zh/configure/app/dev/https.md +13 -0
  267. package/zh/configure/app/dev/port.md +13 -0
  268. package/zh/configure/app/dev/progress-bar.md +13 -0
  269. package/zh/configure/app/dev/proxy.md +79 -0
  270. package/zh/configure/app/dev/start-url.md +13 -0
  271. package/zh/configure/app/dev/with-master-app.md +35 -0
  272. package/zh/configure/app/html/app-icon.md +13 -0
  273. package/zh/configure/app/html/crossorigin.md +13 -0
  274. package/zh/configure/app/html/disable-html-folder.md +13 -0
  275. package/zh/configure/app/html/favicon-by-entries.md +13 -0
  276. package/zh/configure/app/html/favicon.md +13 -0
  277. package/zh/configure/app/html/inject-by-entries.md +13 -0
  278. package/zh/configure/app/html/inject.md +13 -0
  279. package/zh/configure/app/html/meta-by-entries.md +13 -0
  280. package/zh/configure/app/html/meta.md +13 -0
  281. package/zh/configure/app/html/mount-id.md +13 -0
  282. package/zh/configure/app/html/template-by-entries.md +13 -0
  283. package/zh/configure/app/html/template-parameters-by-entries.md +13 -0
  284. package/zh/configure/app/html/template-parameters.md +13 -0
  285. package/zh/configure/app/html/template.md +13 -0
  286. package/zh/configure/app/html/title-by-entries.md +13 -0
  287. package/zh/configure/app/html/title.md +13 -0
  288. package/zh/configure/app/output/_category_.json +4 -0
  289. package/zh/configure/app/output/asset-prefix.md +13 -0
  290. package/zh/configure/app/output/assets-retry.md +13 -0
  291. package/zh/configure/app/output/charset.md +13 -0
  292. package/zh/configure/app/output/clean-dist-path.md +13 -0
  293. package/zh/configure/app/output/convert-to-rem.md +13 -0
  294. package/zh/configure/app/output/copy.md +13 -0
  295. package/zh/configure/app/output/css-module-local-ident-name.md +13 -0
  296. package/zh/configure/app/output/data-uri-limit.md +13 -0
  297. package/zh/configure/app/output/disable-css-module-extension.md +13 -0
  298. package/zh/configure/app/output/disable-filename-hash.md +13 -0
  299. package/zh/configure/app/output/disable-inline-runtime-chunk.md +13 -0
  300. package/zh/configure/app/output/disable-minimize.md +13 -0
  301. package/zh/configure/app/output/disable-node-polyfill.md +24 -0
  302. package/zh/configure/app/output/disable-source-map.md +13 -0
  303. package/zh/configure/app/output/dist-path.md +13 -0
  304. package/zh/configure/app/output/enable-asset-fallback.md +13 -0
  305. package/zh/configure/app/output/enable-asset-manifest.md +13 -0
  306. package/zh/configure/app/output/enable-css-module-tsdeclaration.md +13 -0
  307. package/zh/configure/app/output/enable-inline-scripts.md +13 -0
  308. package/zh/configure/app/output/enable-inline-styles.md +13 -0
  309. package/zh/configure/app/output/enable-latest-decorators.md +13 -0
  310. package/zh/configure/app/output/enable-modern-mode.md +26 -0
  311. package/zh/configure/app/output/externals.md +13 -0
  312. package/zh/configure/app/output/filename.md +13 -0
  313. package/zh/configure/app/output/legal-comments.md +13 -0
  314. package/zh/configure/app/output/override-browserslist.md +13 -0
  315. package/zh/configure/app/output/polyfill.md +13 -0
  316. package/zh/configure/app/output/ssg.md +226 -0
  317. package/zh/configure/app/output/svg-default-export.md +13 -0
  318. package/zh/configure/app/performance/build-cache.md +13 -0
  319. package/zh/configure/app/performance/bundle-analyze.md +13 -0
  320. package/zh/configure/app/performance/chunk-split.md +13 -0
  321. package/zh/configure/app/performance/print-file-size.md +13 -0
  322. package/zh/configure/app/performance/profile.md +13 -0
  323. package/zh/configure/app/performance/remove-console.md +13 -0
  324. package/zh/configure/app/performance/remove-moment-locale.md +13 -0
  325. package/zh/configure/app/plugins.md +74 -0
  326. package/zh/configure/app/runtime/_category_.json +4 -0
  327. package/zh/configure/app/runtime/master-app.md +72 -0
  328. package/zh/configure/app/runtime/router.md +54 -0
  329. package/zh/configure/app/runtime/state.md +45 -0
  330. package/zh/configure/app/security/sri.md +13 -0
  331. package/zh/configure/app/server/_category_.json +4 -0
  332. package/zh/configure/app/server/base-url.md +36 -0
  333. package/zh/configure/app/server/port.md +21 -0
  334. package/zh/configure/app/server/public-routes.md +29 -0
  335. package/zh/configure/app/server/routes.md +92 -0
  336. package/zh/configure/app/server/ssr-by-entries.md +32 -0
  337. package/zh/configure/app/server/ssr.md +24 -0
  338. package/zh/configure/app/source/_category_.json +4 -0
  339. package/zh/configure/app/source/alias.md +13 -0
  340. package/zh/configure/app/source/compile-js-data-uri.md +13 -0
  341. package/zh/configure/app/source/config-dir.md +15 -0
  342. package/zh/configure/app/source/define.md +13 -0
  343. package/zh/configure/app/source/design-system.md +1156 -0
  344. package/zh/configure/app/source/disable-default-entries.md +23 -0
  345. package/zh/configure/app/source/enable-async-entry.md +53 -0
  346. package/zh/configure/app/source/entries-dir.md +42 -0
  347. package/zh/configure/app/source/entries.md +55 -0
  348. package/zh/configure/app/source/global-vars.md +13 -0
  349. package/zh/configure/app/source/include.md +13 -0
  350. package/zh/configure/app/source/module-scopes.md +13 -0
  351. package/zh/configure/app/source/pre-entry.md +13 -0
  352. package/zh/configure/app/source/resolve-extension-prefix.md +13 -0
  353. package/zh/configure/app/source/resolve-main-fields.md +13 -0
  354. package/zh/configure/app/testing/_category_.json +4 -0
  355. package/zh/configure/app/testing/transformer.md +17 -0
  356. package/zh/configure/app/tools/_category_.json +4 -0
  357. package/zh/configure/app/tools/autoprefixer.md +13 -0
  358. package/zh/configure/app/tools/babel.md +13 -0
  359. package/zh/configure/app/tools/css-extract.md +13 -0
  360. package/zh/configure/app/tools/css-loader.md +13 -0
  361. package/zh/configure/app/tools/dev-server.md +13 -0
  362. package/zh/configure/app/tools/esbuild.md +61 -0
  363. package/zh/configure/app/tools/html-plugin.md +13 -0
  364. package/zh/configure/app/tools/inspector.md +13 -0
  365. package/zh/configure/app/tools/jest.md +41 -0
  366. package/zh/configure/app/tools/less.md +13 -0
  367. package/zh/configure/app/tools/minify-css.md +13 -0
  368. package/zh/configure/app/tools/postcss.md +13 -0
  369. package/zh/configure/app/tools/pug.md +13 -0
  370. package/zh/configure/app/tools/sass.md +13 -0
  371. package/zh/configure/app/tools/style-loader.md +13 -0
  372. package/zh/configure/app/tools/styled-components.md +13 -0
  373. package/zh/configure/app/tools/tailwindcss.md +48 -0
  374. package/zh/configure/app/tools/terser.md +13 -0
  375. package/zh/configure/app/tools/ts-checker.md +13 -0
  376. package/zh/configure/app/tools/ts-loader.md +13 -0
  377. package/zh/configure/app/tools/webpack-chain.md +13 -0
  378. package/zh/configure/app/tools/webpack.md +13 -0
  379. package/zh/configure/app/usage.md +81 -0
  380. package/zh/configure/generator/introduce.md +113 -0
  381. package/zh/configure/generator/module.md +43 -0
  382. package/zh/configure/generator/monorepo.md +28 -0
  383. package/zh/configure/generator/mwa.md +127 -0
  384. package/zh/guides/advanced-features/_category_.json +9 -0
  385. package/zh/guides/advanced-features/bff/_category_.json +4 -0
  386. package/zh/guides/advanced-features/bff/bff-proxy.md +25 -0
  387. package/zh/guides/advanced-features/bff/bff-server.md +142 -0
  388. package/zh/guides/advanced-features/bff/frameworks.md +348 -0
  389. package/zh/guides/advanced-features/bff/function.md +236 -0
  390. package/zh/guides/advanced-features/code-split.md +68 -0
  391. package/zh/guides/advanced-features/compatibility.md +89 -0
  392. package/zh/guides/advanced-features/custom-app.md +4 -0
  393. package/zh/guides/advanced-features/eslint.md +146 -0
  394. package/zh/guides/advanced-features/index.md +12 -0
  395. package/zh/guides/advanced-features/low-level.md +44 -0
  396. package/zh/guides/advanced-features/ssg.md +151 -0
  397. package/zh/guides/advanced-features/ssr.md +186 -0
  398. package/zh/guides/advanced-features/testing.md +4 -0
  399. package/zh/guides/advanced-features/typescript.md +4 -0
  400. package/zh/guides/advanced-features/web-server.md +135 -0
  401. package/zh/guides/basic-features/_category_.json +9 -0
  402. package/zh/guides/basic-features/alias.md +67 -0
  403. package/zh/guides/basic-features/css/_category_.json +4 -0
  404. package/zh/guides/basic-features/css/css-in-js.md +38 -0
  405. package/zh/guides/basic-features/css/css-modules.md +86 -0
  406. package/zh/guides/basic-features/css/less-sass.md +29 -0
  407. package/zh/guides/basic-features/css/postcss.md +81 -0
  408. package/zh/guides/basic-features/css/tailwindcss.md +98 -0
  409. package/zh/guides/basic-features/data-fetch.md +4 -0
  410. package/zh/guides/basic-features/env-vars.md +83 -0
  411. package/zh/guides/basic-features/html.md +128 -0
  412. package/zh/guides/basic-features/image.md +43 -0
  413. package/zh/guides/basic-features/index.md +12 -0
  414. package/zh/guides/basic-features/mock.md +85 -0
  415. package/zh/guides/basic-features/proxy.md +85 -0
  416. package/zh/guides/basic-features/routes.md +4 -0
  417. package/zh/guides/concept/_category_.json +5 -0
  418. package/zh/guides/concept/entries.md +4 -0
  419. package/zh/guides/concept/integrated.md +4 -0
  420. package/zh/guides/concept/lifecycle.md +4 -0
  421. package/zh/guides/concept/solutions.md +4 -0
  422. package/zh/guides/get-started/_category_.json +5 -0
  423. package/zh/guides/get-started/quick-start.md +4 -0
  424. package/zh/guides/get-started/upgrade.md +4 -0
  425. package/zh/guides/overview.md +11 -0
  426. package/zh/guides/topic-detail/_category_.json +5 -0
  427. package/zh/guides/topic-detail/changesets/_category_.json +4 -0
  428. package/zh/guides/topic-detail/changesets/add.md +125 -0
  429. package/zh/guides/topic-detail/changesets/changelog.md +239 -0
  430. package/zh/guides/topic-detail/changesets/commit.md +272 -0
  431. package/zh/guides/topic-detail/changesets/config.md +146 -0
  432. package/zh/guides/topic-detail/changesets/github.md +168 -0
  433. package/zh/guides/topic-detail/changesets/introduce.md +57 -0
  434. package/zh/guides/topic-detail/changesets/release-note.md +262 -0
  435. package/zh/guides/topic-detail/changesets/release-pre.md +49 -0
  436. package/zh/guides/topic-detail/changesets/release.md +228 -0
  437. package/zh/guides/topic-detail/compile-speed.md +182 -0
  438. package/zh/guides/topic-detail/framework-plugin/_category_.json +4 -0
  439. package/zh/guides/topic-detail/framework-plugin/abstract.md +27 -0
  440. package/zh/guides/topic-detail/framework-plugin/extend.md +163 -0
  441. package/zh/guides/topic-detail/framework-plugin/implement.md +188 -0
  442. package/zh/guides/topic-detail/framework-plugin/relationship.md +119 -0
  443. package/zh/guides/topic-detail/generator-plugin/_category_.json +4 -0
  444. package/zh/guides/topic-detail/generator-plugin/abstract.md +23 -0
  445. package/zh/guides/topic-detail/generator-plugin/develop.md +120 -0
  446. package/zh/guides/topic-detail/generator-plugin/use.md +61 -0
  447. package/zh/guides/topic-detail/micro-frontend/_category_.json +4 -0
  448. package/zh/guides/topic-detail/micro-frontend/communicate.md +39 -0
  449. package/zh/guides/topic-detail/micro-frontend/debugging.md +168 -0
  450. package/zh/guides/topic-detail/micro-frontend/introduction.md +13 -0
  451. package/zh/guides/topic-detail/micro-frontend/mixed-stack.md +24 -0
  452. package/zh/guides/topic-detail/micro-frontend/route-mode.md +110 -0
  453. package/zh/guides/topic-detail/model/_category_.json +4 -0
  454. package/zh/guides/topic-detail/model/auto-actions.md +90 -0
  455. package/zh/guides/topic-detail/model/computed-state.md +151 -0
  456. package/zh/guides/topic-detail/model/define-model.md +66 -0
  457. package/zh/guides/topic-detail/model/faq.md +43 -0
  458. package/zh/guides/topic-detail/model/manage-effects.md +259 -0
  459. package/zh/guides/topic-detail/model/model-communicate.md +219 -0
  460. package/zh/guides/topic-detail/model/performance.md +173 -0
  461. package/zh/guides/topic-detail/model/quick-start.md +112 -0
  462. package/zh/guides/topic-detail/model/redux-integration.md +21 -0
  463. package/zh/guides/topic-detail/model/test-model.md +43 -0
  464. package/zh/guides/topic-detail/model/typescript-best-practice.md +71 -0
  465. package/zh/guides/topic-detail/model/use-model.md +244 -0
  466. package/zh/guides/topic-detail/model/use-out-of-modernjs.md +51 -0
  467. package/zh/guides/topic-detail/monorepo/_category_.json +4 -0
  468. package/zh/guides/topic-detail/monorepo/create-sub-project.md +64 -0
  469. package/zh/guides/topic-detail/monorepo/deploy.md +43 -0
  470. package/zh/guides/topic-detail/monorepo/intro.md +15 -0
  471. package/zh/guides/topic-detail/monorepo/publish.md +68 -0
  472. package/zh/guides/topic-detail/monorepo/sub-project-interface.md +170 -0
  473. package/zh/guides/troubleshooting/_category_.json +5 -0
  474. package/zh/guides/troubleshooting/compile.md +379 -0
  475. package/zh/guides/troubleshooting/dependencies.md +168 -0
  476. package/zh/tutorials/first-app/_category_.json +5 -0
  477. package/zh/tutorials/first-app/c01-getting-started/1.1-prerequisites.md +25 -0
  478. package/zh/tutorials/first-app/c01-getting-started/1.2-minimal-mwa.md +118 -0
  479. package/zh/tutorials/first-app/c01-getting-started/1.3-dev-command.md +29 -0
  480. package/zh/tutorials/first-app/c01-getting-started/1.4-enable-ssr.md +44 -0
  481. package/zh/tutorials/first-app/c01-getting-started/1.5-start-command.md +18 -0
  482. package/zh/tutorials/first-app/c01-getting-started/1.6-create-repo.md +31 -0
  483. package/zh/tutorials/first-app/c01-getting-started/_category_.json +3 -0
  484. package/zh/tutorials/first-app/c02-generator-and-studio/2.1-generator.md +87 -0
  485. package/zh/tutorials/first-app/c02-generator-and-studio/2.2-boilerplates.md +28 -0
  486. package/zh/tutorials/first-app/c02-generator-and-studio/2.3-configuration.md +21 -0
  487. package/zh/tutorials/first-app/c02-generator-and-studio/_category_.json +3 -0
  488. package/zh/tutorials/first-app/c03-ide/3.1-setting-up.md +55 -0
  489. package/zh/tutorials/first-app/c03-ide/3.2-hints-in-ide.md +66 -0
  490. package/zh/tutorials/first-app/c03-ide/3.3-autofix-in-ide.md +11 -0
  491. package/zh/tutorials/first-app/c03-ide/3.4-autofix-in-cli.md +63 -0
  492. package/zh/tutorials/first-app/c03-ide/_category_.json +3 -0
  493. package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.1-use-es6-plus.md +67 -0
  494. package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.2-use-typescript.md +111 -0
  495. package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.3-compatibility.md +67 -0
  496. package/zh/tutorials/first-app/c04-es6-plus-and-ts/_category_.json +3 -0
  497. package/zh/tutorials/first-app/c05-component/5.1-use-ui-library.md +68 -0
  498. package/zh/tutorials/first-app/c05-component/5.2-use-standalone-component.md +92 -0
  499. package/zh/tutorials/first-app/c05-component/_category_.json +3 -0
  500. package/zh/tutorials/first-app/c06-css-and-component/6.1-css-in-js.md +110 -0
  501. package/zh/tutorials/first-app/c06-css-and-component/6.2-utility-class.md +148 -0
  502. package/zh/tutorials/first-app/c06-css-and-component/6.3-postcss.md +84 -0
  503. package/zh/tutorials/first-app/c06-css-and-component/6.4-design-system.md +83 -0
  504. package/zh/tutorials/first-app/c06-css-and-component/6.5-storybook.md +77 -0
  505. package/zh/tutorials/first-app/c06-css-and-component/6.6-testing.md +113 -0
  506. package/zh/tutorials/first-app/c06-css-and-component/_category_.json +3 -0
  507. package/zh/tutorials/first-app/c07-app-entry/7.1-intro.md +64 -0
  508. package/zh/tutorials/first-app/c07-app-entry/7.2-add-entry-in-cli.md +104 -0
  509. package/zh/tutorials/first-app/c07-app-entry/7.3-manage-entries-by-hand.md +74 -0
  510. package/zh/tutorials/first-app/c07-app-entry/_category_.json +3 -0
  511. package/zh/tutorials/first-app/c08-client-side-routing/8.1-code-based-routing.md +153 -0
  512. package/zh/tutorials/first-app/c08-client-side-routing/8.2-file-based-routing.md +318 -0
  513. package/zh/tutorials/first-app/c08-client-side-routing/_category_.json +3 -0
  514. package/zh/tutorials/first-app/c09-bff/9.1-serverless.md +30 -0
  515. package/zh/tutorials/first-app/c09-bff/9.2-enable-bff.md +93 -0
  516. package/zh/tutorials/first-app/c09-bff/9.3-fetch-bff.md +205 -0
  517. package/zh/tutorials/first-app/c09-bff/_category_.json +3 -0
  518. package/zh/tutorials/first-app/c10-model/10.1-application-architecture.md +23 -0
  519. package/zh/tutorials/first-app/c10-model/10.2-add-model.md +185 -0
  520. package/zh/tutorials/first-app/c10-model/10.3-use-model.md +54 -0
  521. package/zh/tutorials/first-app/c10-model/10.4-testing.md +69 -0
  522. package/zh/tutorials/first-app/c10-model/_category_.json +3 -0
  523. package/zh/tutorials/first-app/c11-container/11.1-use-model-with-app-state.md +274 -0
  524. package/zh/tutorials/first-app/c11-container/11.2-add-container.md +106 -0
  525. package/zh/tutorials/first-app/c11-container/11.3-use-loader.md +61 -0
  526. package/zh/tutorials/first-app/c11-container/11.4-testing.md +56 -0
  527. package/zh/tutorials/first-app/c11-container/_category_.json +3 -0
  528. package/zh/tutorials/first-app/overview.md +11 -0
  529. package/zh/tutorials/foundations/_category_.json +5 -0
  530. package/zh/tutorials/foundations/basic.md +8 -0
  531. package/zh/tutorials/foundations/introduction.md +41 -0
@@ -0,0 +1,170 @@
1
+ ---
2
+ sidebar_position: 2
3
+ ---
4
+
5
+ # Hook 模型
6
+
7
+ 首先介绍一下 Modern.js 的基础的插件系统中的一些内容,包括 Hook 模型的工作方式、各个 Hook 模型的运行模式、Manager 的工作模式。
8
+
9
+ 每种 Hook 模型都是独立的,可以独立管理运行函数。
10
+
11
+ ## 基础工作方式
12
+
13
+ 先以 Pipeline 为例,简单介绍一下 Hook 模型的工作方式。先看一个简单的例子:
14
+
15
+ ```ts
16
+ import { createPipeline } from '@modern-js/plugin'
17
+
18
+ // 1. 创建
19
+ const pipeline = createPipeline<number, number>()
20
+
21
+ // 2. 添加函数
22
+ pipeline.use((count, next) => {
23
+ return next(count + 1)
24
+ })
25
+ pipeline.use((count, next) => {
26
+ return count * 2
27
+ })
28
+
29
+ // 3. 执行
30
+ pipeline.run(1) // 4
31
+ pipeline.run(5) // 12
32
+ ```
33
+
34
+ 在这个例子中,创建了一个 `Pipeline<number, number>` 类型的 Pipeline(L3),这意味着运行它的时候,你需要传入一个 `number`,然后你会得到一个 `number`,而这个模型管理的函数的类型是:
35
+
36
+ ```ts
37
+ (count: number, next: (nextCount: number) => number) => number
38
+ ```
39
+
40
+ 这里全是 `number`,是因为我们创建的是 `Pipeline<number, number>` ,如果创建的是 `Pipeline<number, string>` 则运行它入参是 `number`,返回值是 `string`,对应管理的函数的类型会是:
41
+
42
+ ```ts
43
+ (count: number, next: (nextCount: number) => string) => string
44
+ ```
45
+
46
+
47
+ 创建好 Pipeline 之后,可以通过 `use` 添加函数(L5、L8),需要注意的是,添加的顺序就是他们默认的运行顺序,在这些函数中,你可以对 `count` 进行处理、返回一个值,如果你调用了 `next` 函数,则会运行后面的函数,即如果你添加了三个函数: `A`、`B`、`C`,如果你在 `A` 中调用 `next` 那么就会运行 `B`,同样的,如果你在 `B` 中调用 `next` 那么就会运行 `C`,而在上面的例子中,添加的第一个函数(L5)就运行了 `next`,所以这里就会运行第二个函数(L8),并且运行的返回值就是 第二个函数的返回值,如果在第一个函数中没有调用 `next`,直接返回,例如:
48
+
49
+ ```ts
50
+ import { createPipeline } from '@modern-js/plugin'
51
+
52
+ // 1. 创建
53
+ const pipeline = createPipeline<number, number>()
54
+
55
+ // 2. 添加函数
56
+ pipeline.use((count, next) => {
57
+ return count + 1
58
+ })
59
+ pipeline.use((count, next) => {
60
+ return count * 2
61
+ })
62
+
63
+ // 3. 执行
64
+ pipeline.run(1) // 2
65
+ pipeline.run(5) // 6
66
+ ```
67
+
68
+ 则在运行 Pipeline 的时候就不会运行第二个函数,那么 Pipeline 的运行结果则就是第一个函数的返回值。
69
+
70
+ 最后,运行 Pipeline 的方式也显而易见就是调用 `pipeline.run` 。
71
+
72
+ ## 不同 Hook 模型的区别
73
+
74
+ 上面这部分就是 Pipeline 整体的一个工作模式的描述,其他的 Hook 模型的工作模式基本也是这样,主要的区别点,是函数类型、执行顺序,参数。
75
+
76
+ ### Pipeline
77
+
78
+ 上面的例子就是以 Pipeline 为例描述的,这里就不赘述了,在 Pipeline 这个大类中,提供了两个小类:Sync 和 Async,顾名思义,它们的区别就是管理的函数的类型是 Sync 的还是 Async 的。
79
+
80
+ :::info 注
81
+ 当 Pipeline 中没有函数或者所有函数都调用了 `next` 函数,则就需要在运行的时候提供:
82
+
83
+ ```ts
84
+ pipeline({}, {
85
+ onLast: () => {
86
+ // do something
87
+ }
88
+ })
89
+ ```
90
+ :::
91
+
92
+ ### Waterfall
93
+
94
+ 这种模型顾名思义,他的特点就是参数的顺序递交,即前面一个函数的返回值,将会成为下一个函数的入参,我们也用一个例子来看一下:
95
+
96
+ ```ts
97
+ import { createWaterfall } from '@modern-js/plugin'
98
+
99
+ // 1. 创建
100
+ const waterfall = createWaterfall<number>()
101
+
102
+ // 2. 添加函数
103
+ waterfall.use((count) => {
104
+ return count + 1
105
+ })
106
+ waterfall.use((count) => {
107
+ return count * 2
108
+ })
109
+
110
+ // 3. 执行
111
+ waterfall.run(1) // 4
112
+ waterfall.run(5) // 12
113
+ ```
114
+
115
+ 这个例子中,创建了一个类型为 `Waterfall<number> `,即这个模型执行的入参和返回值是一样的,这个例子中都是 `number`,而它管理的函数的类型是:
116
+
117
+ ```ts
118
+ (count: number) => number
119
+ ```
120
+
121
+ 可能简单看这个例子感觉和上面的 Pipeline 功能一样,那需要注意的是,首先这里 Waterfall 管理的函数没有next 函数作为第二个参数,所以它无法在函数内部通过调用 next 来先运行之后添加的函数,从而修改运行的顺序,其次这里的运行的入参的类型和返回值的类型必须是一样的(而 Pipeline 可以不一样)。
122
+
123
+ 同样的,在 Waterfall 这个大类中,也提供了 Sync 和 Async 的小类,分别对应 Sync 和 Async 的函数。
124
+
125
+ ### Workflow
126
+
127
+ 这种 Hook 模型与上面两种 Hook 模型的区别是,没有那么强的前后参数返回值递交的概念,在这个模型中,每个函数都是基于同样的入参,相对独立运行的,通过一个例子简单看一下:
128
+
129
+ ```ts
130
+ import { createWorkflow } from '@modern-js/plugin'
131
+
132
+ // 1. 创建
133
+ const workflow = createWorkflow <number, number>()
134
+
135
+ // 2. 添加函数
136
+ workflow.use((count) => {
137
+ return count + 1
138
+ })
139
+ workflow.use((count) => {
140
+ return count * 2
141
+ })
142
+
143
+ // 3. 执行
144
+ workflow.run(1) // [2, 2]
145
+ workflow.run(5) // [6, 10]
146
+ ```
147
+
148
+ 在这个例子中,添加了两个函数,所以运行的结果就是这两个函数运行的结果形成的一个数组。
149
+
150
+ 虽然这种模型中没有那么强的前后参数返回值递交的概念,但依旧有执行顺序的区别,在 Workflow 这个大类中,提供了三个小类:Sync、Async、Parallel。他们之间的区别就是函数的执行顺序,当然默认的都是按照添加顺序执行,而在 Sync、Async 则是强制按照添加顺序执行,而 Parallel 则是 Async 模式的一个变体,即它使用的是 `Promise.all` 来执行所有函数,而 Async 则会 `await` 前面的函数运行结束。
151
+
152
+ ## Hook 模型对比
153
+
154
+ <div style={{ width: "100%", overflowX: "scroll" }}>
155
+ <div style={{ width: "150%" }}>
156
+
157
+ ||函数类型|执行顺序|函数参数来源|执行返回值来源|倾向处理的任务类型|函数 TS 类型|
158
+ |-----|-----|-----|-----|----|----|----|
159
+ |Pipeline|Sync|默认执行第一个添加的函数,可以通过 next 调用之后添加的函数|第一个函数的参数来源是运行的参数,之后的函数的参数来源是,前一个函数向 next 函数传递的参数|第一个函数的返回值|<ul><li>需要修改初始参数</li><li>需要修改函数执行顺序</li></ul>|`(input: I, next: Next<I, O>) => O`|
160
+ |AsyncPipeline|Sync/Async|默认执行第一个添加的函数,可以通过 next 调用之后添加的函数|第一个函数的参数来源是运行的参数,之后的函数的参数来源是,前一个函数向 next 函数传递的参数|第一个函数的返回值|<ul><li>需要修改初始参数</li><li>需要修改函数执行顺序</li></ul>|`(input: I, next: AsyncNext<I, O>) => O | Promise<O>`|
161
+ |WaterFall|Sync|一直顺序执行|第一个函数的参数来源是运行的参数,之后的函数的参数来源是,前一个函数的返回值|最后一个函数的返回值|<ul><li>需要修改初始参数</li><li>不需要修改函数执行顺序</li></ul>|`(I: I) => I`|
162
+ |AsyncWaterFall|Sync/Async|一直顺序执行|第一个函数的参数来源是运行的参数,之后的函数的参数来源是,前一个函数的返回值|最后一个函数的返回值|<ul><li>需要修改初始参数</li><li>不需要修改函数执行顺序</li></ul>|`(I: I) => I | Promise<I>`|
163
+ |Workflow|Sync|一直顺序执行|所有函数的入参都是运行的参数|所有函数返回值形成的数组|<ul><li>不需要修改初始参数</li><li>不需要修改函数执行顺序</li></ul>|`(I: I) => O`|
164
+ |AsyncWorkflow|Sync/Async|一直顺序执行|所有函数的入参都是运行的参数|所有函数返回值形成的数组|<ul><li>不需要修改初始参数</li><li>不需要修改函数执行顺序</li></ul>|`(I: I) => O | Promise<O>`|
165
+ |ParallelWorkFlow|Sync/Async|异步执行|所有函数的入参都是运行的参数|所有函数返回值形成的数组|<ul><li>不需要修改初始参数</li><li>不关心执行顺序</li></ul>|`(I: I) => O | Promise<O>`|
166
+
167
+ </div>
168
+ </div>
169
+
170
+ Workflow、Waterfall 其实都是 Pipeline 的变体,Pipeline 可以通过特定的写法来实现 Workflow、Waterfall ,但都较为麻烦,有许多隐形的约定,为了方便使用,提供了这两种变体来满足这种特殊场景。
@@ -0,0 +1,117 @@
1
+ ---
2
+ sidebar_position: 5
3
+ ---
4
+
5
+ # Plugin API
6
+
7
+ 插件的 setup 函数会接收一个 api 入参,你可以调用 api 上提供的一些方法来获取到配置、应用上下文等信息。
8
+
9
+ ```ts
10
+ import type { CliPlugin } from '@modern-js/core';
11
+
12
+ export default (): CliPlugin => ({
13
+ name: 'my-plugin',
14
+
15
+ setup(api) {
16
+ // 获取应用原始配置
17
+ const config = api.useConfigContext();
18
+ // 获取应用运行上下文
19
+ const appContext = api.useAppContext();
20
+ // 获取解析之后的最终配置
21
+ const resolvedConfig = api.useResolvedConfigContext();
22
+ },
23
+ });
24
+ ```
25
+
26
+ ## API
27
+
28
+ ### useConfigContext
29
+
30
+ 用于获取应用原始配置。
31
+
32
+ ```ts
33
+ const useConfigContext: () => UserConfig
34
+
35
+ interface UserConfig {
36
+ source?: SourceConfig;
37
+ output?: OutputConfig;
38
+ server?: ServerConfig;
39
+ dev?: DevConfig;
40
+ deploy?: DeployConfig;
41
+ tools?: ToolsConfig;
42
+ plugins?: PluginConfig;
43
+ runtime?: RuntimeConfig;
44
+ runtimeByEntries?: RuntimeByEntriesConfig;
45
+ }
46
+ ```
47
+
48
+ 具体配置字段的意义请参考【[配置](/docs/configure/app/source/alias)】。
49
+
50
+ ### useAppContext
51
+
52
+ 用于获取应用运行上下文。
53
+
54
+ ```ts
55
+ const useAppContext: () => IAppContext
56
+
57
+ interface IAppContext {
58
+ appDirectory: string;
59
+ configFile: string | false;
60
+ ip?: string;
61
+ port?: number;
62
+ distDirectory: string;
63
+ packageName: string;
64
+ srcDirectory: string;
65
+ sharedDirectory: string;
66
+ nodeModulesDirectory: string;
67
+ internalDirectory: string;
68
+ plugins: {
69
+ cli?: any;
70
+ server?: any;
71
+ }[];
72
+ entrypoints: Entrypoint[];
73
+ serverRoutes: ServerRoute[];
74
+ htmlTemplates: HtmlTemplates;
75
+ }
76
+ ```
77
+
78
+ ### useResolvedConfigContext
79
+
80
+ 用于获取解析之后的最终配置。
81
+
82
+ ```ts
83
+ const useResolvedConfigContext: () => NormalizedConfig
84
+
85
+ interface NormalizedConfig {
86
+ source: NormalizedSourceConfig;
87
+ output: OutputConfig;
88
+ server: ServerConfig;
89
+ dev: DevConfig;
90
+ deploy: DeployConfig;
91
+ tools: NormalizedToolsConfig;
92
+ plugins: PluginConfig;
93
+ runtime: RuntimeConfig;
94
+ runtimeByEntries?: RuntimeByEntriesConfig;
95
+ _raw: UserConfig
96
+ }
97
+ ```
98
+
99
+ 具体配置字段的意义请参考【[配置](/docs/configure/app/source/alias)】。
100
+
101
+ ### useHookRunners
102
+
103
+ 用于获取 Hooks 的执行器,并触发特定的 Hook 执行。
104
+
105
+ ```ts
106
+ import type { CliPlugin } from '@modern-js/core';
107
+
108
+ export default (): CliPlugin => ({
109
+ name: 'my-plugin',
110
+
111
+ async setup(api) {
112
+ const hookRunners = api.useHookRunners();
113
+ // 触发 afterBuild Hook
114
+ await hookRunners.afterBuild();
115
+ },
116
+ });
117
+ ```
@@ -0,0 +1,4 @@
1
+ {
2
+ "label": "Testing API",
3
+ "position": 5
4
+ }
@@ -0,0 +1,34 @@
1
+ ---
2
+ title: act
3
+ sidebar_position: 4
4
+ ---
5
+
6
+ :::info 补充信息
7
+ 用于确保渲染、事件、数据获取等行为已经应用在 DOM 上。
8
+ ```ts
9
+ import { act } from '@modern-js/runtime/testing';
10
+ ```
11
+ :::
12
+
13
+ ## API
14
+
15
+ `act` 和 [react-dom/test-utils act 函数](https://reactjs.org/docs/testing-recipes.html#act) 是一致的。
16
+
17
+ ## 示例
18
+
19
+ ```tsx
20
+ import ReactDOM from 'react-dom';
21
+ import { act } from '@modern-js/runtime/testing';
22
+ import { Foo } from '@/components/Foo';
23
+
24
+ describe('test act', () => {
25
+ it('it should be foo', () => {
26
+ const el = document.createElement("div");
27
+ act(() => {
28
+ ReactDOM.render(<Foo />, el);
29
+ })
30
+
31
+ expect(el.innerHTML).toBe('<div>Foo</div>');
32
+ })
33
+ })
34
+ ```
@@ -0,0 +1,37 @@
1
+ ---
2
+ title: cleanup
3
+ sidebar_position: 3
4
+ ---
5
+
6
+ :::info 补充信息
7
+ 用于卸载掉当前已渲染的所有组件。
8
+ ```ts
9
+ import { cleanup } from '@modern-js/runtime/testing';
10
+ ```
11
+ :::
12
+
13
+ ## API
14
+
15
+ `cleanup() => void`
16
+
17
+ ## 示例
18
+
19
+ :::info 注
20
+ 请注意,如果你使用的测试框架支持 afterEach,并且它被注入到你的测试环境中(如mocha、Jest和Jasmine),**会默认在 afterEach 钩子里执行 `cleanup`**。否则,你将需要在每次测试后进行手动清理。
21
+ :::
22
+
23
+ 例如,如果你使用[ava](https://github.com/avajs/ava)测试框架,那么你需要像这样使用test.afterEach钩子。
24
+
25
+ ```tsx
26
+ import { cleanup, render } from '@modern-js/runtime/testing';
27
+ import test from 'ava'
28
+
29
+ test.afterEach(cleanup)
30
+
31
+ test('renders into document', () => {
32
+ render(<div />)
33
+ // ...
34
+ })
35
+
36
+ // ... more tests ...
37
+ ```
@@ -0,0 +1,52 @@
1
+ ---
2
+ title: render
3
+ sidebar_position: 1
4
+ ---
5
+
6
+ :::info 补充信息
7
+ 用于在测试用例中渲染组件,完成测试。
8
+ ```ts
9
+ import { render } from '@modern-js/runtime/testing';
10
+ ```
11
+ :::
12
+
13
+
14
+ ## API
15
+
16
+ `render(ui, [options]) => RenderResult`
17
+
18
+ ### 参数
19
+
20
+ - ui: `React.ReactElement<any>`,需要被渲染的 React 组件。
21
+ - [options]: `object`,render 可选配置。
22
+ - container: `DOMElement`,表示组件所要挂载到的 DOM 节点,默认是会创建一个 `div` 元素,并自动添加到 `document.body` 上。这个 `div` 元素就是组件要挂载的节点。默认值是 `document.body.append(document.createElement('div'))`。
23
+ - baseElement: `DOMElement`,用于指定 `queries` 中使用到的 `basename`。如果指定了 `container`, 则默认值为 `container` 的值,否则就是 `document.body`。
24
+ - hydrate: `boolean`,如果设置为 `true`,则会使用 [ReactDOM.hydrate](https://reactjs.org/docs/react-dom.html#hydrate) 渲染组件。默认值为 `false`。
25
+ - wrapper: `React.ComponentType<{children: ReactNode}>`,是一个 react 组件,可用于自定义渲染逻辑。
26
+ - queries: `any`,自定义一些自己的 `queries`。
27
+
28
+
29
+ ### 返回值
30
+
31
+ - {...queries}: `any`, 所有可用的 [queries](https://testing-library.com/docs/queries/about/)。
32
+ - container: `DOMElement`,`container` 是挂载 React 组件的 DOM 节点。
33
+ - baseElement: `DOMElement`。
34
+ - debug: `function`。
35
+ - rerender: `function`,如果想测试一个已渲染的组件在其 props 更新时的一些场景,可以使用 rerender 来现实。
36
+ - unmount: `function`,会卸载掉已渲染的组件。如果想测试组件卸载后的情况(如,绑定的事件是否在 unmount 阶段被卸载掉),那么这个 API 是很帮助的。
37
+ - asFragment: `function`,返回当前渲染的组件的 [DocumentFragment](https://developer.mozilla.org/en-US/docs/Web/API/DocumentFragment) 对象。可用于测试 react 事件触发后 DOM 结构的响应。
38
+
39
+
40
+ ## 示例
41
+
42
+ ```ts
43
+ import { render } from '@modern-js/runtime/testing';
44
+
45
+ test('renders a message', () => {
46
+ const { container, getByText } = render(<Greeting />)
47
+ expect(getByText('Hello, world!')).toBeInTheDocument()
48
+ expect(container.firstChild).toMatchInlineSnapshot(`
49
+ <h1>Hello, World!</h1>
50
+ `)
51
+ })
52
+ ```
@@ -0,0 +1,31 @@
1
+ ---
2
+ title: renderApp
3
+ sidebar_position: 2
4
+ ---
5
+
6
+ :::info 补充信息
7
+ `render` 函数用于测试普通组件,`renderApp` 函数用于测试应用组件。
8
+ ```ts
9
+ import { renderApp } from '@modern-js/runtime/testing';
10
+ ```
11
+ :::
12
+
13
+ 应用组件指包含一些 Modern 上下文的组件,如 App根组件,使用了 model 的 Container 等。对于这类组件的测试,可以使用 `renderApp` 函数,会自动按照当前 `modern.config.js` 配置,包裹上对应的上下文信息。
14
+
15
+ ## API
16
+
17
+ `renderApp` 在 API 层面和 [render](./render.md) 完全一致。
18
+
19
+ ## 示例
20
+
21
+ ```ts
22
+ import { renderApp } from '@modern-js/runtime/testing';
23
+ import App from '../App';
24
+
25
+ describe('test', () => {
26
+ it('test App', () => {
27
+ const { getByText } = renderApp(<App />);
28
+ expect(getByText('Hello Modern!')).toBeInTheDocument();
29
+ });
30
+ })
31
+ ```
@@ -0,0 +1,4 @@
1
+ {
2
+ "label": "Utility API",
3
+ "position": 6
4
+ }
@@ -0,0 +1,60 @@
1
+ ---
2
+ title: CSS-In-JS API
3
+ sidebar_position: 2
4
+ ---
5
+
6
+ :::info 补充信息
7
+ 通过 Style Component 在页面上使用 CSS。
8
+ ```ts
9
+ import styled from '@modern-js/runtime/styled';
10
+ ```
11
+ :::
12
+
13
+ `styled` 具体API,请看:[styled-component api](https://styled-components.com/docs/api)。
14
+
15
+ ## API
16
+
17
+ 请看 [styled-component API](https://styled-components.com/docs/api)。
18
+
19
+ ## 示例
20
+
21
+ ```tsx
22
+ import styled from '@modern-js/runtime/styled';
23
+
24
+ const Button = styled.button`
25
+ background: palevioletred;
26
+ border-radius: 3px;
27
+ border: none;
28
+ color: white;
29
+ `
30
+
31
+ const TomatoButton = styled(Button)`
32
+ background: tomato;
33
+ `
34
+
35
+ render(
36
+ <>
37
+ <Button>I'm purple.</Button>
38
+ <br />
39
+ <TomatoButton>I'm red.</TomatoButton>
40
+ </>
41
+ )
42
+ `
43
+
44
+ render(
45
+ <div>
46
+ <Button
47
+ href="https://github.com/styled-components/styled-components"
48
+ target="_blank"
49
+ rel="noopener"
50
+ primary
51
+ >
52
+ GitHub
53
+ </Button>
54
+
55
+ <Button as={Link} href="/docs">
56
+ Documentation
57
+ </Button>
58
+ </div>
59
+ )
60
+ ```
@@ -0,0 +1,4 @@
1
+ {
2
+ "label": "loadable",
3
+ "position": 9
4
+ }
@@ -0,0 +1,29 @@
1
+ ---
2
+ title: lazy
3
+ sidebar_position: 2
4
+ ---
5
+
6
+ :::info
7
+ 用于创建支持 [Suspense](https://reactjs.org/docs/react-api.html#reactsuspense) 的 `loadable 组件`。
8
+ ```ts
9
+ import { lazy } from '@modern-js/runtime/loadable';
10
+ ```
11
+ :::
12
+ ## API
13
+
14
+ ### lazy
15
+
16
+ ```ts
17
+ import { lazy } from '@modern-js/runtime/loadable';
18
+ const OtherComponent = lazy(() => import('./OtherComponent'));
19
+ ```
20
+
21
+ ### lazy.lib
22
+
23
+ 创建一个支持 [Suspense](https://reactjs.org/docs/react-api.html#reactsuspense) 的 `loadable 库`。
24
+
25
+ ```ts
26
+ import { lazy } from '@modern-js/runtime/loadable';
27
+ const Moment = lazy.lib(() => import('moment'))
28
+ ```
29
+
@@ -0,0 +1,61 @@
1
+ ---
2
+ title: LoadableComponent
3
+ sidebar_position: 3
4
+ ---
5
+
6
+ `LoadableComponent` 是 `loadable` 或 `lazy` 函数返回的对象类型。
7
+
8
+ ## LoadableComponent 类型
9
+
10
+ ```ts
11
+ type LoadableComponent<Props> =
12
+ React.ComponentType<
13
+ Props & { fallback?: JSX.Element; }>
14
+ & {
15
+ preload(props?: Props): void;
16
+ load(props?: Props): Promise<React.ComponentType<Props>>;
17
+ }
18
+ ```
19
+
20
+ ### props
21
+
22
+ 类型:`object`
23
+
24
+ `LoadableComponent` 组件可接收任意 props 参数,这些参数会转发给 loadFn。
25
+
26
+ ### fallback
27
+
28
+ 类型:`JSX.Element`
29
+
30
+ 当组件尚未加载完成(即 loading 阶段)会显示 `fallback` 内容。
31
+
32
+ ## LoadableComponent.preload
33
+
34
+ ```ts
35
+ import loadable from '@modern-js/runtime/loadable'
36
+
37
+ const OtherComponent = loadable(() => import('./OtherComponent'))
38
+ OtherComponent.preload()
39
+ ```
40
+
41
+ `preload` 接收的参数会全部传给 `loadFn`。
42
+
43
+ :::info 注
44
+ 预加载脚本中函数始终不会返回一个 Promise 对象,如果你想等待组件加载完成,请使用 [load](#LoadableComponent.load) 函数
45
+ :::
46
+
47
+
48
+ ## LoadableComponent.load
49
+
50
+ ```ts
51
+ import loadable from '@modern-js/runtime/loadable'
52
+
53
+ const OtherComponent = loadable(() => import('./OtherComponent'))
54
+ OtherComponent.load().then(() => {
55
+ console.log('Component is loaded!')
56
+ })
57
+ ```
58
+
59
+ :::info 注
60
+ 如果你无需等待组件加载完成,则使用 [preload](#LoadableComponent.preload) 即可。
61
+ :::
@@ -0,0 +1,67 @@
1
+ ---
2
+ title: LoadableLibrary
3
+ sidebar_position: 4
4
+ ---
5
+
6
+ `lazy.lib` 和 `loadable.lib` 函数返回 `LoadableLibrary` 对象
7
+
8
+ ## LoadableLibrary 类型
9
+
10
+ ```ts
11
+ type LoadableLibrary = React.ComponentType<{
12
+ fallback?: JSX.Element;
13
+ children?: (module: Module) => React.ReactNode;
14
+ ref?: React.Ref<Module>;
15
+ }>
16
+ ```
17
+
18
+ ### fallback
19
+
20
+ 类型:`JSX.Element`
21
+
22
+ 组件 `loading` 阶段显示 `fallback` 内容。
23
+
24
+ ### children
25
+
26
+ 库加载完成只有的回调。
27
+
28
+ ```ts
29
+ import loadable from '@modern-js/runtime/loadable'
30
+ const Moment = loadable.lib(() => import('moment'))
31
+ function FromNow({ date }) {
32
+ return (
33
+ <div>
34
+ <Moment fallback={date.toLocaleDateString()}>
35
+ {({ default: moment }) => moment(date).fromNow()}
36
+ </Moment>
37
+ </div>
38
+ )
39
+ }
40
+ ```
41
+
42
+ ### ref
43
+
44
+ 类型:`React.Ref<Module>`
45
+
46
+ 可以通过 `ref` 拿到所加载库的实例。
47
+
48
+ ```ts
49
+ import loadable from '@modern-js/runtime/loadable'
50
+ const Moment = loadable.lib(() => import('moment'))
51
+ class MyComponent {
52
+ moment = React.createRef()
53
+ handleClick = () => {
54
+ if (this.moment.current) {
55
+ return alert(this.moment.current.default.format('HH:mm'))
56
+ }
57
+ }
58
+ render() {
59
+ return (
60
+ <div>
61
+ <button onClick={this.handleClick}>What time is it?</button>
62
+ <Moment ref={this.moment} />
63
+ </div>
64
+ )
65
+ }
66
+ }
67
+ ```