@modern-js/main-doc 2.0.0-beta.2 → 2.0.0-beta.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (276) hide show
  1. package/.turbo/turbo-build.log +1 -1
  2. package/en/docusaurus-plugin-content-docs/current/apis/app/commands/new.md +0 -2
  3. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/core/bootstrap.md +17 -3
  4. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/create-app.md +1 -1
  5. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/model/use-store.md +0 -22
  6. package/en/docusaurus-plugin-content-docs/current/components/reduck-migration.md +1 -0
  7. package/en/docusaurus-plugin-content-docs/current/configure/app/dev/asset-prefix.md +1 -1
  8. package/en/docusaurus-plugin-content-docs/current/configure/app/dev/hmr.md +1 -1
  9. package/en/docusaurus-plugin-content-docs/current/configure/app/dev/https.md +1 -1
  10. package/en/docusaurus-plugin-content-docs/current/configure/app/dev/port.md +1 -1
  11. package/en/docusaurus-plugin-content-docs/current/configure/app/dev/progress-bar.md +1 -1
  12. package/en/docusaurus-plugin-content-docs/current/configure/app/dev/start-url.md +1 -1
  13. package/en/docusaurus-plugin-content-docs/current/configure/app/experiments/lazy-compilation.md +1 -1
  14. package/en/docusaurus-plugin-content-docs/current/configure/app/html/app-icon.md +1 -1
  15. package/en/docusaurus-plugin-content-docs/current/configure/app/html/crossorigin.md +1 -1
  16. package/en/docusaurus-plugin-content-docs/current/configure/app/html/disable-html-folder.md +1 -1
  17. package/en/docusaurus-plugin-content-docs/current/configure/app/html/favicon-by-entries.md +1 -1
  18. package/en/docusaurus-plugin-content-docs/current/configure/app/html/favicon.md +1 -1
  19. package/en/docusaurus-plugin-content-docs/current/configure/app/html/inject-by-entries.md +1 -1
  20. package/en/docusaurus-plugin-content-docs/current/configure/app/html/inject.md +1 -1
  21. package/en/docusaurus-plugin-content-docs/current/configure/app/html/meta-by-entries.md +1 -1
  22. package/en/docusaurus-plugin-content-docs/current/configure/app/html/meta.md +1 -1
  23. package/en/docusaurus-plugin-content-docs/current/configure/app/html/mount-id.md +1 -1
  24. package/en/docusaurus-plugin-content-docs/current/configure/app/html/template-by-entries.md +1 -1
  25. package/en/docusaurus-plugin-content-docs/current/configure/app/html/template-parameters-by-entries.md +1 -1
  26. package/en/docusaurus-plugin-content-docs/current/configure/app/html/template-parameters.md +1 -1
  27. package/en/docusaurus-plugin-content-docs/current/configure/app/html/template.md +1 -1
  28. package/en/docusaurus-plugin-content-docs/current/configure/app/html/title-by-entries.md +1 -1
  29. package/en/docusaurus-plugin-content-docs/current/configure/app/html/title.md +1 -1
  30. package/en/docusaurus-plugin-content-docs/current/configure/app/output/asset-prefix.md +1 -1
  31. package/en/docusaurus-plugin-content-docs/current/configure/app/output/assets-retry.md +1 -1
  32. package/en/docusaurus-plugin-content-docs/current/configure/app/output/charset.md +1 -1
  33. package/en/docusaurus-plugin-content-docs/current/configure/app/output/clean-dist-path.md +1 -1
  34. package/en/docusaurus-plugin-content-docs/current/configure/app/output/convert-to-rem.md +1 -1
  35. package/en/docusaurus-plugin-content-docs/current/configure/app/output/copy.md +1 -1
  36. package/en/docusaurus-plugin-content-docs/current/configure/app/output/css-module-local-ident-name.md +1 -1
  37. package/en/docusaurus-plugin-content-docs/current/configure/app/output/data-uri-limit.md +1 -1
  38. package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-css-extract.md +1 -1
  39. package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-css-module-extension.md +1 -1
  40. package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-filename-hash.md +1 -1
  41. package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-inline-runtime-chunk.md +1 -1
  42. package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-minimize.md +1 -1
  43. package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-source-map.md +1 -1
  44. package/en/docusaurus-plugin-content-docs/current/configure/app/output/disable-ts-checker.md +1 -1
  45. package/en/docusaurus-plugin-content-docs/current/configure/app/output/dist-path.md +1 -1
  46. package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-asset-fallback.md +1 -1
  47. package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-asset-manifest.md +1 -1
  48. package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-css-module-tsdeclaration.md +1 -1
  49. package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-inline-scripts.md +1 -1
  50. package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-inline-styles.md +1 -1
  51. package/en/docusaurus-plugin-content-docs/current/configure/app/output/enable-latest-decorators.md +1 -1
  52. package/en/docusaurus-plugin-content-docs/current/configure/app/output/externals.md +1 -1
  53. package/en/docusaurus-plugin-content-docs/current/configure/app/output/filename.md +1 -1
  54. package/en/docusaurus-plugin-content-docs/current/configure/app/output/legal-comments.md +1 -1
  55. package/en/docusaurus-plugin-content-docs/current/configure/app/output/override-browserslist.md +1 -1
  56. package/en/docusaurus-plugin-content-docs/current/configure/app/output/polyfill.md +1 -1
  57. package/en/docusaurus-plugin-content-docs/current/configure/app/output/svg-default-export.md +1 -1
  58. package/en/docusaurus-plugin-content-docs/current/configure/app/performance/build-cache.md +1 -1
  59. package/en/docusaurus-plugin-content-docs/current/configure/app/performance/bundle-analyze.md +1 -1
  60. package/en/docusaurus-plugin-content-docs/current/configure/app/performance/chunk-split.md +1 -1
  61. package/en/docusaurus-plugin-content-docs/current/configure/app/performance/print-file-size.md +1 -1
  62. package/en/docusaurus-plugin-content-docs/current/configure/app/performance/profile.md +1 -1
  63. package/en/docusaurus-plugin-content-docs/current/configure/app/performance/remove-console.md +1 -1
  64. package/en/docusaurus-plugin-content-docs/current/configure/app/performance/remove-moment-locale.md +1 -1
  65. package/en/docusaurus-plugin-content-docs/current/configure/app/plugins.md +1 -1
  66. package/en/docusaurus-plugin-content-docs/current/configure/app/security/sri.md +1 -1
  67. package/en/docusaurus-plugin-content-docs/current/configure/app/source/alias.md +1 -1
  68. package/en/docusaurus-plugin-content-docs/current/configure/app/source/compile-js-data-uri.md +1 -1
  69. package/en/docusaurus-plugin-content-docs/current/configure/app/source/define.md +1 -1
  70. package/en/docusaurus-plugin-content-docs/current/configure/app/source/exclude.md +1 -1
  71. package/en/docusaurus-plugin-content-docs/current/configure/app/source/global-vars.md +1 -1
  72. package/en/docusaurus-plugin-content-docs/current/configure/app/source/include.md +1 -1
  73. package/en/docusaurus-plugin-content-docs/current/configure/app/source/module-scopes.md +1 -1
  74. package/en/docusaurus-plugin-content-docs/current/configure/app/source/pre-entry.md +1 -1
  75. package/en/docusaurus-plugin-content-docs/current/configure/app/source/resolve-extension-prefix.md +1 -1
  76. package/en/docusaurus-plugin-content-docs/current/configure/app/source/resolve-main-fields.md +1 -1
  77. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/autoprefixer.md +1 -1
  78. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/babel.md +1 -1
  79. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/css-extract.md +1 -1
  80. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/css-loader.md +1 -1
  81. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/dev-server.md +1 -1
  82. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/html-plugin.md +1 -1
  83. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/inspector.md +1 -1
  84. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/less.md +1 -1
  85. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/minify-css.md +1 -1
  86. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/postcss.md +1 -1
  87. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/pug.md +1 -1
  88. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/sass.md +1 -1
  89. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/style-loader.md +1 -1
  90. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/styled-components.md +1 -1
  91. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/swc.md +42 -0
  92. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/terser.md +1 -1
  93. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/ts-checker.md +1 -1
  94. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/ts-loader.md +1 -1
  95. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/webpack-chain.md +1 -1
  96. package/en/docusaurus-plugin-content-docs/current/configure/app/tools/webpack.md +1 -1
  97. package/en/docusaurus-plugin-content-docs/current/guides/basic-features/builder.md +46 -0
  98. package/en/docusaurus-plugin-content-docs/current.json +18 -18
  99. package/package.json +3 -3
  100. package/scripts/config.ts +2 -2
  101. package/zh/apis/app/commands/new.md +0 -2
  102. package/zh/apis/app/runtime/app/_category_.json +1 -1
  103. package/zh/apis/app/runtime/bff/_category_.json +1 -1
  104. package/zh/apis/app/runtime/core/_category_.json +1 -1
  105. package/zh/apis/app/runtime/core/bootstrap.md +17 -3
  106. package/zh/apis/app/runtime/model/_category_.json +1 -1
  107. package/zh/apis/app/runtime/model/create-app.md +1 -1
  108. package/zh/apis/app/runtime/model/use-store.md +1 -23
  109. package/zh/apis/app/runtime/router/_category_.json +1 -1
  110. package/zh/apis/app/runtime/ssr/_category_.json +1 -1
  111. package/zh/apis/app/runtime/testing/_category_.json +1 -1
  112. package/zh/apis/app/runtime/utility/_category_.json +1 -1
  113. package/zh/apis/app/runtime/web-server/_category_.json +1 -1
  114. package/zh/components/reduck-migration.md +1 -0
  115. package/zh/configure/app/dev/asset-prefix.md +1 -1
  116. package/zh/configure/app/dev/hmr.md +1 -1
  117. package/zh/configure/app/dev/https.md +1 -1
  118. package/zh/configure/app/dev/port.md +1 -1
  119. package/zh/configure/app/dev/progress-bar.md +1 -1
  120. package/zh/configure/app/dev/start-url.md +1 -1
  121. package/zh/configure/app/experiments/_category_.json +4 -0
  122. package/zh/configure/app/experiments/lazy-compilation.md +1 -1
  123. package/zh/configure/app/html/_category_.json +4 -0
  124. package/zh/configure/app/html/app-icon.md +1 -1
  125. package/zh/configure/app/html/crossorigin.md +1 -1
  126. package/zh/configure/app/html/disable-html-folder.md +1 -1
  127. package/zh/configure/app/html/favicon-by-entries.md +1 -1
  128. package/zh/configure/app/html/favicon.md +1 -1
  129. package/zh/configure/app/html/inject-by-entries.md +1 -1
  130. package/zh/configure/app/html/inject.md +1 -1
  131. package/zh/configure/app/html/meta-by-entries.md +1 -1
  132. package/zh/configure/app/html/meta.md +1 -1
  133. package/zh/configure/app/html/mount-id.md +1 -1
  134. package/zh/configure/app/html/template-by-entries.md +1 -1
  135. package/zh/configure/app/html/template-parameters-by-entries.md +1 -1
  136. package/zh/configure/app/html/template-parameters.md +1 -1
  137. package/zh/configure/app/html/template.md +1 -1
  138. package/zh/configure/app/html/title-by-entries.md +1 -1
  139. package/zh/configure/app/html/title.md +1 -1
  140. package/zh/configure/app/output/asset-prefix.md +1 -1
  141. package/zh/configure/app/output/assets-retry.md +1 -1
  142. package/zh/configure/app/output/charset.md +1 -1
  143. package/zh/configure/app/output/clean-dist-path.md +1 -1
  144. package/zh/configure/app/output/convert-to-rem.md +1 -1
  145. package/zh/configure/app/output/copy.md +1 -1
  146. package/zh/configure/app/output/css-module-local-ident-name.md +1 -1
  147. package/zh/configure/app/output/data-uri-limit.md +1 -1
  148. package/zh/configure/app/output/disable-css-extract.md +1 -1
  149. package/zh/configure/app/output/disable-css-module-extension.md +1 -1
  150. package/zh/configure/app/output/disable-filename-hash.md +1 -1
  151. package/zh/configure/app/output/disable-inline-runtime-chunk.md +1 -1
  152. package/zh/configure/app/output/disable-minimize.md +1 -1
  153. package/zh/configure/app/output/disable-source-map.md +1 -1
  154. package/zh/configure/app/output/disable-ts-checker.md +1 -1
  155. package/zh/configure/app/output/dist-path.md +1 -1
  156. package/zh/configure/app/output/enable-asset-fallback.md +1 -1
  157. package/zh/configure/app/output/enable-asset-manifest.md +1 -1
  158. package/zh/configure/app/output/enable-css-module-tsdeclaration.md +1 -1
  159. package/zh/configure/app/output/enable-inline-scripts.md +1 -1
  160. package/zh/configure/app/output/enable-inline-styles.md +1 -1
  161. package/zh/configure/app/output/enable-latest-decorators.md +1 -1
  162. package/zh/configure/app/output/externals.md +1 -1
  163. package/zh/configure/app/output/filename.md +1 -1
  164. package/zh/configure/app/output/legal-comments.md +1 -1
  165. package/zh/configure/app/output/override-browserslist.md +1 -1
  166. package/zh/configure/app/output/polyfill.md +1 -1
  167. package/zh/configure/app/output/ssg.md +118 -114
  168. package/zh/configure/app/output/svg-default-export.md +1 -1
  169. package/zh/configure/app/performance/_category_.json +4 -0
  170. package/zh/configure/app/performance/build-cache.md +1 -1
  171. package/zh/configure/app/performance/bundle-analyze.md +1 -1
  172. package/zh/configure/app/performance/chunk-split.md +1 -1
  173. package/zh/configure/app/performance/print-file-size.md +1 -1
  174. package/zh/configure/app/performance/profile.md +1 -1
  175. package/zh/configure/app/performance/remove-console.md +1 -1
  176. package/zh/configure/app/performance/remove-moment-locale.md +1 -1
  177. package/zh/configure/app/plugins.md +1 -1
  178. package/zh/configure/app/runtime/state.md +13 -0
  179. package/zh/configure/app/security/_category_.json +4 -0
  180. package/zh/configure/app/security/sri.md +1 -1
  181. package/zh/configure/app/server/ssr.md +0 -2
  182. package/zh/configure/app/source/alias.md +1 -1
  183. package/zh/configure/app/source/compile-js-data-uri.md +1 -1
  184. package/zh/configure/app/source/define.md +1 -1
  185. package/zh/configure/app/source/exclude.md +1 -1
  186. package/zh/configure/app/source/global-vars.md +1 -1
  187. package/zh/configure/app/source/include.md +1 -1
  188. package/zh/configure/app/source/module-scopes.md +1 -1
  189. package/zh/configure/app/source/pre-entry.md +1 -1
  190. package/zh/configure/app/source/resolve-extension-prefix.md +1 -1
  191. package/zh/configure/app/source/resolve-main-fields.md +1 -1
  192. package/zh/configure/app/tools/autoprefixer.md +1 -1
  193. package/zh/configure/app/tools/babel.md +1 -1
  194. package/zh/configure/app/tools/css-extract.md +1 -1
  195. package/zh/configure/app/tools/css-loader.md +1 -1
  196. package/zh/configure/app/tools/dev-server.md +1 -1
  197. package/zh/configure/app/tools/html-plugin.md +1 -1
  198. package/zh/configure/app/tools/inspector.md +1 -1
  199. package/zh/configure/app/tools/less.md +1 -1
  200. package/zh/configure/app/tools/minify-css.md +1 -1
  201. package/zh/configure/app/tools/postcss.md +1 -1
  202. package/zh/configure/app/tools/pug.md +1 -1
  203. package/zh/configure/app/tools/sass.md +1 -1
  204. package/zh/configure/app/tools/style-loader.md +1 -1
  205. package/zh/configure/app/tools/styled-components.md +1 -1
  206. package/zh/configure/app/tools/swc.md +42 -0
  207. package/zh/configure/app/tools/terser.md +1 -1
  208. package/zh/configure/app/tools/ts-checker.md +1 -1
  209. package/zh/configure/app/tools/ts-loader.md +1 -1
  210. package/zh/configure/app/tools/webpack-chain.md +1 -1
  211. package/zh/configure/app/tools/webpack.md +1 -1
  212. package/zh/guides/advanced-features/custom-app.md +8 -2
  213. package/zh/guides/advanced-features/ssg.md +74 -63
  214. package/zh/guides/advanced-features/ssr.md +74 -11
  215. package/zh/guides/basic-features/builder.md +46 -0
  216. package/zh/guides/basic-features/css/_category_.json +1 -1
  217. package/zh/guides/basic-features/css/less-sass.md +1 -14
  218. package/zh/guides/basic-features/data-fetch.md +1 -1
  219. package/zh/guides/basic-features/env-vars.md +34 -0
  220. package/zh/guides/basic-features/routes.md +32 -35
  221. package/zh/guides/concept/entries.md +4 -4
  222. package/zh/guides/topic-detail/framework-plugin/extend.md +3 -4
  223. package/zh/{apis/app/runtime/plugin/hook-api.md → guides/topic-detail/framework-plugin/hook-list.md} +42 -135
  224. package/zh/{apis/app/runtime/plugin → guides/topic-detail/framework-plugin}/hook.md +2 -3
  225. package/zh/guides/topic-detail/framework-plugin/implement.md +21 -10
  226. package/zh/guides/topic-detail/framework-plugin/introduction.md +49 -0
  227. package/{en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin → zh/guides/topic-detail/framework-plugin}/plugin-api.md +3 -4
  228. package/zh/guides/topic-detail/framework-plugin/relationship.md +2 -3
  229. package/zh/guides/topic-detail/model/quick-start.md +4 -0
  230. package/zh/tutorials/first-app/c01-getting-started/1.2-minimal-mwa.md +2 -2
  231. package/zh/tutorials/first-app/c01-getting-started/1.4-enable-ssr.md +5 -2
  232. package/zh/tutorials/first-app/c02-generator-and-studio/2.2-boilerplates.md +4 -6
  233. package/zh/tutorials/first-app/c02-generator-and-studio/2.3-configuration.md +2 -4
  234. package/zh/tutorials/first-app/c03-ide/3.1-setting-up.md +1 -1
  235. package/zh/tutorials/first-app/c03-ide/3.2-hints-in-ide.md +44 -50
  236. package/zh/tutorials/first-app/c03-ide/3.3-autofix-in-ide.md +1 -1
  237. package/zh/tutorials/first-app/c03-ide/3.4-autofix-in-cli.md +4 -4
  238. package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.1-use-es6-plus.md +8 -21
  239. package/zh/tutorials/first-app/c04-es6-plus-and-ts/4.2-use-typescript.md +37 -13
  240. package/zh/tutorials/first-app/c05-component/5.1-use-ui-library.md +3 -13
  241. package/zh/tutorials/first-app/c05-component/5.2-use-standalone-component.md +1 -21
  242. package/zh/tutorials/first-app/c06-css-and-component/6.1-css-in-js.md +9 -9
  243. package/zh/tutorials/first-app/c06-css-and-component/6.2-utility-class.md +9 -14
  244. package/zh/tutorials/first-app/c06-css-and-component/6.3-postcss.md +7 -7
  245. package/zh/tutorials/first-app/c06-css-and-component/6.4-design-system.md +1 -1
  246. package/zh/tutorials/first-app/c06-css-and-component/6.5-storybook.md +2 -2
  247. package/zh/tutorials/first-app/c06-css-and-component/6.6-testing.md +8 -17
  248. package/zh/tutorials/first-app/c07-app-entry/7.1-intro.md +23 -18
  249. package/zh/tutorials/first-app/c07-app-entry/7.2-add-entry-in-cli.md +30 -30
  250. package/zh/tutorials/first-app/c07-app-entry/7.3-manage-entries-by-hand.md +4 -9
  251. package/zh/tutorials/first-app/c08-client-side-routing/8.1-code-based-routing.md +66 -63
  252. package/zh/tutorials/first-app/c09-bff/9.2-enable-bff.md +35 -33
  253. package/zh/tutorials/first-app/c09-bff/9.3-fetch-bff.md +28 -102
  254. package/zh/tutorials/first-app/c10-model/10.1-application-architecture.md +4 -6
  255. package/zh/tutorials/first-app/c10-model/10.2-add-model.md +3 -3
  256. package/zh/tutorials/first-app/c10-model/10.3-use-model.md +21 -20
  257. package/zh/tutorials/first-app/c10-model/10.4-testing.md +2 -2
  258. package/zh/tutorials/first-app/c11-container/11.1-use-model-with-app-state.md +34 -68
  259. package/zh/tutorials/first-app/c11-container/11.2-add-container.md +40 -37
  260. package/zh/tutorials/first-app/c11-container/11.3-use-loader.md +6 -4
  261. package/zh/tutorials/first-app/c11-container/11.4-testing.md +2 -2
  262. package/zh/tutorials/foundations/introduction.md +1 -1
  263. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/default-alias.md +0 -25
  264. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/_category_.json +0 -4
  265. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/abstract.md +0 -26
  266. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/hook-api.md +0 -896
  267. package/en/docusaurus-plugin-content-docs/current/apis/app/runtime/plugin/hook.md +0 -170
  268. package/zh/apis/app/runtime/default-alias.md +0 -23
  269. package/zh/apis/app/runtime/plugin/_category_.json +0 -4
  270. package/zh/apis/app/runtime/plugin/abstract.md +0 -26
  271. package/zh/apis/app/runtime/plugin/plugin-api.md +0 -117
  272. package/zh/guides/basic-features/image.md +0 -43
  273. package/zh/guides/topic-detail/compile-speed.md +0 -182
  274. package/zh/guides/topic-detail/framework-plugin/abstract.md +0 -27
  275. package/zh/guides/troubleshooting/compile.md +0 -379
  276. package/zh/tutorials/first-app/c08-client-side-routing/8.2-file-based-routing.md +0 -310
@@ -8,37 +8,42 @@ title: 入口的用途​​​
8
8
 
9
9
  ```md
10
10
  .
11
- ├── .vscode/
12
- ├── src/
13
- │ ├── components/
14
- │ │ ├── Avatar/
15
- │ │ │ ├── index.stories.tsx
16
- │ │ │ └── index.tsx
17
- │ │ └── Item/
18
- │ │ ├── index.test.tsx
19
- │ │ └── index.tsx
20
- │ ├── styles/
21
- │ │ └── utils.css
22
- │ ├── .eslintrc.json
23
- │ ├── App.css
24
- │ ├── App.tsx
25
- │ └── modern-app-env.d.ts
26
- ├── .editorconfig
11
+ ├── .eslintrc.js
27
12
  ├── .gitignore
13
+ ├── .husky
28
14
  ├── .npmrc
29
15
  ├── .nvmrc
16
+ ├── .prettierrc
17
+ ├── .vscode
30
18
  ├── README.md
19
+ ├── modern.config.ts
31
20
  ├── package.json
32
21
  ├── pnpm-lock.yaml
22
+ ├── src
23
+ │ ├── .eslintrc.js
24
+ │ ├── modern-app-env.d.ts
25
+ │ └── routes
26
+ │ ├── components
27
+ │ │ ├── Avatar
28
+ │ │ │ ├── index.stories.tsx
29
+ │ │ │ └── index.tsx
30
+ │ │ └── Item
31
+ │ │ ├── index.test.tsx
32
+ │ │ └── index.tsx
33
+ │ ├── index.css
34
+ │ ├── layout.tsx
35
+ │ ├── page.tsx
36
+ │ └── styles
37
+ │ └── utils.css
33
38
  └── tsconfig.json
34
39
  ```
35
40
 
36
41
  hello-modern 项目是一个应用工程,`src/` 目录里是应用工程源代码的主要部分,我们称之为【 Universal App 代码(大一统应用代码)】—— 既可以在客户端运行又可以在服务器端运行,有多种运行模式和部署模式,既能实现多页(MPA)也能实现单页(SPA)。
37
42
 
38
- 我们把 `src/App.tsx` 称作【 应用入口(App Entry)】,一个应用工程可以有一到多个应用入口。
43
+ 我们把 `src/routes` 称作【 应用入口(App Entry)】,一个应用工程可以有一到多个应用入口。
39
44
 
40
45
  :::info 注
41
- 应用入口不止 `App.[jt]sx` 一种,之后章节中会再次介绍。
46
+ 应用入口不止 `src/routes` 一种,之后章节中会再次介绍。
42
47
  :::
43
48
 
44
49
  :::info 注
@@ -23,38 +23,46 @@ Modern.js 支持自动创建新入口,前面的章节中提到过,`pnpm run
23
23
 
24
24
  ```md
25
25
  .
26
- ├── .vscode/
27
- ├── src/
28
- │ ├── hello-modern/
29
- │ │ ├── components/
30
- │ │ │ ├── Avatar/
31
- │ │ │ │ ├── index.stories.tsx
32
- │ │ │ │ └── index.tsx
33
- │ │ │ └── Item/
34
- │ │ │ ├── index.test.tsx
35
- │ │ │ └── index.tsx
36
- │ │ ├── styles/
37
- │ │ │ └── utils.css
38
- │ │ ├── App.css
39
- │ │ └── App.tsx
40
- │ ├── landing-page/
41
- │ │ ├── App.css
42
- │ │ └── App.tsx
43
- │ ├── .eslintrc.json
44
- │ └── modern-app-env.d.ts
45
- ├── .editorconfig
26
+ ├── .eslintrc.js
46
27
  ├── .gitignore
28
+ ├── .husky
47
29
  ├── .npmrc
48
30
  ├── .nvmrc
31
+ ├── .prettierrc
32
+ ├── .vscode
49
33
  ├── README.md
34
+ ├── modern.config.ts
50
35
  ├── package.json
51
36
  ├── pnpm-lock.yaml
37
+ ├── src
38
+ │ ├── .eslintrc.js
39
+ │ ├── hello-modern
40
+ │ │ ├── index.test.ts
41
+ │ │ └── routes
42
+ │ │ ├── components
43
+ │ │ │ ├── Avatar
44
+ │ │ │ │ ├── index.stories.tsx
45
+ │ │ │ │ └── index.tsx
46
+ │ │ │ └── Item
47
+ │ │ │ ├── index.test.tsx
48
+ │ │ │ └── index.tsx
49
+ │ │ ├── index.css
50
+ │ │ ├── layout.tsx
51
+ │ │ ├── page.tsx
52
+ │ │ └── styles
53
+ │ │ └── utils.css
54
+ │ ├── landing-page
55
+ │ │ └── routes
56
+ │ │ ├── index.css
57
+ │ │ ├── layout.tsx
58
+ │ │ └── page.tsx
59
+ │ └── modern-app-env.d.ts
52
60
  └── tsconfig.json
53
61
  ```
54
62
 
55
63
  可以看到联系人列表应用的文件,都被自动重构到 `src/hello-modern/` 里。
56
64
 
57
- 同时新建了一个 `src/landing-page/`,里面同样有 `App.tsx`(`pnpm run new` 命令只做了这些事,所以你也可以很容易的手动创建新入口或修改入口)
65
+ 同时新建了一个 `src/landing-page/`,里面同样有 `routes/*`(`pnpm run new` 命令只做了这些事,所以你也可以很容易的手动创建新入口或修改入口)
58
66
 
59
67
  执行 `pnpm run dev`,显示:
60
68
 
@@ -74,15 +82,7 @@ Modern.js 框架的设计原则之一是【[约定优于配置(Convention over
74
82
 
75
83
  其他入口的 URL,是在根路径后追加入口名,比如 `http://localhost:8080/landing-page`。
76
84
 
77
- :::info
78
- `src/` 下如果有 `App.[jt]sx`,就认为这个应用工程是单入口的,`src/` 下的其他文件和目录,都会被视为入口内部的文件。
79
-
80
- `src/` 下如果没有 `App.[jt]sx`,那么 `src/` **下一级**目录里,如果有 `App.[jt]sx`,这个目录就会被视为一个应用入口。
81
-
82
- `App.jsx` 被看作约定中**标识**,也有其他形式的**标识**,之后的章节中会继续介绍。
83
- :::
84
-
85
- 接下来,我们把 `src/hello-modern/App.tsx` 重命名为 `src/contacts/App.tsx`:
85
+ 接下来,我们把 `src/hello-modern/` 重命名为 `src/contacts/`:
86
86
 
87
87
  ```bash
88
88
  mv src/hello-modern src/contacts
@@ -8,9 +8,8 @@ title: 管理应用入口​​​
8
8
 
9
9
  我们可以在 `package.json` 中的 `modernConfig`,或是在符合[业界主流惯例](https://github.com/davidtheclark/cosmiconfig)的 Modern.js 配置文件里,自己写代码来控制项目的配置。
10
10
 
11
- 之前的章节中,我们都是直接修改 `package.json` 中的 `modernConfig` 字段来实现修改配置。
12
11
 
13
- 现在,让我们在项目目录下,新建一个 `modern.config.ts`(若已新建可忽略),并在里面添加内容:
12
+ 现在,让我们在项目目录 `modern.config.ts` 里面添加内容:
14
13
 
15
14
  ```typescript title="modern.config.ts"
16
15
  export default defineConfig({
@@ -29,19 +28,15 @@ export default defineConfig({
29
28
 
30
29
  如果注释掉 `ssrByEntries` 和它的值,landing-page 的 SSR 功能就恢复开启了。
31
30
 
32
- :::info 注
33
- 当相同配置字段出现于两个文件中时, `package.json` 中 `modernConfig` 字段里的配置会优先于 `modern.config.js` 中的配置。
34
- :::
35
-
36
31
  当需要配置包含复杂逻辑的选项时,比如,开发者想在项目中使用 `*.myext` 文件,这是一种非主流的文件类型,Modern.js 没有默认集成对它的支持。
37
32
 
38
- 所以,开发者可以在 `modern.config.js` 里增加对它的支持(通过webpack配置),如下所示:
33
+ 所以,开发者可以在 `modern.config.ts` 里增加对它的支持(通过webpack配置),如下所示:
39
34
 
40
35
  :::info 注
41
36
  更多 webpack 配置相关可以查看 [Webpack 配置文档](/docs/configure/app/tools/webpack)。
42
37
  :::
43
38
 
44
- ```js
39
+ ```ts
45
40
  // 注:以下为伪代码,loader等名字皆为虚构,仅做演示使用
46
41
  export default defineConfig({
47
42
  tools: {
@@ -59,7 +54,7 @@ export default defineConfig({
59
54
 
60
55
  这个需求要修改 webpack 配置,用 Modern.js 配置的`tools.webpack`选项来实现显然是更方便的。
61
56
 
62
- 还有一些时候,需要一些更复杂的逻辑来做设置,比如需要 JS 变量、表达式、导入模块等,这种时候也适合用 `modern.config.js` 来手动配置,比如:
57
+ 还有一些时候,需要一些更复杂的逻辑来做设置,比如需要 JS 变量、表达式、导入模块等,这种时候也适合用 `modern.config.ts` 来手动配置,比如:
63
58
 
64
59
  ```js
65
60
  export default defineConfig({
@@ -1,5 +1,5 @@
1
1
  ---
2
- title: 使用自控式路由​​​​
2
+ title: 使用约定式路由​​​​
3
3
  ---
4
4
 
5
5
  上一章节中,我们学习了如何创建应用入口。
@@ -21,55 +21,53 @@ export default defineConfig({
21
21
 
22
22
  之前我们已经为联系人列表增加了 Archive 按钮,接下来我们添加一个客户端路由 `/archives`,访问这个路由时,只显示已存档的联系人,而原有的 `/` 继续显示所有联系人。
23
23
 
24
- 打开 `src/contacts/App.tsx`,在原有的 `mockData` 下方新增 `mockArchivedData`:
24
+ 新建 `src/contacts/routes/archives/page.tsx`, 添加如下代码:
25
25
 
26
- ```js
27
- const mockData = getAvatar([
28
- { name: 'Thomas', email: 'w.kccip@bllmfbgv.dm' },
29
- { name: 'Chow', email: 'f.lfqljnlk@ywoefljhc.af' },
30
- { name: 'Bradley', email: 'd.wfovsqyo@gpkcjwjgb.fr' },
31
- { name: 'Davis', email: '"t.kqkoj@utlkwnpwk.nu' },
32
- ]);
33
-
34
- const mockArchivedData = getAvatar([
35
- { name: 'Thomas', email: 'w.kccip@bllmfbgv.dm' },
36
- { name: 'Chow', email: 'f.lfqljnlk@ywoefljhc.af' },
37
- ]);
26
+ ```ts
27
+ import { List } from 'antd';
28
+ import { Helmet } from '@modern-js/runtime/head';
29
+ import Item from '../components/Item';
30
+
31
+ const getAvatar = (users: Array<{ name: string; email: string }>) =>
32
+ users.map(user => ({
33
+ ...user,
34
+ avatar: `https://avatars.dicebear.com/v2/identicon/${user.name}.svg`,
35
+ }));
36
+
37
+ const getMockArchivedData = () =>
38
+ getAvatar([
39
+ { name: 'Thomas', email: 'w.kccip@bllmfbgv.dm' },
40
+ { name: 'Chow', email: 'f.lfqljnlk@ywoefljhc.af' },
41
+ ]);
42
+ function Index() {
43
+ return (
44
+ <div className="container lg mx-auto">
45
+ <Helmet>
46
+ <title>Archives</title>
47
+ </Helmet>
48
+ <List
49
+ dataSource={getMockArchivedData()}
50
+ renderItem={info => <Item key={info.name} info={info} />}
51
+ />
52
+ </div>
53
+ );
54
+ }
55
+
56
+ export default Index;
38
57
  ```
39
58
 
40
- 在文件顶部引入 [React Router](https://reactrouter.com/) 的 `Route`、`Switch` 和 [React Helmet](https://github.com/nfl/react-helmet) 的 `Helmet` 组件:
59
+ 这里使用了 [React Helmet](https://github.com/nfl/react-helmet) 的 `Helmet` 组件,在 `src/contacts/routes/page.tsx` 中也添加 Helmet 组件:
41
60
 
42
- ```js
43
- import { Route, Switch } from '@modern-js/runtime/router';
61
+ ```tsx
44
62
  import { Helmet } from '@modern-js/runtime/head';
45
- ```
46
63
 
47
- 在 `App` 组件中使用 `Route` 写两个路由,分别用不同的 mock 数据渲染列表:
48
-
49
- ```js
50
64
  function App() {
51
65
  return (
52
66
  <div className="container lg mx-auto">
53
- <Switch>
54
- <Route path="/" exact={true}>
55
- <Helmet>
56
- <title>All</title>
57
- </Helmet>
58
- <List
59
- dataSource={mockData}
60
- renderItem={info => <Item key={info.name} info={info} />}
61
- />
62
- </Route>
63
- <Route path="/archives" exact={true}>
64
- <Helmet>
65
- <title>Archives</title>
66
- </Helmet>
67
- <List
68
- dataSource={mockArchivedData}
69
- renderItem={info => <Item key={info.name} info={info} />}
70
- />
71
- </Route>
72
- </Switch>
67
+ <Helmet>
68
+ <title>All</title>
69
+ </Helmet>
70
+ ...
73
71
  </div>
74
72
  );
75
73
  }
@@ -77,12 +75,8 @@ function App() {
77
75
 
78
76
  :::info 注
79
77
  Modern.js 默认集成了 react-helmet,无需安装依赖,可以直接使用,也可以结合 SSR 使用,满足 SEO 需求。
80
-
81
- Modern.js 也默认集成了 react-router,无需安装依赖和自己配置 `BrowserRouter` 等样板代码,可以直接用 Route、Switch 等组件实现路由逻辑。
82
78
  :::
83
79
 
84
- React Router v4+ 有两种用法,一种是 `component-based` 的,一种是基于全局配置的。这两种都由开发者自己用代码来控制客户端路由逻辑,所以我们把这种模式称作【**自控式路由**】。
85
-
86
80
  执行 `pnpm run dev`,访问 `http://localhost:8080/contacts`,可以看到完整的联系人,页面的标题是 All:
87
81
 
88
82
  ![display](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/docs/08/display.png)
@@ -95,7 +89,7 @@ React Router v4+ 有两种用法,一种是 `component-based` 的,一种是
95
89
 
96
90
  **接下来我们增加一个简单的导航栏,让用户能在两个列表之间切换**。
97
91
 
98
- 打开 src/contacts/App.tsx,在顶部导入 Radio 组件:
92
+ 打开 `src/contacts/layout.tsx`,在顶部导入 Radio 组件:
99
93
 
100
94
  ```tsx
101
95
  import { List, Radio } from 'antd';
@@ -103,39 +97,48 @@ import { List, Radio } from 'antd';
103
97
 
104
98
  然后将 UI 最顶部进行修改,增加一组单选框
105
99
 
106
- ```tsx {3-8}
107
- return (
108
- <div className="container lg mx-auto">
109
- <div className="h-16 p-2 flex items-center justify-center">
110
- <Radio.Group onChange={handleSetList} value={currentList}>
111
- <Radio value="/">All</Radio>
112
- <Radio value="/archives">Archives</Radio>
113
- </Radio.Group>
100
+ ```tsx {5-8}
101
+ export default function Layout() {
102
+ return (
103
+ <div>
104
+ <div className="h-16 p-2 flex items-center justify-center">
105
+ <Radio.Group onChange={handleSetList} value={currentList}>
106
+ <Radio value="/">All</Radio>
107
+ <Radio value="/archives">Archives</Radio>
108
+ </Radio.Group>
109
+ </div>
110
+ <Outlet />
114
111
  </div>
115
- <Switch>
112
+ );
113
+ }
114
+
116
115
  ```
117
116
 
118
117
  然后我们来实现 `currentList` 和 `handleSetList`。
119
118
 
120
- 引入两个 React Hook:`useState` 和 `useHistory`,以及 Ant Design 的事件类型定义:
119
+ 引入三个 React Hook:`useState` 和 `useNavigate` 和 `useParams`,以及 Ant Design 的事件类型定义:
121
120
 
122
121
  ```js
123
122
  import { useState } from 'react';
124
- import { List, Radio, RadioChangeEvent } from 'antd';
125
- import { Route, Switch, useHistory } from '@modern-js/runtime/router';
123
+ import { Radio, RadioChangeEvent } from 'antd';
124
+ import { Outlet, useNavigate, useParams } from '@modern-js/runtime/router';
126
125
  ```
127
126
 
128
- 最后在 App 组件里增加局部状态和相关逻辑:
127
+ 最后在 Layout 组件里增加局部状态和相关逻辑:
129
128
 
130
129
  ```js {2-8}
131
- function App() {
132
- const history = useHistory();
133
- const [currentList, setList] = useState(history.location.pathname || '/');
130
+ export default function Layout() {
131
+ const navigate = useNavigate();
132
+ const params = useParams();
133
+ const [currentList, setList] = useState(params.pathname || '/');
134
134
  const handleSetList = (e: RadioChangeEvent) => {
135
135
  const { value } = e.target;
136
136
  setList(value);
137
- history.push(value);
137
+ navigate(value);
138
138
  };
139
+ return (
140
+ ...
141
+ }
139
142
  ```
140
143
 
141
144
  到这里就已经完成了页面导航栏实现,执行 `pnpm run dev` 查看效果:
@@ -18,8 +18,6 @@ title: 启用 BFF
18
18
  # 请选择运行时框
19
19
  ❯ Express
20
20
  Koa
21
- Egg
22
- Nest
23
21
  ```
24
22
 
25
23
  :::info 注
@@ -30,43 +28,47 @@ title: 启用 BFF
30
28
 
31
29
  ```md
32
30
  .
33
- ├── .vscode/
34
- ├── api/
35
- │ ├── info/
36
- │ │ └── [type].ts
37
- │ ├── .eslintrc.json
38
- │ ├── _app.ts
39
- │ └── index.ts
40
- ├── src/
41
- │ ├── contacts/
42
- │ │ ├── components/
43
- │ │ │ ├── Avatar/
44
- │ │ │ │ ├── index.stories.tsx
45
- │ │ │ │ └── index.tsx
46
- │ │ │ └── Item/
47
- │ │ │ ├── index.test.tsx
48
- │ │ │ └── index.tsx
49
- │ │ ├── styles/
50
- │ │ │ └── utils.css
51
- │ │ ├── App.css
52
- │ │ └── App.tsx
53
- │ ├── landing-page/
54
- │ │ └── pages/
55
- │ │ ├── comments/
56
- │ │ │ └── [commentTitle]/
57
- │ │ │ └── index.tsx
58
- │ │ ├── _app.tsx
59
- │ │ ├── docs.tsx
60
- │ │ └── index.tsx
61
- │ ├── .eslintrc.json
62
- │ └── modern-app-env.d.ts
63
- ├── .editorconfig
31
+ ├── .eslintrc.js
64
32
  ├── .gitignore
33
+ ├── .husky
65
34
  ├── .npmrc
66
35
  ├── .nvmrc
36
+ ├── .prettierrc
37
+ ├── .vscode
67
38
  ├── README.md
39
+ ├── api
40
+ │ ├── _app.ts
41
+ │ ├── index.ts
42
+ │ └── info
43
+ │ └── [type].ts
44
+ ├── modern.config.ts
68
45
  ├── package.json
69
46
  ├── pnpm-lock.yaml
47
+ ├── src
48
+ │ ├── .eslintrc.js
49
+ │ ├── contacts
50
+ │ │ ├── index.test.ts
51
+ │ │ └── routes
52
+ │ │ ├── archives
53
+ │ │ │ └── page.tsx
54
+ │ │ ├── components
55
+ │ │ │ ├── Avatar
56
+ │ │ │ │ ├── index.stories.tsx
57
+ │ │ │ │ └── index.tsx
58
+ │ │ │ └── Item
59
+ │ │ │ ├── index.test.tsx
60
+ │ │ │ └── index.tsx
61
+ │ │ ├── index.css
62
+ │ │ ├── layout.tsx
63
+ │ │ ├── page.tsx
64
+ │ │ └── styles
65
+ │ │ └── utils.css
66
+ │ ├── landing-page
67
+ │ │ └── routes
68
+ │ │ ├── index.css
69
+ │ │ ├── layout.tsx
70
+ │ │ └── page.tsx
71
+ │ └── modern-app-env.d.ts
70
72
  └── tsconfig.json
71
73
  ```
72
74
 
@@ -35,7 +35,7 @@ mv api/index.ts api/contacts.ts
35
35
  我们使用 [faker](https://github.com/Marak/Faker.js) 来 mock 需要的数据,首先安装依赖:
36
36
 
37
37
  ```bash
38
- pnpm add faker
38
+ pnpm add faker@5.5.3
39
39
  ```
40
40
 
41
41
  将 `api/contacts.ts` 内容改为:
@@ -65,69 +65,22 @@ export const get = async () => {
65
65
 
66
66
  ![browser-result](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/docs/08/api-result.png)
67
67
 
68
- 接下来我们把 `src/contacts/App.tsx` 里硬编码的 `mockData` 改成从 BFF 加载。
68
+ 接下来我们把 `src/routes/contacts/page.tsx` 里硬编码的 `getMockData` 改成从 BFF 加载:
69
69
 
70
- 我们将业务逻辑迁移到组件中,`App.tsx` 只保留简单的路由部分,执行:
71
-
72
- <Tabs>
73
- <TabItem value="macOS" label="macOS" default>
74
-
75
- ```bash
76
- mkdir -p src/contacts/components/AllContacts/
77
- mkdir -p src/contacts/components/ArchivedContacts/
78
- touch src/contacts/components/AllContacts/index.tsx
79
- touch src/contacts/components/ArchivedContacts/index.tsx
80
- ```
81
-
82
- </TabItem>
83
- <TabItem value="Windows" label="Windows">
84
-
85
- ```powershell
86
- mkdir -p src/contacts/components/AllContacts/
87
- mkdir -p src/contacts/components/ArchivedContacts/
88
- ni src/contacts/components/AllContacts/index.tsx
89
- ni src/contacts/components/ArchivedContacts/index.tsx
90
- ```
91
-
92
- </TabItem>
93
- </Tabs>
94
-
95
- `ArchivedContacts/index.tsx` 的内容:
96
-
97
- ```js
70
+ ```tsx
71
+ import { Helmet } from '@modern-js/runtime/head';
98
72
  import { List } from 'antd';
99
- import Item from '../Item';
100
-
101
- const getAvatar = (users: Array<{ name: string; email: string }>) =>
102
- users.map(user => ({
103
- ...user,
104
- avatar: `https://avatars.dicebear.com/v2/identicon/${user.name}.svg`,
105
- }));
106
-
107
- const mockArchivedData = getAvatar([
108
- { name: 'Thomas', email: 'w.kccip@bllmfbgv.dm' },
109
- { name: 'Chow', email: 'f.lfqljnlk@ywoefljhc.af' },
110
- ]);
111
-
112
- const ArchivedContacts = () => (
113
- <List
114
- dataSource={mockArchivedData}
115
- renderItem={info => <Item key={info.name} info={info} />}
116
- />
117
- );
118
-
119
- export default ArchivedContacts;
120
- ```
121
-
122
- `AllContacts/index.tsx` 的内容:
73
+ import 'ladda/dist/ladda.min.css';
74
+ import 'tailwindcss/base.css';
75
+ import 'tailwindcss/components.css';
76
+ import 'tailwindcss/utilities.css';
77
+ import './styles/utils.css';
123
78
 
124
- ```tsx
125
79
  import { useState, useEffect } from 'react';
126
- import { List } from 'antd';
127
80
  import { get as contacts } from '@api/contacts';
128
- import Item from '../Item';
81
+ import Item from './components/Item';
129
82
 
130
- const AllContacts = () => {
83
+ function Index() {
131
84
  const [list, setList] = useState(
132
85
  [] as Array<{ name: string; email: string; avatar: string }>,
133
86
  );
@@ -141,20 +94,25 @@ const AllContacts = () => {
141
94
  }
142
95
  });
143
96
  return (
144
- (list.length && (
145
- <List
146
- dataSource={list}
147
- renderItem={info => <Item key={info.name} info={info} />}
148
- />
149
- )) || (
150
- <div className="p-4 items-center border-gray-200 border-b border-t custom-text-gray">
151
- Pending...
152
- </div>
153
- )
97
+ <div className="container lg mx-auto">
98
+ <Helmet>
99
+ <title>All</title>
100
+ </Helmet>
101
+ {(list.length && (
102
+ <List
103
+ dataSource={list}
104
+ renderItem={info => <Item key={info.name} info={info} />}
105
+ />
106
+ )) || (
107
+ <div className="p-4 items-center border-gray-200 border-b border-t custom-text-gray">
108
+ Pending...
109
+ </div>
110
+ )}
111
+ </div>
154
112
  );
155
- };
113
+ }
156
114
 
157
- export default AllContacts;
115
+ export default Index;
158
116
  ```
159
117
 
160
118
  在 Modern.js 中,可以通过调用函数(前后端一体化)的方式,直接调用 BFF 接口,调用时无需关心域名、路径等。
@@ -163,38 +121,6 @@ export default AllContacts;
163
121
  在使用 `pnpm run new` 创建 BFF 时,Modern.js 已经默认在 `tsconig.json` 中注入了别名。这也是之前提到的,生成器在项目创建之后并不会被抛弃,仍旧可以在开发过程中不断为项目提供新的内容。
164
122
  :::
165
123
 
166
- 接下来修改 `src/contacts/App.tsx`,把 `List` 组件的调用代码替换成上面的 `AllContacts` 和 `ArchivedContacts`:
167
-
168
- ```tsx
169
- <Route path="/" exact={true}>
170
- <Helmet>
171
- <title>All</title>
172
- </Helmet>
173
- <AllContacts />
174
- </Route>
175
- <Route path="/archives" exact={true}>
176
- <Helmet>
177
- <title>Archives</title>
178
- </Helmet>
179
- <ArchivedContacts />
180
- </Route>
181
- ```
182
-
183
- 删除 `App.tsx` 里的 mock 数据和 `List` 组件,把 `Item` 组件替换成 `ContactList`:
184
-
185
- ```tsx
186
- import { useState } from 'react';
187
- import { Radio, RadioChangeEvent } from 'antd';
188
- import { Route, Switch, useHistory } from '@modern-js/runtime/router';
189
- import { Helmet } from '@modern-js/runtime/head';
190
- import 'tailwindcss/base.css';
191
- import 'tailwindcss/components.css';
192
- import 'tailwindcss/utilities.css';
193
- import './styles/utils.css';
194
- import AllContacts from './components/AllContacts';
195
- import ArchivedContacts from './components/ArchivedContacts';
196
- ```
197
-
198
124
  执行 `pnpm run dev`,再打开页面`http://localhost:8000/contacts`,可以看到页面加载后,会先初始化联系人数据(显示 pending),之后每次切换到 All 列表,也会重新请求联系人数据:
199
125
 
200
126
  ![browser-result](https://lf3-static.bytednsdoc.com/obj/eden-cn/aphqeh7uhohpquloj/modern-js/docs/08/browser-result.png)
@@ -2,11 +2,11 @@
2
2
  title: 应用架构
3
3
  ---
4
4
 
5
- 上一章节中,我们把硬编码的 `mockData` 改成从 BFF 加载,从 `App.tsx` 里拆分出了 `components/AllContacts.tsx` 和 `components/ArchivedContacts.tsx`,在 `AllContacts` 组件里用 BFF 函数,获取到联系人数据之后,保存在 `AllContacts` 的组件内部状态里,而 `ArchivedContacts` 组件暂时继续使用 mock 数据。
5
+ 上一章节中,我们把硬编码的 `mockData` 改成从 BFF 加载,在 `pages.tsx` 组件里用 BFF 函数,获取到联系人数据之后,保存在 `Index` 的组件内部状态里,而 `archives/index` 组件暂时继续使用 mock 数据。
6
6
 
7
- 本章节中,为了进一步实现项目功能,我们需要让 `AllContacts` 和 `ArchivedContacts` 都从 BFF 获取数据,还要实现【 Archive 】按钮,点击按钮能把联系人归档。
7
+ 本章节中,为了进一步实现项目功能,我们需要让两个组件都从 BFF 获取数据,还要实现【 Archive 】按钮,点击按钮能把联系人归档。
8
8
 
9
- 业务逻辑变复杂之后,相关代码不可避免会变多,如果都写在 AllContacts 组件或其他组件里,都会让这个组件的可读性和可维护性变差,让做不同事情的代码混在一起。
9
+ 业务逻辑变复杂之后,相关代码不可避免会变多,如果都写在组件里,都会让这个组件的可读性和可维护性变差,让做不同事情的代码混在一起。
10
10
 
11
11
  原本可以跟 UI 完全解耦的业务逻辑(比如网络请求、纯数据的操作、状态的管理等)跟 UI 逻辑(比如联系人列表如何展现)混在一起,当需要修改 UI 的时候,不得不跟 UI 无关的业务逻辑代码打交道,反过来也一样,不符合【 [单一职责原则(SRP)](https://zh.wikipedia.org/wiki/%E5%8D%95%E4%B8%80%E5%8A%9F%E8%83%BD%E5%8E%9F%E5%88%99)】,也做不到【 [关注点分离(SoC)](https://zh.wikipedia.org/wiki/%E5%85%B3%E6%B3%A8%E7%82%B9%E5%88%86%E7%A6%BB)】。
12
12
 
@@ -16,8 +16,6 @@ title: 应用架构
16
16
 
17
17
  Modern.js 提供开箱即用的**应用架构**,支持几种扮演不同**角色(role)**、属于不同**分层(layer)**的代码模块类型,可以把业务逻辑解耦到不同类型的代码模块里,做到高[内聚](https://zh.wikipedia.org/wiki/%E5%85%A7%E8%81%9A%E6%80%A7_(%E8%A8%88%E7%AE%97%E6%A9%9F%E7%A7%91%E5%AD%B8))低[耦合](https://zh.wikipedia.org/wiki/%E8%80%A6%E5%90%88%E6%80%A7_(%E8%A8%88%E7%AE%97%E6%A9%9F%E7%A7%91%E5%AD%B8))。
18
18
 
19
- 之前介绍的 `App.tsx` 和 `pages/` 都是其中一种代码模块,通过在最顶层对客户端路由的管理,把其他代码模块最终组织到一起,形成应用。
20
-
21
19
  当前项目里 `components/` 目录中的 React 组件,是一种可以称作【 视图组件 】的代码模块,负责 UI、交互上的界面展现。
22
20
 
23
- 本章节我们来把 `AllContacts` 组件中可以跟 UI 解耦的业务逻辑,移到一种叫【 Model(业务模型)】的代码模块里。
21
+ 本章节我们来把 `page.tsx` 中的 Index 组件中可以跟 UI 解耦的业务逻辑,移到一种叫【 Model(业务模型)】的代码模块里。
@@ -121,11 +121,11 @@ const actions = {
121
121
  为了做到高内聚低耦合,一个 Model 的 state、action、side effect 不应该分散在不同文件里。接下来我们把上面的代码连起来,放在同一个 Model 文件里,执行以下命令:
122
122
 
123
123
  ```bash
124
- mkdir -p src/contacts/models/
125
- touch src/contacts/models/contacts.ts
124
+ mkdir -p src/contacts/routes/models/
125
+ touch src/contacts/routes/models/contacts.ts
126
126
  ```
127
127
 
128
- `src/contacts/models/contacts.ts` 的内容:
128
+ `src/contacts/routes/models/contacts.ts` 的内容:
129
129
 
130
130
  ```tsx
131
131
  import { model } from '@modern-js/runtime/model';