@modern-js/main-doc 2.59.0 → 2.60.1-alpha.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (414) hide show
  1. package/docs/en/_meta.json +10 -5
  2. package/docs/en/apis/app/hooks/api/lambda.mdx +4 -48
  3. package/docs/en/apis/app/hooks/api/middleware.mdx +11 -0
  4. package/docs/en/community/blog/v2-release-note.mdx +1 -1
  5. package/docs/en/community/contributing-guide.mdx +0 -1
  6. package/docs/en/components/builder.mdx +3 -0
  7. package/docs/en/components/bundler.mdx +3 -0
  8. package/docs/en/components/enable-bff.mdx +19 -2
  9. package/docs/en/components/enableSwc.mdx +17 -0
  10. package/docs/en/components/esbuild.mdx +3 -0
  11. package/docs/en/components/extend-bff-function.mdx +5 -0
  12. package/docs/en/components/micro-frontend.mdx +6 -0
  13. package/docs/en/components/module-federation.mdx +7 -0
  14. package/docs/en/components/nodeVersion.mdx +26 -0
  15. package/docs/en/components/other-plugins.mdx +0 -0
  16. package/docs/en/components/output-asset-prefix-extend.mdx +0 -0
  17. package/docs/en/components/output-polyfill-extend.mdx +0 -0
  18. package/docs/en/components/prerequisites.mdx +1 -1
  19. package/docs/en/components/rsbuild-config-tooltip.mdx +5 -0
  20. package/docs/en/components/rsbuild.mdx +3 -0
  21. package/docs/en/components/rspack.mdx +3 -0
  22. package/docs/en/components/rspackPrecautions.mdx +6 -0
  23. package/docs/en/components/rspackTip.mdx +7 -0
  24. package/docs/en/components/swc.mdx +3 -0
  25. package/docs/en/configure/app/auto-load-plugin.mdx +4 -0
  26. package/docs/en/configure/app/dev/asset-prefix.mdx +12 -2
  27. package/docs/en/configure/app/dev/before-start-url.mdx +14 -2
  28. package/docs/en/configure/app/dev/client.mdx +20 -16
  29. package/docs/en/configure/app/dev/hmr.mdx +8 -2
  30. package/docs/en/configure/app/dev/host.mdx +15 -2
  31. package/docs/en/configure/app/dev/https.mdx +71 -2
  32. package/docs/en/configure/app/dev/live-reload.mdx +3 -15
  33. package/docs/en/configure/app/dev/port.mdx +18 -2
  34. package/docs/en/configure/app/dev/progress-bar.mdx +17 -2
  35. package/docs/en/configure/app/dev/setup-middlewares.mdx +25 -39
  36. package/docs/en/configure/app/dev/start-url.mdx +46 -2
  37. package/docs/en/configure/app/dev/watch-files.mdx +5 -39
  38. package/docs/en/configure/app/dev/write-to-disk.mdx +4 -27
  39. package/docs/en/configure/app/experiments/lazy-compilation.mdx +84 -2
  40. package/docs/en/configure/app/experiments/source-build.mdx +28 -3
  41. package/docs/en/configure/app/html/app-icon.mdx +48 -2
  42. package/docs/en/configure/app/html/crossorigin.mdx +8 -2
  43. package/docs/en/configure/app/html/disable-html-folder.mdx +35 -2
  44. package/docs/en/configure/app/html/favicon-by-entries.mdx +29 -2
  45. package/docs/en/configure/app/html/favicon.mdx +14 -2
  46. package/docs/en/configure/app/html/inject-by-entries.mdx +29 -2
  47. package/docs/en/configure/app/html/inject.mdx +8 -2
  48. package/docs/en/configure/app/html/meta-by-entries.mdx +41 -2
  49. package/docs/en/configure/app/html/meta.mdx +22 -2
  50. package/docs/en/configure/app/html/mount-id.mdx +8 -2
  51. package/docs/en/configure/app/html/script-loading.mdx +8 -2
  52. package/docs/en/configure/app/html/tags-by-entries.mdx +37 -2
  53. package/docs/en/configure/app/html/tags.mdx +13 -2
  54. package/docs/en/configure/app/html/template-by-entries.mdx +26 -2
  55. package/docs/en/configure/app/html/template-parameters-by-entries.mdx +28 -2
  56. package/docs/en/configure/app/html/template-parameters.mdx +31 -2
  57. package/docs/en/configure/app/html/template.mdx +8 -2
  58. package/docs/en/configure/app/html/title-by-entries.mdx +30 -2
  59. package/docs/en/configure/app/html/title.mdx +16 -2
  60. package/docs/en/configure/app/output/asset-prefix.mdx +12 -2
  61. package/docs/en/configure/app/output/assets-retry.mdx +72 -2
  62. package/docs/en/configure/app/output/charset.mdx +8 -2
  63. package/docs/en/configure/app/output/clean-dist-path.mdx +13 -2
  64. package/docs/en/configure/app/output/convert-to-rem.mdx +76 -2
  65. package/docs/en/configure/app/output/copy.mdx +5 -2
  66. package/docs/en/configure/app/output/css-module-local-ident-name.mdx +14 -2
  67. package/docs/en/configure/app/output/css-modules.mdx +46 -2
  68. package/docs/en/configure/app/output/data-uri-limit.mdx +24 -2
  69. package/docs/en/configure/app/output/disable-css-extract.mdx +9 -2
  70. package/docs/en/configure/app/output/disable-css-module-extension.mdx +52 -2
  71. package/docs/en/configure/app/output/disable-filename-hash.mdx +9 -2
  72. package/docs/en/configure/app/output/disable-inline-runtime-chunk.mdx +38 -2
  73. package/docs/en/configure/app/output/disable-minimize.mdx +7 -2
  74. package/docs/en/configure/app/output/disable-source-map.mdx +24 -2
  75. package/docs/en/configure/app/output/disable-svgr.mdx +13 -2
  76. package/docs/en/configure/app/output/disable-ts-checker.mdx +46 -2
  77. package/docs/en/configure/app/output/dist-path.mdx +39 -2
  78. package/docs/en/configure/app/output/enable-asset-fallback.mdx +29 -2
  79. package/docs/en/configure/app/output/enable-asset-manifest.mdx +33 -2
  80. package/docs/en/configure/app/output/enable-css-module-tsdeclaration.mdx +25 -2
  81. package/docs/en/configure/app/output/enable-inline-scripts.mdx +15 -2
  82. package/docs/en/configure/app/output/enable-inline-styles.mdx +15 -2
  83. package/docs/en/configure/app/output/enable-latest-decorators.mdx +7 -2
  84. package/docs/en/configure/app/output/externals.mdx +18 -2
  85. package/docs/en/configure/app/output/filename-hash.mdx +3 -27
  86. package/docs/en/configure/app/output/filename.mdx +47 -2
  87. package/docs/en/configure/app/output/inject-styles.mdx +15 -0
  88. package/docs/en/configure/app/output/inline-scripts.mdx +34 -0
  89. package/docs/en/configure/app/output/inline-styles.mdx +34 -0
  90. package/docs/en/configure/app/output/legal-comments.mdx +16 -2
  91. package/docs/en/configure/app/output/minify.mdx +27 -0
  92. package/docs/en/configure/app/output/override-browserslist.mdx +18 -2
  93. package/docs/en/configure/app/output/polyfill.mdx +12 -2
  94. package/docs/en/configure/app/output/source-map.mdx +30 -0
  95. package/docs/en/configure/app/output/ssg.mdx +20 -17
  96. package/docs/en/configure/app/output/svg-default-export.mdx +27 -2
  97. package/docs/en/configure/app/performance/build-cache.mdx +78 -2
  98. package/docs/en/configure/app/performance/bundle-analyze.mdx +18 -2
  99. package/docs/en/configure/app/performance/chunk-split.mdx +38 -2
  100. package/docs/en/configure/app/performance/dns-prefetch.mdx +13 -2
  101. package/docs/en/configure/app/performance/preconnect.mdx +14 -2
  102. package/docs/en/configure/app/performance/prefetch.mdx +19 -2
  103. package/docs/en/configure/app/performance/preload.mdx +21 -2
  104. package/docs/en/configure/app/performance/print-file-size.mdx +38 -2
  105. package/docs/en/configure/app/performance/profile.mdx +8 -2
  106. package/docs/en/configure/app/performance/remove-console.mdx +8 -2
  107. package/docs/en/configure/app/performance/remove-moment-locale.mdx +8 -2
  108. package/docs/en/configure/app/performance/transform-lodash.mdx +42 -2
  109. package/docs/en/configure/app/plugins.mdx +3 -3
  110. package/docs/en/configure/app/security/check-syntax.mdx +66 -2
  111. package/docs/en/configure/app/security/nonce.mdx +13 -2
  112. package/docs/en/configure/app/security/sri.mdx +19 -2
  113. package/docs/en/configure/app/server/port.mdx +5 -0
  114. package/docs/en/configure/app/server/ssr.mdx +10 -9
  115. package/docs/en/configure/app/source/alias-strategy.mdx +8 -2
  116. package/docs/en/configure/app/source/alias.mdx +17 -2
  117. package/docs/en/configure/app/source/config-dir.mdx +1 -1
  118. package/docs/en/configure/app/source/decorators.mdx +8 -21
  119. package/docs/en/configure/app/source/define.mdx +14 -2
  120. package/docs/en/configure/app/source/enable-async-entry.mdx +1 -1
  121. package/docs/en/configure/app/source/entries-dir.mdx +1 -1
  122. package/docs/en/configure/app/source/exclude.mdx +8 -2
  123. package/docs/en/configure/app/source/global-vars.mdx +103 -2
  124. package/docs/en/configure/app/source/include.mdx +19 -2
  125. package/docs/en/configure/app/source/mainEntryName.mdx +1 -1
  126. package/docs/en/configure/app/source/module-scopes.mdx +62 -2
  127. package/docs/en/configure/app/source/pre-entry.mdx +8 -2
  128. package/docs/en/configure/app/source/resolve-extension-prefix.mdx +48 -2
  129. package/docs/en/configure/app/source/resolve-main-fields.mdx +39 -2
  130. package/docs/en/configure/app/source/transform-import.mdx +56 -2
  131. package/docs/en/configure/app/tools/autoprefixer.mdx +41 -2
  132. package/docs/en/configure/app/tools/babel.mdx +218 -2
  133. package/docs/en/configure/app/tools/bundler-chain.mdx +23 -2
  134. package/docs/en/configure/app/tools/css-extract.mdx +31 -2
  135. package/docs/en/configure/app/tools/css-loader.mdx +14 -2
  136. package/docs/en/configure/app/tools/dev-server.mdx +435 -2
  137. package/docs/en/configure/app/tools/esbuild.mdx +2 -2
  138. package/docs/en/configure/app/tools/html-plugin.mdx +21 -2
  139. package/docs/en/configure/app/tools/less.mdx +78 -2
  140. package/docs/en/configure/app/tools/minify-css.mdx +50 -2
  141. package/docs/en/configure/app/tools/postcss.mdx +30 -2
  142. package/docs/en/configure/app/tools/pug.mdx +47 -2
  143. package/docs/en/configure/app/tools/rspack.mdx +8 -2
  144. package/docs/en/configure/app/tools/sass.mdx +75 -2
  145. package/docs/en/configure/app/tools/style-loader.mdx +8 -2
  146. package/docs/en/configure/app/tools/styled-components.mdx +48 -2
  147. package/docs/en/configure/app/tools/swc.mdx +34 -3
  148. package/docs/en/configure/app/tools/terser.mdx +49 -2
  149. package/docs/en/configure/app/tools/ts-checker.mdx +49 -2
  150. package/docs/en/configure/app/tools/ts-loader.mdx +63 -2
  151. package/docs/en/configure/app/tools/webpack-chain.mdx +239 -2
  152. package/docs/en/configure/app/tools/webpack.mdx +295 -2
  153. package/docs/en/guides/_meta.json +0 -5
  154. package/docs/en/guides/advanced-features/_meta.json +7 -5
  155. package/docs/en/guides/advanced-features/bff/_meta.json +1 -1
  156. package/docs/en/guides/advanced-features/bff/extend-server.mdx +154 -0
  157. package/docs/en/guides/advanced-features/bff/frameworks.mdx +52 -123
  158. package/docs/en/guides/advanced-features/bff/function.mdx +108 -80
  159. package/docs/en/guides/advanced-features/bff/sdk.mdx +40 -51
  160. package/docs/en/guides/advanced-features/build-performance.mdx +6 -21
  161. package/docs/en/guides/advanced-features/page-performance/_meta.json +1 -0
  162. package/docs/en/guides/advanced-features/rspack-start.mdx +2 -2
  163. package/docs/en/guides/basic-features/css/css-modules.mdx +2 -2
  164. package/docs/en/guides/basic-features/output-files.mdx +1 -1
  165. package/docs/en/guides/basic-features/render/ssg.mdx +1 -1
  166. package/docs/en/guides/basic-features/render/streaming-ssr.mdx +1 -1
  167. package/docs/en/guides/basic-features/routes.mdx +2 -3
  168. package/docs/en/guides/basic-features/static-assets.mdx +1 -1
  169. package/docs/en/guides/concept/builder.mdx +1 -1
  170. package/docs/en/guides/deprecated.md +2 -0
  171. package/docs/en/guides/get-started/glossary.mdx +7 -7
  172. package/docs/en/guides/get-started/quick-start.mdx +1 -1
  173. package/docs/en/guides/topic-detail/_meta.json +0 -6
  174. package/docs/en/guides/topic-detail/micro-frontend/c01-introduction.mdx +1 -1
  175. package/docs/en/guides/troubleshooting/builder.mdx +2 -2
  176. package/docs/en/plugin/_meta.json +19 -0
  177. package/docs/en/plugin/cli-plugins/_meta.json +1 -0
  178. package/docs/en/plugin/cli-plugins/plugin-bff.mdx +5 -0
  179. package/docs/en/plugin/cli-plugins/plugin-ssg.mdx +5 -0
  180. package/docs/en/{guides/rsbuild-plugins → plugin/cli-plugins}/plugin-swc.mdx +11 -4
  181. package/docs/en/plugin/cli-plugins/plugin-tailwind.mdx +5 -0
  182. package/docs/en/plugin/cli-plugins.mdx +6 -0
  183. package/docs/en/{guides/advanced-features/rsbuild-plugin.mdx → plugin/introduction.mdx} +34 -9
  184. package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/extend.mdx +1 -1
  185. package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/implement.mdx +3 -3
  186. package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/plugin-api.mdx +2 -2
  187. package/docs/en/plugin/rsbuild-plugins/_meta.json +1 -0
  188. package/docs/en/{guides → plugin}/rsbuild-plugins/plugin-esbuild.mdx +4 -4
  189. package/docs/en/plugin/rsbuild-plugins.mdx +3 -0
  190. package/docs/zh/_meta.json +10 -5
  191. package/docs/zh/apis/app/hooks/api/lambda.mdx +5 -48
  192. package/docs/zh/apis/app/hooks/api/middleware.mdx +11 -0
  193. package/docs/zh/community/blog/v2-release-note.mdx +1 -1
  194. package/docs/zh/community/contributing-guide.mdx +0 -1
  195. package/docs/zh/components/builder.mdx +3 -0
  196. package/docs/zh/components/bundler.mdx +4 -0
  197. package/docs/zh/components/enable-bff.mdx +19 -2
  198. package/docs/zh/components/enableSwc.mdx +17 -0
  199. package/docs/zh/components/esbuild.mdx +3 -0
  200. package/docs/zh/components/extend-bff-function.mdx +5 -0
  201. package/docs/zh/components/micro-frontend.mdx +6 -0
  202. package/docs/zh/components/module-federation.mdx +7 -0
  203. package/docs/zh/components/nodeVersion.mdx +28 -0
  204. package/docs/zh/components/other-plugins.mdx +0 -0
  205. package/docs/zh/components/output-asset-prefix-extend.mdx +0 -0
  206. package/docs/zh/components/output-polyfill-extend.mdx +0 -0
  207. package/docs/zh/components/prerequisites.mdx +1 -1
  208. package/docs/zh/components/rsbuild-config-tooltip.mdx +5 -0
  209. package/docs/zh/components/rsbuild.mdx +3 -0
  210. package/docs/zh/components/rspack.mdx +3 -0
  211. package/docs/zh/components/rspackPrecautions.mdx +6 -0
  212. package/docs/zh/components/rspackTip.mdx +7 -0
  213. package/docs/zh/components/swc.mdx +3 -0
  214. package/docs/zh/configure/app/auto-load-plugin.mdx +4 -0
  215. package/docs/zh/configure/app/dev/asset-prefix.mdx +12 -2
  216. package/docs/zh/configure/app/dev/before-start-url.mdx +14 -2
  217. package/docs/zh/configure/app/dev/client.mdx +20 -16
  218. package/docs/zh/configure/app/dev/hmr.mdx +8 -2
  219. package/docs/zh/configure/app/dev/host.mdx +15 -2
  220. package/docs/zh/configure/app/dev/https.mdx +72 -2
  221. package/docs/zh/configure/app/dev/live-reload.mdx +3 -15
  222. package/docs/zh/configure/app/dev/port.mdx +18 -2
  223. package/docs/zh/configure/app/dev/progress-bar.mdx +17 -2
  224. package/docs/zh/configure/app/dev/setup-middlewares.mdx +26 -39
  225. package/docs/zh/configure/app/dev/start-url.mdx +47 -2
  226. package/docs/zh/configure/app/dev/watch-files.mdx +5 -39
  227. package/docs/zh/configure/app/dev/write-to-disk.mdx +3 -26
  228. package/docs/zh/configure/app/experiments/lazy-compilation.mdx +84 -2
  229. package/docs/zh/configure/app/experiments/source-build.mdx +29 -2
  230. package/docs/zh/configure/app/html/app-icon.mdx +48 -2
  231. package/docs/zh/configure/app/html/crossorigin.mdx +9 -2
  232. package/docs/zh/configure/app/html/disable-html-folder.mdx +34 -2
  233. package/docs/zh/configure/app/html/favicon-by-entries.mdx +30 -2
  234. package/docs/zh/configure/app/html/favicon.mdx +15 -2
  235. package/docs/zh/configure/app/html/inject-by-entries.mdx +30 -2
  236. package/docs/zh/configure/app/html/inject.mdx +8 -2
  237. package/docs/zh/configure/app/html/meta-by-entries.mdx +41 -2
  238. package/docs/zh/configure/app/html/meta.mdx +22 -2
  239. package/docs/zh/configure/app/html/mount-id.mdx +8 -2
  240. package/docs/zh/configure/app/html/script-loading.mdx +8 -2
  241. package/docs/zh/configure/app/html/tags-by-entries.mdx +37 -2
  242. package/docs/zh/configure/app/html/tags.mdx +13 -2
  243. package/docs/zh/configure/app/html/template-by-entries.mdx +26 -2
  244. package/docs/zh/configure/app/html/template-parameters-by-entries.mdx +29 -2
  245. package/docs/zh/configure/app/html/template-parameters.mdx +31 -2
  246. package/docs/zh/configure/app/html/template.mdx +8 -2
  247. package/docs/zh/configure/app/html/title-by-entries.mdx +30 -2
  248. package/docs/zh/configure/app/html/title.mdx +16 -2
  249. package/docs/zh/configure/app/output/asset-prefix.mdx +12 -2
  250. package/docs/zh/configure/app/output/assets-retry.mdx +72 -2
  251. package/docs/zh/configure/app/output/charset.mdx +8 -2
  252. package/docs/zh/configure/app/output/clean-dist-path.mdx +13 -2
  253. package/docs/zh/configure/app/output/convert-to-rem.mdx +77 -2
  254. package/docs/zh/configure/app/output/copy.mdx +6 -2
  255. package/docs/zh/configure/app/output/css-module-local-ident-name.mdx +14 -2
  256. package/docs/zh/configure/app/output/css-modules.mdx +46 -2
  257. package/docs/zh/configure/app/output/data-uri-limit.mdx +24 -2
  258. package/docs/zh/configure/app/output/disable-css-extract.mdx +9 -2
  259. package/docs/zh/configure/app/output/disable-css-module-extension.mdx +52 -2
  260. package/docs/zh/configure/app/output/disable-filename-hash.mdx +9 -2
  261. package/docs/zh/configure/app/output/disable-inline-runtime-chunk.mdx +38 -2
  262. package/docs/zh/configure/app/output/disable-minimize.mdx +7 -2
  263. package/docs/zh/configure/app/output/disable-source-map.mdx +24 -2
  264. package/docs/zh/configure/app/output/disable-svgr.mdx +14 -2
  265. package/docs/zh/configure/app/output/disable-ts-checker.mdx +46 -2
  266. package/docs/zh/configure/app/output/dist-path.mdx +39 -2
  267. package/docs/zh/configure/app/output/enable-asset-fallback.mdx +29 -2
  268. package/docs/zh/configure/app/output/enable-asset-manifest.mdx +33 -2
  269. package/docs/zh/configure/app/output/enable-css-module-tsdeclaration.mdx +25 -2
  270. package/docs/zh/configure/app/output/enable-inline-scripts.mdx +15 -2
  271. package/docs/zh/configure/app/output/enable-inline-styles.mdx +15 -2
  272. package/docs/zh/configure/app/output/enable-latest-decorators.mdx +7 -2
  273. package/docs/zh/configure/app/output/externals.mdx +18 -2
  274. package/docs/zh/configure/app/output/filename-hash.mdx +4 -27
  275. package/docs/zh/configure/app/output/filename.mdx +47 -2
  276. package/docs/zh/configure/app/output/inject-styles.mdx +15 -0
  277. package/docs/zh/configure/app/output/inline-scripts.mdx +34 -0
  278. package/docs/zh/configure/app/output/inline-styles.mdx +34 -0
  279. package/docs/zh/configure/app/output/legal-comments.mdx +16 -2
  280. package/docs/zh/configure/app/output/minify.mdx +27 -0
  281. package/docs/zh/configure/app/output/override-browserslist.mdx +20 -2
  282. package/docs/zh/configure/app/output/polyfill.mdx +12 -2
  283. package/docs/zh/configure/app/output/source-map.mdx +30 -0
  284. package/docs/zh/configure/app/output/ssg.mdx +19 -15
  285. package/docs/zh/configure/app/output/svg-default-export.mdx +27 -2
  286. package/docs/zh/configure/app/performance/build-cache.mdx +77 -2
  287. package/docs/zh/configure/app/performance/bundle-analyze.mdx +18 -2
  288. package/docs/zh/configure/app/performance/chunk-split.mdx +38 -2
  289. package/docs/zh/configure/app/performance/dns-prefetch.mdx +13 -2
  290. package/docs/zh/configure/app/performance/preconnect.mdx +14 -2
  291. package/docs/zh/configure/app/performance/prefetch.mdx +19 -2
  292. package/docs/zh/configure/app/performance/preload.mdx +21 -2
  293. package/docs/zh/configure/app/performance/print-file-size.mdx +38 -2
  294. package/docs/zh/configure/app/performance/profile.mdx +8 -2
  295. package/docs/zh/configure/app/performance/remove-console.mdx +8 -2
  296. package/docs/zh/configure/app/performance/remove-moment-locale.mdx +8 -2
  297. package/docs/zh/configure/app/performance/transform-lodash.mdx +42 -2
  298. package/docs/zh/configure/app/plugins.mdx +3 -3
  299. package/docs/zh/configure/app/security/check-syntax.mdx +66 -2
  300. package/docs/zh/configure/app/security/nonce.mdx +13 -2
  301. package/docs/zh/configure/app/security/sri.mdx +19 -2
  302. package/docs/zh/configure/app/server/port.mdx +5 -0
  303. package/docs/zh/configure/app/server/ssr.mdx +10 -9
  304. package/docs/zh/configure/app/source/alias-strategy.mdx +8 -2
  305. package/docs/zh/configure/app/source/alias.mdx +17 -2
  306. package/docs/zh/configure/app/source/config-dir.mdx +1 -1
  307. package/docs/zh/configure/app/source/decorators.mdx +8 -20
  308. package/docs/zh/configure/app/source/define.mdx +14 -2
  309. package/docs/zh/configure/app/source/enable-async-entry.mdx +1 -1
  310. package/docs/zh/configure/app/source/entries-dir.mdx +1 -1
  311. package/docs/zh/configure/app/source/exclude.mdx +8 -2
  312. package/docs/zh/configure/app/source/global-vars.mdx +102 -2
  313. package/docs/zh/configure/app/source/include.mdx +19 -2
  314. package/docs/zh/configure/app/source/mainEntryName.mdx +1 -1
  315. package/docs/zh/configure/app/source/module-scopes.mdx +62 -2
  316. package/docs/zh/configure/app/source/pre-entry.mdx +8 -2
  317. package/docs/zh/configure/app/source/resolve-extension-prefix.mdx +50 -2
  318. package/docs/zh/configure/app/source/resolve-main-fields.mdx +39 -2
  319. package/docs/zh/configure/app/source/transform-import.mdx +56 -2
  320. package/docs/zh/configure/app/tools/autoprefixer.mdx +41 -2
  321. package/docs/zh/configure/app/tools/babel.mdx +218 -2
  322. package/docs/zh/configure/app/tools/bundler-chain.mdx +26 -2
  323. package/docs/zh/configure/app/tools/css-extract.mdx +28 -2
  324. package/docs/zh/configure/app/tools/css-loader.mdx +15 -2
  325. package/docs/zh/configure/app/tools/dev-server.mdx +435 -2
  326. package/docs/zh/configure/app/tools/esbuild.mdx +2 -2
  327. package/docs/zh/configure/app/tools/html-plugin.mdx +21 -2
  328. package/docs/zh/configure/app/tools/less.mdx +79 -2
  329. package/docs/zh/configure/app/tools/minify-css.mdx +50 -2
  330. package/docs/zh/configure/app/tools/postcss.mdx +31 -2
  331. package/docs/zh/configure/app/tools/pug.mdx +47 -2
  332. package/docs/zh/configure/app/tools/rspack.mdx +8 -2
  333. package/docs/zh/configure/app/tools/sass.mdx +73 -2
  334. package/docs/zh/configure/app/tools/style-loader.mdx +8 -2
  335. package/docs/zh/configure/app/tools/styled-components.mdx +47 -2
  336. package/docs/zh/configure/app/tools/swc.mdx +34 -3
  337. package/docs/zh/configure/app/tools/terser.mdx +49 -2
  338. package/docs/zh/configure/app/tools/ts-checker.mdx +49 -2
  339. package/docs/zh/configure/app/tools/ts-loader.mdx +63 -2
  340. package/docs/zh/configure/app/tools/webpack-chain.mdx +243 -2
  341. package/docs/zh/configure/app/tools/webpack.mdx +295 -2
  342. package/docs/zh/guides/_meta.json +0 -5
  343. package/docs/zh/guides/advanced-features/_meta.json +7 -5
  344. package/docs/zh/guides/advanced-features/bff/_meta.json +1 -1
  345. package/docs/zh/guides/advanced-features/bff/extend-server.mdx +156 -0
  346. package/docs/zh/guides/advanced-features/bff/frameworks.mdx +51 -117
  347. package/docs/zh/guides/advanced-features/bff/function.mdx +69 -59
  348. package/docs/zh/guides/advanced-features/bff/sdk.mdx +27 -36
  349. package/docs/zh/guides/advanced-features/build-performance.mdx +6 -21
  350. package/docs/zh/guides/advanced-features/page-performance/_meta.json +1 -0
  351. package/docs/zh/guides/advanced-features/rspack-start.mdx +4 -4
  352. package/docs/zh/guides/basic-features/alias.mdx +5 -11
  353. package/docs/zh/guides/basic-features/css/css-modules.mdx +1 -1
  354. package/docs/zh/guides/basic-features/env-vars.mdx +1 -1
  355. package/docs/zh/guides/basic-features/output-files.mdx +2 -2
  356. package/docs/zh/guides/basic-features/routes.mdx +1 -2
  357. package/docs/zh/guides/basic-features/static-assets.mdx +1 -1
  358. package/docs/zh/guides/concept/builder.mdx +1 -1
  359. package/docs/zh/guides/deprecated.md +4 -0
  360. package/docs/zh/guides/get-started/glossary.mdx +7 -7
  361. package/docs/zh/guides/get-started/quick-start.mdx +1 -1
  362. package/docs/zh/guides/topic-detail/_meta.json +0 -6
  363. package/docs/zh/guides/topic-detail/micro-frontend/c01-introduction.mdx +1 -1
  364. package/docs/zh/guides/troubleshooting/builder.mdx +2 -2
  365. package/docs/zh/plugin/_meta.json +19 -0
  366. package/docs/zh/plugin/cli-plugins/_meta.json +1 -0
  367. package/docs/zh/plugin/cli-plugins/plugin-bff.mdx +5 -0
  368. package/docs/zh/plugin/cli-plugins/plugin-ssg.mdx +5 -0
  369. package/docs/zh/{guides/rsbuild-plugins → plugin/cli-plugins}/plugin-swc.mdx +11 -4
  370. package/docs/zh/plugin/cli-plugins/plugin-tailwind.mdx +5 -0
  371. package/docs/zh/plugin/cli-plugins.mdx +6 -0
  372. package/docs/zh/{guides/advanced-features/rsbuild-plugin.mdx → plugin/introduction.mdx} +36 -11
  373. package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/extend.mdx +1 -1
  374. package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/implement.mdx +3 -3
  375. package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/plugin-api.mdx +2 -2
  376. package/docs/zh/plugin/rsbuild-plugins/_meta.json +1 -0
  377. package/docs/zh/{guides → plugin}/rsbuild-plugins/plugin-esbuild.mdx +6 -6
  378. package/docs/zh/plugin/rsbuild-plugins.mdx +4 -0
  379. package/i18n.json +27 -3
  380. package/package.json +8 -13
  381. package/rspress.config.ts +1 -58
  382. package/src/components/Footer/index.tsx +1 -1
  383. package/src/components/RsbuildLink/index.tsx +19 -0
  384. package/src/pages/index.tsx +0 -1
  385. package/docs/en/apis/app/hooks/api/api.mdx +0 -80
  386. package/docs/en/apis/app/hooks/api/app.mdx +0 -12
  387. package/docs/en/guides/advanced-features/bff/type.mdx +0 -46
  388. package/docs/en/guides/advanced-features/eslint.mdx +0 -148
  389. package/docs/zh/apis/app/hooks/api/api.mdx +0 -81
  390. package/docs/zh/apis/app/hooks/api/app.mdx +0 -12
  391. package/docs/zh/guides/advanced-features/bff/type.mdx +0 -46
  392. package/docs/zh/guides/advanced-features/eslint.mdx +0 -152
  393. /package/docs/en/configure/app/output/{splitRouteChunks.mdx → split-route-chunks.mdx} +0 -0
  394. /package/docs/en/guides/advanced-features/{bff/index.mdx → bff.mdx} +0 -0
  395. /package/docs/en/guides/advanced-features/{code-split.mdx → page-performance/code-split.mdx} +0 -0
  396. /package/docs/en/guides/advanced-features/{inline-assets.mdx → page-performance/inline-assets.mdx} +0 -0
  397. /package/docs/en/guides/advanced-features/{optimize-bundle.mdx → page-performance/optimize-bundle.mdx} +0 -0
  398. /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/_meta.json +0 -0
  399. /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook-list.mdx +0 -0
  400. /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook.mdx +0 -0
  401. /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/introduction.mdx +0 -0
  402. /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/lifecycle.mdx +0 -0
  403. /package/docs/en/{guides/topic-detail/framework-plugin → plugin/plugin-system}/relationship.mdx +0 -0
  404. /package/docs/zh/configure/app/output/{splitRouteChunks.mdx → split-route-chunks.mdx} +0 -0
  405. /package/docs/zh/guides/advanced-features/{bff/index.mdx → bff.mdx} +0 -0
  406. /package/docs/zh/guides/advanced-features/{code-split.mdx → page-performance/code-split.mdx} +0 -0
  407. /package/docs/zh/guides/advanced-features/{inline-assets.mdx → page-performance/inline-assets.mdx} +0 -0
  408. /package/docs/zh/guides/advanced-features/{optimize-bundle.mdx → page-performance/optimize-bundle.mdx} +0 -0
  409. /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/_meta.json +0 -0
  410. /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook-list.mdx +0 -0
  411. /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/hook.mdx +0 -0
  412. /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/introduction.mdx +0 -0
  413. /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/lifecycle.mdx +0 -0
  414. /package/docs/zh/{guides/topic-detail/framework-plugin → plugin/plugin-system}/relationship.mdx +0 -0
@@ -1,10 +1,8 @@
1
- ---
2
- sidebar_position: 1
3
- title: Basic Usage
4
- ---
5
1
  # Basic Usage
6
2
 
7
- Applications developed with Modern.js can define API functions in the `api/` directory, which can be called by the front-end to send requests without writing front and back-end glue layer code, At the same time, it ensures the type safety of the front and back end
3
+ In a Modern.js application, developers can define API files under the `api/lambda` directory and export API functions from these files. In the frontend code, these API functions can be directly invoked by importing the file, which initiates the API requests.
4
+
5
+ This invocation method is called **unified invocation**, where developers do not need to write glue code for the frontend and backend separately, thereby ensuring type safety across both.
8
6
 
9
7
  ## Enable BFF
10
8
 
@@ -12,17 +10,17 @@ import EnableBFF from "@site-docs-en/components/enable-bff"
12
10
 
13
11
  <EnableBFF/>
14
12
 
15
- ## BFF Function
13
+ ## BFF Functions
16
14
 
17
- The functions that are allowed to be called through integration are called **BFF functions**. Here is the simplest BFF function to write, creating an `api/hello.ts` file:
15
+ Functions that allow unified invocation are called **BFF Functions**. Here is an example of the simplest BFF function. First, create the `api/lambda/hello.ts` file:
18
16
 
19
- ```ts title="api/hello.ts"
17
+ ```ts title="api/lambda/hello.ts"
20
18
  export const get = async () => 'Hello Modern.js';
21
19
  ```
22
20
 
23
- Then directly import the function in `src/App.tsx` and call:
21
+ Then, import and invoke the function directly in `src/routes/page.tsx`:
24
22
 
25
- ```tsx title=src/App.tsx
23
+ ```tsx title="src/routes/page.tsx"
26
24
  import { useState, useEffect } from 'react';
27
25
  import { get as hello } from '@api/hello';
28
26
 
@@ -36,131 +34,142 @@ export default () => {
36
34
  };
37
35
  ```
38
36
 
39
- :::info
40
- Modern.js generator has already configured the `@api` alias in tsconfig.json, so you can import functions directly by aliases.
41
-
37
+ :::tip
38
+ After running the `new` command, the Modern.js generator will automatically configure the `@api` alias in `tsconfig.json`, allowing you to import functions directly using the alias.
42
39
  :::
43
40
 
44
- The functions import in `src/App.tsx` will be automatically converted into interface calls, so there is no need to call the interface through fetch.
41
+ The function imported in `src/routes/page.tsx` will be automatically converted into an API call, eliminating the need to use an SDK or Web Fetch to call the API.
45
42
 
46
- Execute `pnpm run dev`, then open `http://localhost:8080/` to see that the page has displayed the content returned by the BFF function. In Network, you can see that the page sent a request to `http://localhost:8080/api/hello`.
43
+ After running `pnpm run dev`, open `http://localhost:8080/` and you can see that the page displays the content returned by the BFF function. In the Network tab, you can see a request was made to `http://localhost:8080/api/hello`.
47
44
 
48
45
  ![Network](https://p6-piu.byteimg.com/tos-cn-i-8jisjyls3a/fd41750f8d414179a9b4ecb519919b36~tplv-8jisjyls3a-3:0:0:q75.png)
49
46
 
50
- ## API Routes
47
+ ## Function Routes
51
48
 
52
- In Modern.js, the BFF function routing system is implemented based on the file system, and it is also a conventional routing system.
53
-
54
- In **Function Mode**, All files under `api/` will map to an interface. In **Framework Mode**, All files under `api/lambda` will map to an interface
55
-
56
- :::note
57
- Function Mode & Framework Mode will introduce soon.
49
+ In Modern.js, the routing system for BFF functions is implemented based on the file system, which is another form of **conventional routing**. Each BFF function in the `api/lambda` directory is mapped to an API route. Here are some routing conventions.
58
50
 
51
+ :::info
52
+ All routes generated by BFF functions have a common prefix, which defaults to `/api`. This can be configured using [bff.prefix](/configure/app/bff/prefix).
59
53
  :::
60
54
 
61
- All routes generated by BFF functions have a prefix, and the default value is `/api`. The prefix can be set through [bff.prefix](/configure/app/bff/prefix).
55
+ ### Default Routes
62
56
 
63
- Several routing conventions are described as follow.
57
+ Files named `index.[jt]s` will be mapped to the parent directory.
64
58
 
65
- ### Default Route
59
+ - `api/lambda/index.ts` -> `{prefix}/`
60
+ - `api/lambda/user/index.ts` -> `{prefix}/user`
66
61
 
67
- Files named `index.[jt]s` are mapped to the previous directory.
62
+ ### Nested Routes
68
63
 
69
- - `api/index.ts` -> `{prefix}/`
70
- - `api/user/index.ts` -> `{prefix}/user`
64
+ Nested directories are supported, and files will be automatically parsed into routes in the same way.
71
65
 
72
- ### Multi-layer Routing
66
+ - `api/lambda/hello.ts` -> `{prefix}/hello`
67
+ - `api/lambda/user/list.ts` -> `{prefix}/user/list`
73
68
 
74
- Supports parsing nested files, if you create a nested folder structure, the files will still automatically parse routes in the same way.
69
+ ### Dynamic Routes
75
70
 
76
- - `api/hello.ts` -> `{prefix}/hello`
77
- - `api/user/list.ts` -> `{prefix}/user/list`
71
+ Similarly, creating a directory or file with `[xxx]` in the name supports dynamic route parameters. The rules for dynamic route function parameters can be found in [dynamic-path](/guides/advanced-features/bff/function#dynamic-path).
78
72
 
79
- ### Dynamic Routing
73
+ - `api/lambda/user/[username]/info.ts` -> `{prefix}/user/:username/info`
74
+ - `api/lambda/user/username/[action].ts` -> `{prefix}/user/username/:action`
80
75
 
81
- Create folders or files named with `[xxx]` to support dynamic named routing parameters.
76
+ ### Whitelist
82
77
 
83
- - `api/user/[username]/info.ts` -> `{prefix}/user/:username/info`
84
- - `api/user/username/[action].ts` -> `{prefix}/user/username/:action`
78
+ By default, all files under the `api/lambda/` directory are parsed as BFF function files, but the following files are ignored:
85
79
 
86
- ### Allow List
87
-
88
- By default, all files in the'api/'directory will be parsed as BFF function files, but the following files will not be parsed:
89
-
90
- - file name start with `_`, for example `_utils.ts`.
91
- - files in directory which name start with `_`, for example `_utils/index.ts`、`_utils/cp.ts`.
92
- - test files, for example `foo.test.ts`.
93
- - type files, for example `hello.d.ts`.
94
- - files in `node_module`.
80
+ - Files starting with an underscore `_`. For example: `_utils.ts`.
81
+ - Files under directories starting with an underscore `_`. For example: `_utils/index.ts`, `_utils/cp.ts`.
82
+ - Test files. For example: `foo.test.ts`.
83
+ - TypeScript type files. For example: `hello.d.ts`.
84
+ - Files under `node_modules`.
95
85
 
96
86
  ## RESTful API
97
87
 
98
- Modern.js BFF functions need to be defined according to the RESTful API standard, follow the HTTP Method specification, and do not allow free parameter definition.
99
-
100
- :::info
101
- Assuming that the function allows free definition of parameters, the resulting route must be called by the **private protocol** (the reason is that the request parameters cannot be distinguished from the request body), and cannot implement any RESTful API.
102
-
103
- If the service is only used for the application itself, there is no problem. but its **non-standard interface definition** cannot be integrated into the larger system. In the case of multiple systems working together (such as BFF low-code construction), other systems also need to follow the **private protocol**.
88
+ Modern.js BFF functions need to follow RESTful API standards for definition. Developers must define BFF functions according to a set of rules.
104
89
 
90
+ :::tip Design Principles
91
+ BFF functions should not only be invoked within the project but also be accessible to other projects via an SDK or Web fetch. Therefore, Modern.js does not define a **private protocol** for unified invocation but uses standard HTTP methods along with common HTTP request parameters like `params`, `query`, and `body` to define functions.
105
92
  :::
106
93
 
107
- ### Function Named Export
94
+ ### Function Export Rules
108
95
 
109
- Modern.js the export name of the BFF function determines the Method of the corresponding interface of the function, such as `get`, `post` and so on.
96
+ #### HTTP Method Named Functions
110
97
 
111
- For example, following the example, a `GET` interface can be exported.
98
+ Modern.js BFF functions' export names determine the HTTP method for the corresponding API, such as `get`, `post`, etc. For example, to export a GET API:
112
99
 
113
100
  ```ts
114
101
  export const get = async () => {
115
102
  return {
116
103
  name: 'Modern.js',
117
- desc: 'Web engineering system',
104
+ desc: 'A modern web engineering solution',
118
105
  };
119
106
  };
120
107
  ```
121
108
 
122
- Following the example below, a `POST` interface can be exported.
109
+ The following example exports a `POST` API:
123
110
 
124
111
  ```ts
125
112
  export const post = async () => {
126
113
  return {
127
114
  name: 'Modern.js',
128
- desc: 'Web engineering system',
115
+ desc: 'A modern web engineering solution',
129
116
  };
130
117
  };
131
118
  ```
132
119
 
133
- - Modern.js supports 9 definitions for HTTP Method: `GET`、`POST`、`PUT`、`DELETE`、`CONNECT`、`TRACE`、`PATCH`、`OPTIONS`、`HEAD`, can be exported using these methods as functions.
120
+ - Modern.js supports 9 HTTP methods: `GET`, `POST`, `PUT`, `DELETE`, `CONNECT`, `TRACE`, `PATCH`, `OPTIONS`, and `HEAD`, which can be used as function export names.
134
121
 
135
- - The name is size insensitive, if `GET`, can write `get`、`Get`、`GEt`、`GET`, can be accurately identified. But default export as `export default xxx` will be map to `Get`.
122
+ - Names are case-insensitive. If the method is `GET`, it can be written as `get`, `Get`, `GEt`, or `GET`, and the default export, i.e., `export default xxx`, will be mapped to `Get`.
136
123
 
137
- - Multiple functions of different Methods can be defined in one file, but if multiple functions of the same Method are defined, only the first will take effect.
124
+ #### Using Async Functions
138
125
 
139
- :::info
140
- It should be noted that the defined functions should all be asynchronous, which is related to the type when the function is called, which will be mentioned later.
126
+ Modern.js recommends defining BFF functions as async functions, even if there is no asynchronous process in the function, for example:
141
127
 
142
- :::
128
+ ```ts
129
+ export const get = async () => {
130
+ return {
131
+ name: 'Modern.js',
132
+ desc: 'A modern web engineering solution',
133
+ };
134
+ };
135
+ ```
143
136
 
144
- ### Function Parameter Rule
137
+ This is because, during frontend invocation, the BFF function will be automatically converted into an HTTP API call, and HTTP API calls are asynchronous. On the frontend, it is typically used like this:
145
138
 
146
- As mentioned above, in order to meet the design criteria of RESTful APIs, the BFF function in Modern.js needs to follow certain imported parameter rules.
139
+ ```tsx title="src/routes/page.tsx"
140
+ import { useState, useEffect } from 'react';
141
+ import { get as hello } from '@api/hello';
147
142
 
148
- The function parameters are divided into two parts, the dynamic part in the request path and the request option `RequestOption`.
143
+ export default () => {
144
+ const [text, setText] = useState('');
145
+
146
+ useEffect(() => {
147
+ hello().then(setText);
148
+ }, []);
149
+ return <div>{text}</div>;
150
+ };
151
+ ```
152
+
153
+ Therefore, to keep the type definitions consistent with the actual invocation experience, we recommend defining BFF functions as async functions.
154
+
155
+ ### Function Parameter Rules
156
+
157
+ Function parameter rules are divided into two parts: dynamic routes in the request path (`Dynamic Path`) and request options (`RequestOption`).
149
158
 
150
159
  #### Dynamic Path
151
160
 
152
- Dynamic routing will be used as imported parameters in the first part of the function, and each imported parameter corresponds to a dynamic route. For example, in the following example, uid will be passed into the function as the first two parameters:
161
+ Dynamic routes will be the first part of the BFF function parameters, with each parameter corresponding to a segment of the dynamic route. For example, the `level` and `id` parameters will be passed to the function in the following example:
153
162
 
154
- ```ts title="api/[level]/[id].ts"
163
+ ```ts title="api/lambda/[level]/[id].ts"
155
164
  export default async (level: number, id: number) => {
156
165
  const userData = await queryUser(level, uid);
157
166
  return userData;
158
167
  };
159
168
  ```
160
169
 
161
- Pass dynamic parameters directly when calling:
170
+ Invoke the function by directly passing in the dynamic parameters:
162
171
 
163
- ```ts title="App.tsx"
172
+ ```tsx title="src/routes/page.tsx"
164
173
  import { useState, useEffect } from 'react';
165
174
  import { get as getUser } from '@api/[level]/[id]';
166
175
 
@@ -177,24 +186,41 @@ export default () => {
177
186
 
178
187
  #### RequestOption
179
188
 
180
- The parameter after Dynamic Path is the object `RequestOption` containing querystring and request body, which is used to define the types of `data` and `query`.
189
+ Parameters following the dynamic path are an object called `RequestOption`, which includes the query string and request body. This field is used to define the types for `data` and `query`.
181
190
 
182
- In normal functions without dynamic routing, the incoming `data` and `query` can be obtained from the first imported parameter, for example:
191
+ In a standard function without dynamic routes, `RequestOption` can be obtained from the first parameter, for example:
183
192
 
184
- ```ts title="api/hello.ts"
193
+ ```ts title="api/lambda/hello.ts"
185
194
  import type { RequestOption } from '@modern-js/runtime/server';
186
195
 
187
196
  export async function post({
188
197
  query,
189
198
  data,
190
199
  }: RequestOption<Record<string, string>, Record<string, string>>) {
191
- // do somethings
200
+ // do something
192
201
  }
193
202
  ```
194
203
 
195
- When a function file uses dynamic routing rules, dynamic routing before the `RequestOption` parameter.
204
+ Custom types can also be used here:
205
+
206
+ ```ts title="api/lambda/hello.ts"
207
+ import type { RequestOption } from '@modern-js/runtime/server';
208
+
209
+ type IQuery = {
210
+ // some types
211
+ };
212
+ type IData = {
213
+ // some types
214
+ };
196
215
 
197
- ```ts title="api/[sku]/[id]/item.ts"
216
+ export async function post({ query, data }: { query: IQuery; data: IData }) {
217
+ // do something
218
+ }
219
+ ```
220
+
221
+ When the function file uses dynamic routing, dynamic routes will precede the `RequestOption` object parameter.
222
+
223
+ ```ts title="api/lambda/[sku]/[id]/item.ts"
198
224
  export async function post(
199
225
  sku: string,
200
226
  id: string,
@@ -207,9 +233,9 @@ export async function post(
207
233
  }
208
234
  ```
209
235
 
210
- Also pass in the parameters according to the function definition:
236
+ Pass the corresponding parameters when invoking the function according to its definition:
211
237
 
212
- ```ts title="App.tsx"
238
+ ```ts title="src/routes/page.tsx"
213
239
  import { post } from '@api/[sku]/[id]/item';
214
240
 
215
241
  export default () => {
@@ -228,6 +254,8 @@ export default () => {
228
254
  };
229
255
  ```
230
256
 
231
- As mentioned earlier, the defined functions should be asynchronous because they are automatically converted to HTTP interface calls when called by the front end.
257
+ ## Extend BFF Function
258
+
259
+ import ExtendBFF from "@site-docs-en/components/extend-bff-function"
232
260
 
233
- so in order to keep the type definition consistent with the actual calling, it is necessary to set the BFF function to asynchronous when defining it.
261
+ <ExtendBFF/>
@@ -1,81 +1,70 @@
1
- ---
2
- sidebar_position: 4
3
- title: Custom request SDK
4
- ---
5
- # Custom request SDK
1
+ # Extend Request SDK
6
2
 
7
- Modernjs's BFF is isomorphic in CSR and SSR.In the browser side rely on the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch),On the server relies on the [node-fetch](https://www.npmjs.com/package/node-fetch).However, in many business scenarios we need to do some additional processing of the request or response, for example:
3
+ The unified invocation of BFF functions is isomorphic in both CSR and SSR. The request SDK encapsulated by Modern.js relies on the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) on the browser side, and on [node-fetch](https://www.npmjs.com/package/node-fetch) on the server side. However, in actual business scenarios, additional processing may be required for requests or responses, such as:
8
4
 
9
- - Write auth information in the request header
10
- - Uniform processing of response data or errors
11
- - The browser's native fetch function is not available for a particular platform, and other methods of sending requests are required
5
+ - Writing authentication information in the request headers
6
+ - Uniform handling of response data or errors
7
+ - Using other methods to send requests when the native fetch function is unavailable on specific platforms
12
8
 
13
- For the above scenario, Modern.js provides the `configure` function,the customization capabilities range from low to high and can be used to configure ssr pass-through request headers, interceptors, and request SDKs..
14
-
15
- :::caution
16
- The `configure` function call needs to be called before all BFF requests are sent, to ensure that the default request configuration is overridden.
9
+ To address these scenarios, Modern.js provides the `configure` function, which offers a series of extension capabilities. You can use it to configure SSR passthrough request headers, add interceptors, or customize the request SDK.
17
10
 
11
+ :::caution Note
12
+ The `configure` function needs to be called before all BFF requests are sent to ensure that the default request configuration is overridden.
18
13
  :::
19
14
 
20
-
21
- ```ts title="App.tsx"
15
+ ```tsx title="routes/page.tsx"
22
16
  import { configure } from '@modern-js/runtime/bff';
23
17
 
24
18
  configure({
25
- request: customRequest
19
+ // ...
26
20
  })
27
- ```
28
21
 
29
- ## Configure ssr pass-through request headers
22
+ const Index = () => <div>Hello world</div>
23
+ export default Index;
24
+ ```
30
25
 
31
- In scenarios where both Modern.js SSR and BFF are used, it is often necessary to pass some request headers on SSR page requests to the BFF service.
26
+ ## Configuring SSR Passthrough Request Headers
32
27
 
33
- For example, the project has a page address `https://website.com`, which is an SSR page, and the API interface `https://website.com/api/info` will be called in the component, which requires the user's cookie information for authentication. When the page requests this API interface, it needs to pass the `cookie` requested by the SSR page to BFF.
28
+ When using both Modern.js SSR and BFF, it is often necessary to pass some request header information from the SSR page request to the BFF service.
34
29
 
35
- Currently the following request headers are automatically passed through in Modern.js:
30
+ For example, imagine a project with a page URL `https://website.com`. This page is rendered using SSR, and in the component, it will call the API endpoint `https://website.com/api/info`, which requires the user's cookie information for authentication. The page needs to pass the `cookie` of the SSR page request to the BFF when requesting this API endpoint.
36
31
 
37
- - cookie
38
- - x-tt-logid
39
- - user-agent
40
- - x-tt-stress
32
+ Currently, the following request headers are automatically passed through in Modern.js:
41
33
 
42
- The request header can be configured via `configure`. For example, in the following example, Modern.js will automatically pass the cookie information of the SSR page request to the BFF service:
34
+ ```ts
35
+ ['cookie', 'user-agent', 'x-tt-logid', 'x-tt-stress']
36
+ ```
43
37
 
44
- ```tsx title="App.tsx"
45
- import { configure } from '@modern-js/runtime/bff';
38
+ You can configure additional request headers using `configure`. For example, in the following snippet, Modern.js will automatically pass the `x-uid` information from the SSR page request to the BFF service:
46
39
 
40
+ ```tsx
47
41
  configure({
48
42
  allowedHeaders: ['x-uid']
49
43
  })
50
44
  ```
51
45
 
52
- ## Configuring Interceptors
46
+ ## Adding Interceptors
53
47
 
54
- In certain business scenarios, there is a requirement for unified processing of requests and responses, and interceptors can be configured to fulfill these requirements in such scenarios.
48
+ In some business scenarios, you may need to handle requests and responses uniformly. This can be achieved by **configuring interceptors**:
55
49
 
56
- ```tsx title="App.tsx"
50
+ ```tsx
57
51
  configure({
58
- // The request here is the default request sdk for bff, and the interceptor function needs to return a new request.
59
- // The return value of the new request must be the result of the parse body
60
- interceptor(request){
61
- return async(url, params) => {
52
+ // The `request` here is the default request tool for unified invocation. The `interceptor` function needs to return a new request.
53
+ // The output of the new request must be the parsed body result.
54
+ interceptor(request) {
55
+ return async (url, params) => {
62
56
  const res = await request(url, params);
63
57
  return res.json();
64
58
  };
65
- };
59
+ }
66
60
  });
67
61
  ```
68
62
 
69
- ## Configure custom request SDK
70
-
71
- If the requirements cannot be met by configuring interceptors alone and need to further customize the request SDK, you can configure the custom request SDK by using the `configure` function:
72
-
73
- :::caution
74
- Send a request to the BFF service when the server side renders, Modern.js will find the BFF service intranet IP via **service discovery** and send requests via IP to improve performance. This optimization is **lost** if a custom request SDK is used.
63
+ ## Customizing the Request SDK
75
64
 
76
- :::
65
+ If configuring interceptors alone cannot meet your needs and you want to customize the request function, you can also configure it using `configure`:
77
66
 
78
- ```tsx title="App.tsx"
67
+ ```tsx
79
68
  import nodeFetch from 'node-fetch';
80
69
 
81
70
  const customFetch = (input: RequestInfo | URL, init: RequestInit) => {
@@ -92,13 +81,13 @@ configure({
92
81
  });
93
82
  ```
94
83
 
95
- The configuration custom request SDK has the following conventions:
84
+ There are some conventions when configuring custom request functions:
96
85
 
97
- - The `configure` function allows you to configure a `request` function whose input is the same as the Fetch or node-fetch in the browser, and all BFF functions will send requests through this function
98
- - The return value of the `request` function must be the actual data returned by the interface, not a Promise, otherwise the BFF function will not return data properly.
99
- - In the case of SSR projects, `request` must support both browser-side and server-side sending of requests.
86
+ - The function's parameters should align with the Fetch API or node-fetch in the browser. All unified invocations of BFF functions will send requests via this function.
87
+ - The function's output must be the actual data returned by the API, not a Promise, otherwise, the BFF function will not return data correctly.
88
+ - If it's an SSR project, the function must support sending requests on both the browser and server sides.
100
89
 
101
- Example of custom request SDK using axios:
90
+ Below is an example of using axios to customize a request function:
102
91
 
103
92
  ```tsx title="App.tsx"
104
93
  import { configure } from '@modern-js/runtime/bff';
@@ -108,7 +97,7 @@ configure({
108
97
  async request(...config: Parameters<typeof fetch>) {
109
98
  const [url, params] = config;
110
99
  const res = await axios({
111
- url: url as string, // Here, because of some incompatibility between fetch and axios types, you need to use `as`
100
+ url: url as string, // Here we need to use `as` because fetch and axios types are somewhat incompatible
112
101
  method: params?.method as Method,
113
102
  data: params?.body,
114
103
  headers: params?.headers as Headers,
@@ -116,4 +105,4 @@ configure({
116
105
  return res.data;
117
106
  },
118
107
  });
119
- ```
108
+ ```
@@ -9,13 +9,17 @@ Modern.js optimizes build performance by default, but as the project becomes lar
9
9
  This document provides some optional speed-up strategies, developers can choose some of them to improve the build performance.
10
10
 
11
11
  :::tip 📢 Notice
12
- The strategies in [Bundle Size Optimization](/guides/advanced-features/optimize-bundle.html) can also be used to improve build performance, so we won't repeat them here.
12
+ The strategies in [Bundle Size Optimization](/guides/advanced-features/page-performance/optimize-bundle) can also be used to improve build performance, so we won't repeat them here.
13
13
  :::
14
14
 
15
15
  ## General optimization strategy
16
16
 
17
17
  The following are some general optimization strategies, which can speed up the development build and production build, and some of them also optimize the bundle size.
18
18
 
19
+ ### Using Rspack (recommended)
20
+
21
+ If you are not using Rspack yet, you can switch to Rspack build mode to improve the build speed by 5~10 times, see [Using Rspack](/guides/advanced-features/rspack-start.html) for more information.
22
+
19
23
  ### Upgrade Node.js version
20
24
 
21
25
  In general, updating Node.js to the latest [LTS release](https://github.com/nodejs/release#release-schedule) will help improve build performance.
@@ -40,25 +44,6 @@ nvm default 18
40
44
  node -v
41
45
  ```
42
46
 
43
- ### Using Rspack build
44
-
45
- If you have higher build performance requirements, you can easily switch to Rspack build mode, see [Using Rspack](/guides/advanced-features/rspack-start.html) for more information.
46
-
47
- ### Using SWC or esbuild
48
-
49
- [SWC](https://SWC.rs/) (Speedy Web Compiler) is a transformer and minimizer for JavaScript and TypeScript based on `Rust`. SWC can provide the same abilities with Babel, and it's more than 10x faster than Babel.
50
-
51
- [esbuild](https://esbuild.github.io/) is a front-end build tool based on Golang. It has the functions of bundling, compiling and minimizing JavaScript code. Compared with traditional tools, the performance is significantly improved. When minimizing code, compared to webpack's built-in terser minimizer, esbuild has dozens of times better performance.
52
-
53
- Modern.js provides SWC plugin and esbuild plugin that allow you to use SWC or esbuild instead of babel-loader, ts-loader and terser for transformation and minification process. See:
54
-
55
- - [SWC plugin document](/configure/app/tools/swc.html)
56
- - [esbuild plugin document](/configure/app/tools/esbuild.html)
57
-
58
- :::tip SWC vs esbuild
59
- The SWC compiled outputs has better compatibility, supports polyfills such as core-js, and has more complete features, so it is recommended to use the SWC plugin first.
60
- :::
61
-
62
47
  ### Avoid using ts-loader
63
48
 
64
49
  By default, Modern.js uses Babel to compile TS files. After enabling the [tools.tsLoader](/en/configure/app/tools/ts-loader.html) option, `ts-loader` will be used to compile TS files.
@@ -118,7 +103,7 @@ export default {
118
103
 
119
104
  ### Adjust Browserslist for development
120
105
 
121
- This strategy is similar to ["Adjust Browserslist"](/guides/advanced-features/optimize-bundle.html#adjust-browserslist), the difference is that we can set different browserslist for development and production environment, thereby reducing the compilation overhead in the development environment.
106
+ This strategy is similar to ["Adjust Browserslist"](/guides/advanced-features/page-performance/optimize-bundle#adjust-browserslist), the difference is that we can set different browserslist for development and production environment, thereby reducing the compilation overhead in the development environment.
122
107
 
123
108
  For example, you can add the following config to `package.json`, which means that only the latest browsers are compatible in the development environment, and the actual browsers are compatible in the production environment:
124
109
 
@@ -0,0 +1 @@
1
+ ["code-split", "inline-assets", "optimize-bundle"]
@@ -4,7 +4,7 @@ sidebar_position: 1
4
4
 
5
5
  # Using Rspack
6
6
 
7
- import Rspack from '@modern-js/builder-doc/docs/en/shared/rspackTip.mdx';
7
+ import Rspack from '@site-docs-en/components/rspackTip.mdx';
8
8
 
9
9
  <Rspack />
10
10
 
@@ -42,7 +42,7 @@ export default defineConfig({
42
42
  If your current version is lower than MAJOR_VERSION.59.0, you can upgrade by executing `npx modern upgrade`.
43
43
  :::
44
44
 
45
- import RspackPrecautions from '@modern-js/builder-doc/docs/en/shared/rspackPrecautions.md';
45
+ import RspackPrecautions from '@site-docs-en/components/rspackPrecautions.mdx';
46
46
 
47
47
  <RspackPrecautions />
48
48
 
@@ -2,7 +2,7 @@
2
2
 
3
3
  [CSS Modules](https://github.com/css-modules/css-modules) allows us to write CSS code in a modular way, and these styles can be imported and used in JavaScript files. Using CSS Modules can automatically generate unique class names, isolate styles between different modules, and avoid class name conflicts.
4
4
 
5
- Builder supports CSS Modules by default, you don't need to add additional configuration. Our convention is to use the `[name].module.css` filename to enable CSS Modules.
5
+ Modern.js supports CSS Modules by default, you don't need to add additional configuration. Our convention is to use the `[name].module.css` filename to enable CSS Modules.
6
6
 
7
7
  The following style files are considered CSS Modules:
8
8
 
@@ -163,7 +163,7 @@ After adding the type declaration, if the type error still exists, you can try t
163
163
 
164
164
  Although the above method can provide the type of CSS Modules, it cannot accurately prompt which classNames are exported by a certain CSS file.
165
165
 
166
- Builder supports generating accurate type declarations for CSS Modules, you only need to enable the [output.enableCssModuleTSDeclaration](/configure/app/output/enable-css-module-tsdeclaration) config, and then execute the build, Modern.js will generate type declaration files for all CSS Modules.
166
+ Modern.js supports generating accurate type declarations for CSS Modules, you only need to enable the [output.enableCssModuleTSDeclaration](/configure/app/output/enable-css-module-tsdeclaration) config, and then execute the build, Modern.js will generate type declaration files for all CSS Modules.
167
167
 
168
168
  ```ts
169
169
  export default {
@@ -42,7 +42,7 @@ In the filename, `[name]` represents the entry name corresponding to this file,
42
42
 
43
43
  ## Modify the Directory
44
44
 
45
- Builder provides some configs to modify the directory or filename, you can:
45
+ Modern.js provides some configs to modify the directory or filename, you can:
46
46
 
47
47
  - Modify the filename through [output.filename](/configure/app/output/filename).
48
48
  - Modify the output path of through [output.distPath](/configure/app/output/dist-path).
@@ -205,4 +205,4 @@ In the above configuration, the `x-tt-env` request header is set for all routes,
205
205
 
206
206
  :::tip
207
207
  Headers set in routes will override headers set for entries.
208
- :::
208
+ :::
@@ -220,7 +220,7 @@ However, when a crawler visits the page, it might need to load all content and o
220
220
 
221
221
  Modern.js uses [isbot](https://www.npmjs.com/package/isbot) to determine if a request is from a crawler based on the `user-agent` header.
222
222
 
223
- import StreamSSRPerformance from '@site-docs/components/stream-ssr-performance';
223
+ import StreamSSRPerformance from '@site-docs-en/components/stream-ssr-performance';
224
224
 
225
225
  <StreamSSRPerformance />
226
226
 
@@ -462,8 +462,7 @@ For applications with higher performance requirements, prefetching can further e
462
462
 
463
463
  :::tip
464
464
 
465
- - This feature is currently only supported in Webpack projects and not in Rspack projects.
466
- - Data preloading currently only preloads data returned by the [Data Loader](/guides/basic-features/data/data-fetch) in SSR projects.
465
+ Data preloading currently only preloads data returned by the [Data Loader](/guides/basic-features/data/data-fetch) in SSR projects.
467
466
 
468
467
  :::
469
468
 
@@ -587,4 +586,4 @@ Additionally, when using conventional routing, make sure to use the API from `@m
587
586
  If you must directly use the React Router package's API (e.g., route behavior wrapped in a unified npm package), you can set [`source.alias`](/configure/app/source/alias) to point `react-router` and `react-router-dom` to the project's dependencies, avoiding the issue of two versions of React Router.
588
587
  :::
589
588
 
590
- import Motivation from '@site-docs/components/convention-routing-motivation';
589
+ import Motivation from '@site-docs-en/components/convention-routing-motivation';
@@ -76,7 +76,7 @@ console.log(largeImage); // "/static/largeImage.6c12aba3.png"
76
76
  console.log(smallImage); // "data:image/png;base64,iVBORw0KGgo..."
77
77
  ```
78
78
 
79
- For a more detailed introduction to asset inlining, please refer to the [Static Asset Inlining](/guides/advanced-features/inline-assets) chapter.
79
+ For a more detailed introduction to asset inlining, please refer to the [Static Asset Inlining](/guides/advanced-features/page-performance/inline-assets) chapter.
80
80
 
81
81
  ## Output Files
82
82
 
@@ -4,7 +4,7 @@ sidebar_position: 2
4
4
 
5
5
  # Build Engine
6
6
 
7
- Modern.js internally encapsulates its own build tool (Modern.js Builder) based on [Rsbuild](https://rsbuild.dev/), and supports seamless switching between Webpack and Rspack bundlers.
7
+ Modern.js internally encapsulates [Rsbuild](https://rsbuild.dev/), and supports seamless switching between Webpack and Rspack bundlers.
8
8
 
9
9
  ::: tip What is Rsbuild?
10
10
  Rsbuild is a build tool based on Rspack. It is an enhanced Rspack CLI, easy-to-use, and ready-to-use out of the box.