@modern-js/main-doc 2.67.5 → 2.67.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (208) hide show
  1. package/docs/en/apis/app/hooks/server/server.mdx +10 -0
  2. package/docs/en/apis/app/hooks/src/routes.mdx +3 -73
  3. package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +30 -0
  4. package/docs/en/components/enable-bff.mdx +1 -27
  5. package/docs/en/components/rsbuild-config-tooltip.mdx +2 -2
  6. package/docs/en/components/tech-stack-node-framework.mdx +1 -1
  7. package/docs/en/configure/app/dev/asset-prefix.mdx +2 -3
  8. package/docs/en/configure/app/dev/client.mdx +2 -3
  9. package/docs/en/configure/app/dev/hmr.mdx +2 -3
  10. package/docs/en/configure/app/dev/live-reload.mdx +2 -3
  11. package/docs/en/configure/app/dev/progress-bar.mdx +2 -3
  12. package/docs/en/configure/app/dev/setup-middlewares.mdx +2 -3
  13. package/docs/en/configure/app/dev/watch-files.mdx +2 -3
  14. package/docs/en/configure/app/dev/write-to-disk.mdx +2 -3
  15. package/docs/en/configure/app/html/app-icon.mdx +2 -3
  16. package/docs/en/configure/app/html/crossorigin.mdx +2 -3
  17. package/docs/en/configure/app/html/favicon.mdx +2 -3
  18. package/docs/en/configure/app/html/inject.mdx +2 -3
  19. package/docs/en/configure/app/html/meta.mdx +2 -3
  20. package/docs/en/configure/app/html/mount-id.mdx +2 -3
  21. package/docs/en/configure/app/html/output-structure.mdx +2 -3
  22. package/docs/en/configure/app/html/script-loading.mdx +2 -3
  23. package/docs/en/configure/app/html/tags.mdx +2 -3
  24. package/docs/en/configure/app/html/template-parameters.mdx +2 -3
  25. package/docs/en/configure/app/html/template.mdx +2 -3
  26. package/docs/en/configure/app/html/title.mdx +2 -3
  27. package/docs/en/configure/app/output/asset-prefix.mdx +2 -3
  28. package/docs/en/configure/app/output/charset.mdx +2 -3
  29. package/docs/en/configure/app/output/copy.mdx +2 -3
  30. package/docs/en/configure/app/output/css-modules.mdx +2 -3
  31. package/docs/en/configure/app/output/data-uri-limit.mdx +2 -3
  32. package/docs/en/configure/app/output/dist-path.mdx +2 -4
  33. package/docs/en/configure/app/output/externals.mdx +2 -3
  34. package/docs/en/configure/app/output/filename-hash.mdx +2 -3
  35. package/docs/en/configure/app/output/filename.mdx +2 -3
  36. package/docs/en/configure/app/output/inject-styles.mdx +2 -3
  37. package/docs/en/configure/app/output/inline-scripts.mdx +2 -3
  38. package/docs/en/configure/app/output/inline-styles.mdx +2 -3
  39. package/docs/en/configure/app/output/legal-comments.mdx +2 -3
  40. package/docs/en/configure/app/output/minify.mdx +2 -3
  41. package/docs/en/configure/app/output/override-browserslist.mdx +2 -3
  42. package/docs/en/configure/app/output/polyfill.mdx +2 -3
  43. package/docs/en/configure/app/output/source-map.mdx +2 -3
  44. package/docs/en/configure/app/performance/build-cache.mdx +2 -3
  45. package/docs/en/configure/app/performance/bundle-analyze.mdx +2 -3
  46. package/docs/en/configure/app/performance/chunk-split.mdx +2 -3
  47. package/docs/en/configure/app/performance/dns-prefetch.mdx +2 -3
  48. package/docs/en/configure/app/performance/preconnect.mdx +2 -3
  49. package/docs/en/configure/app/performance/prefetch.mdx +2 -3
  50. package/docs/en/configure/app/performance/preload.mdx +2 -3
  51. package/docs/en/configure/app/performance/print-file-size.mdx +2 -3
  52. package/docs/en/configure/app/performance/profile.mdx +2 -3
  53. package/docs/en/configure/app/performance/remove-console.mdx +2 -3
  54. package/docs/en/configure/app/performance/remove-moment-locale.mdx +2 -3
  55. package/docs/en/configure/app/performance/transform-lodash.mdx +4 -1
  56. package/docs/en/configure/app/security/nonce.mdx +2 -3
  57. package/docs/en/configure/app/security/sri.mdx +0 -1
  58. package/docs/en/configure/app/server/port.mdx +2 -3
  59. package/docs/en/configure/app/source/alias-strategy.mdx +2 -3
  60. package/docs/en/configure/app/source/alias.mdx +2 -3
  61. package/docs/en/configure/app/source/decorators.mdx +2 -3
  62. package/docs/en/configure/app/source/define.mdx +2 -3
  63. package/docs/en/configure/app/source/exclude.mdx +2 -3
  64. package/docs/en/configure/app/source/include.mdx +2 -3
  65. package/docs/en/configure/app/source/module-scopes.mdx +4 -1
  66. package/docs/en/configure/app/source/pre-entry.mdx +2 -3
  67. package/docs/en/configure/app/source/transform-import.mdx +2 -3
  68. package/docs/en/configure/app/tools/css-extract.mdx +2 -3
  69. package/docs/en/configure/app/tools/css-loader.mdx +2 -2
  70. package/docs/en/configure/app/tools/html-plugin.mdx +7 -3
  71. package/docs/en/configure/app/tools/lightningcss-loader.mdx +2 -3
  72. package/docs/en/configure/app/tools/postcss.mdx +2 -3
  73. package/docs/en/configure/app/tools/rspack.mdx +2 -3
  74. package/docs/en/configure/app/tools/style-loader.mdx +2 -3
  75. package/docs/en/configure/app/tools/swc.mdx +1 -1
  76. package/docs/en/configure/app/tools/terser.mdx +4 -2
  77. package/docs/en/configure/app/tools/ts-loader.mdx +4 -1
  78. package/docs/en/configure/app/tools/webpack-chain.mdx +4 -1
  79. package/docs/en/configure/app/tools/webpack.mdx +4 -1
  80. package/docs/en/guides/advanced-features/_meta.json +0 -1
  81. package/docs/en/guides/advanced-features/bff/extend-server.mdx +33 -82
  82. package/docs/en/guides/advanced-features/bff/frameworks.mdx +12 -68
  83. package/docs/en/guides/advanced-features/page-performance/_meta.json +1 -1
  84. package/docs/en/guides/advanced-features/page-performance/react-compiler.mdx +44 -0
  85. package/docs/en/guides/advanced-features/web-server.mdx +223 -20
  86. package/docs/en/guides/basic-features/data/data-cache.mdx +1 -1
  87. package/docs/en/guides/basic-features/deploy.mdx +3 -3
  88. package/docs/en/guides/basic-features/output-files.mdx +0 -28
  89. package/docs/en/guides/basic-features/render/ssr.mdx +1 -1
  90. package/docs/en/guides/basic-features/render/streaming-ssr.mdx +2 -2
  91. package/docs/en/guides/basic-features/routes.mdx +72 -0
  92. package/docs/en/guides/basic-features/static-assets/wasm-assets.mdx +1 -1
  93. package/docs/en/guides/topic-detail/module-federation/deploy.mdx +83 -7
  94. package/docs/en/guides/topic-detail/module-federation/usage.mdx +2 -4
  95. package/docs/en/plugin/cli-plugins/api.mdx +1 -1
  96. package/docs/en/tutorials/first-app/c04-routes.mdx +4 -2
  97. package/docs/en/tutorials/first-app/c05-loader.mdx +4 -1
  98. package/docs/zh/apis/app/hooks/server/server.mdx +10 -0
  99. package/docs/zh/apis/app/hooks/src/routes.mdx +3 -3
  100. package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +31 -0
  101. package/docs/zh/components/enable-bff.mdx +2 -27
  102. package/docs/zh/components/rsbuild-config-tooltip.mdx +2 -2
  103. package/docs/zh/components/tech-stack-node-framework.mdx +1 -1
  104. package/docs/zh/configure/app/dev/asset-prefix.mdx +2 -3
  105. package/docs/zh/configure/app/dev/client.mdx +2 -3
  106. package/docs/zh/configure/app/dev/hmr.mdx +2 -3
  107. package/docs/zh/configure/app/dev/live-reload.mdx +2 -3
  108. package/docs/zh/configure/app/dev/progress-bar.mdx +2 -3
  109. package/docs/zh/configure/app/dev/setup-middlewares.mdx +2 -3
  110. package/docs/zh/configure/app/dev/watch-files.mdx +2 -3
  111. package/docs/zh/configure/app/dev/write-to-disk.mdx +2 -3
  112. package/docs/zh/configure/app/html/app-icon.mdx +2 -3
  113. package/docs/zh/configure/app/html/crossorigin.mdx +2 -3
  114. package/docs/zh/configure/app/html/favicon.mdx +2 -3
  115. package/docs/zh/configure/app/html/inject.mdx +2 -3
  116. package/docs/zh/configure/app/html/meta.mdx +2 -3
  117. package/docs/zh/configure/app/html/mount-id.mdx +2 -3
  118. package/docs/zh/configure/app/html/output-structure.mdx +2 -3
  119. package/docs/zh/configure/app/html/script-loading.mdx +2 -3
  120. package/docs/zh/configure/app/html/tags.mdx +2 -3
  121. package/docs/zh/configure/app/html/template-parameters.mdx +2 -3
  122. package/docs/zh/configure/app/html/template.mdx +2 -3
  123. package/docs/zh/configure/app/html/title.mdx +2 -3
  124. package/docs/zh/configure/app/output/asset-prefix.mdx +2 -3
  125. package/docs/zh/configure/app/output/charset.mdx +2 -3
  126. package/docs/zh/configure/app/output/copy.mdx +2 -3
  127. package/docs/zh/configure/app/output/css-modules.mdx +2 -3
  128. package/docs/zh/configure/app/output/data-uri-limit.mdx +2 -3
  129. package/docs/zh/configure/app/output/dist-path.mdx +2 -4
  130. package/docs/zh/configure/app/output/externals.mdx +2 -3
  131. package/docs/zh/configure/app/output/filename-hash.mdx +2 -3
  132. package/docs/zh/configure/app/output/filename.mdx +2 -3
  133. package/docs/zh/configure/app/output/inject-styles.mdx +2 -3
  134. package/docs/zh/configure/app/output/inline-scripts.mdx +2 -3
  135. package/docs/zh/configure/app/output/inline-styles.mdx +2 -3
  136. package/docs/zh/configure/app/output/legal-comments.mdx +2 -3
  137. package/docs/zh/configure/app/output/minify.mdx +2 -3
  138. package/docs/zh/configure/app/output/override-browserslist.mdx +2 -3
  139. package/docs/zh/configure/app/output/polyfill.mdx +2 -3
  140. package/docs/zh/configure/app/output/source-map.mdx +2 -3
  141. package/docs/zh/configure/app/performance/build-cache.mdx +2 -3
  142. package/docs/zh/configure/app/performance/bundle-analyze.mdx +2 -3
  143. package/docs/zh/configure/app/performance/chunk-split.mdx +2 -3
  144. package/docs/zh/configure/app/performance/dns-prefetch.mdx +2 -3
  145. package/docs/zh/configure/app/performance/preconnect.mdx +2 -3
  146. package/docs/zh/configure/app/performance/prefetch.mdx +2 -3
  147. package/docs/zh/configure/app/performance/preload.mdx +2 -3
  148. package/docs/zh/configure/app/performance/print-file-size.mdx +2 -3
  149. package/docs/zh/configure/app/performance/profile.mdx +2 -3
  150. package/docs/zh/configure/app/performance/remove-console.mdx +2 -3
  151. package/docs/zh/configure/app/performance/remove-moment-locale.mdx +2 -3
  152. package/docs/zh/configure/app/performance/transform-lodash.mdx +4 -1
  153. package/docs/zh/configure/app/security/nonce.mdx +2 -3
  154. package/docs/zh/configure/app/security/sri.mdx +0 -1
  155. package/docs/zh/configure/app/server/port.mdx +2 -3
  156. package/docs/zh/configure/app/source/alias-strategy.mdx +2 -3
  157. package/docs/zh/configure/app/source/alias.mdx +2 -3
  158. package/docs/zh/configure/app/source/decorators.mdx +2 -3
  159. package/docs/zh/configure/app/source/define.mdx +2 -3
  160. package/docs/zh/configure/app/source/exclude.mdx +2 -3
  161. package/docs/zh/configure/app/source/include.mdx +2 -3
  162. package/docs/zh/configure/app/source/module-scopes.mdx +4 -1
  163. package/docs/zh/configure/app/source/pre-entry.mdx +2 -3
  164. package/docs/zh/configure/app/source/transform-import.mdx +2 -3
  165. package/docs/zh/configure/app/tools/css-extract.mdx +2 -3
  166. package/docs/zh/configure/app/tools/css-loader.mdx +2 -3
  167. package/docs/zh/configure/app/tools/html-plugin.mdx +6 -3
  168. package/docs/zh/configure/app/tools/lightningcss-loader.mdx +2 -3
  169. package/docs/zh/configure/app/tools/postcss.mdx +2 -3
  170. package/docs/zh/configure/app/tools/rspack.mdx +2 -3
  171. package/docs/zh/configure/app/tools/style-loader.mdx +2 -3
  172. package/docs/zh/configure/app/tools/swc.mdx +1 -1
  173. package/docs/zh/configure/app/tools/terser.mdx +4 -2
  174. package/docs/zh/configure/app/tools/ts-loader.mdx +4 -1
  175. package/docs/zh/configure/app/tools/webpack-chain.mdx +4 -1
  176. package/docs/zh/configure/app/tools/webpack.mdx +4 -1
  177. package/docs/zh/guides/advanced-features/_meta.json +0 -1
  178. package/docs/zh/guides/advanced-features/bff/extend-server.mdx +28 -76
  179. package/docs/zh/guides/advanced-features/bff/frameworks.mdx +6 -66
  180. package/docs/zh/guides/advanced-features/page-performance/_meta.json +1 -1
  181. package/docs/zh/guides/advanced-features/page-performance/react-compiler.mdx +44 -0
  182. package/docs/zh/guides/advanced-features/web-server.mdx +221 -24
  183. package/docs/zh/guides/basic-features/data/data-cache.mdx +1 -1
  184. package/docs/zh/guides/basic-features/deploy.mdx +4 -3
  185. package/docs/zh/guides/basic-features/output-files.mdx +0 -28
  186. package/docs/zh/guides/basic-features/render/ssr.mdx +1 -1
  187. package/docs/zh/guides/basic-features/render/streaming-ssr.mdx +1 -1
  188. package/docs/zh/guides/basic-features/static-assets/wasm-assets.mdx +1 -1
  189. package/docs/zh/guides/topic-detail/module-federation/deploy.mdx +83 -7
  190. package/docs/zh/guides/topic-detail/module-federation/usage.mdx +2 -4
  191. package/docs/zh/plugin/cli-plugins/api.mdx +1 -1
  192. package/docs/zh/tutorials/first-app/c04-routes.mdx +4 -2
  193. package/docs/zh/tutorials/first-app/c05-loader.mdx +4 -1
  194. package/package.json +7 -4
  195. package/rspress.config.ts +16 -1
  196. package/src/components/RsbuildLink/index.tsx +2 -2
  197. package/src/index.ts +1 -5
  198. package/src/pages/index.tsx +3 -3
  199. package/docs/en/apis/app/hooks/api/middleware.mdx +0 -11
  200. package/docs/en/apis/app/runtime/bff/hook.mdx +0 -44
  201. package/docs/en/apis/app/runtime/bff/use-context.mdx +0 -38
  202. package/docs/en/configure/app/bff/enable-handle-web.mdx +0 -24
  203. package/docs/en/guides/advanced-features/custom-server.mdx +0 -218
  204. package/docs/zh/apis/app/hooks/api/middleware.mdx +0 -11
  205. package/docs/zh/apis/app/runtime/bff/hook.mdx +0 -44
  206. package/docs/zh/apis/app/runtime/bff/use-context.mdx +0 -38
  207. package/docs/zh/configure/app/bff/enable-handle-web.mdx +0 -24
  208. package/docs/zh/guides/advanced-features/custom-server.mdx +0 -216
@@ -166,7 +166,7 @@ const getComplexStatistics = cache(
166
166
  }
167
167
  );
168
168
 
169
- revalidateTag('dashboard-stats'); // Invalidates the cache for both getDashboardStats and getComplexStatistics functions
169
+ revalidateTag('dashboard'); // Invalidates the cache for both getDashboardStats and getComplexStatistics functions
170
170
  ```
171
171
 
172
172
 
@@ -285,6 +285,7 @@ Add the following script to `packages/app/package.json` to run `build` command o
285
285
  ```
286
286
 
287
287
  Add the following content to the `packages/app/vercel.json` file:
288
+
288
289
  ```json title="vercel.json"
289
290
  {
290
291
  "buildCommand": "npm run deploy",
@@ -298,7 +299,7 @@ Just submit your code and deploy it using the Vercel platform.
298
299
 
299
300
  If you're creating a GitHub Pages for a repository without a custom domain, the page URL will follow this format: `http://<username>.github.io/<repository-name>`. Therefore, you need to add the following configuration in `modern.config.ts`:
300
301
 
301
- ```
302
+ ```ts
302
303
  import { defineConfig } from '@modern-js/app-tools';
303
304
 
304
305
  export default defineConfig({
@@ -331,7 +332,6 @@ For branch deployment, follow these steps:
331
332
  :::info
332
333
  1. Running `MODERNJS_DEPLOY=ghPages modern deploy` will build the production output for GitHub in the .output directory.
333
334
  2. You can refer to the [project](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/modern-js-deploy-csr)
334
-
335
335
  :::
336
336
 
337
337
  For GitHub Actions deployment, select Settings > Pages > Source > GitHub Actions, and add a workflow file to the project. You can refer to the [example](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/modern-js-deploy-csr).
@@ -407,7 +407,7 @@ Nginx is a high-performance HTTP and reverse proxy server that can handle static
407
407
 
408
408
  If your project is a purely front-end project, you can also deploy the application through Nginx. Here is an example of an Nginx configuration to demonstrate how to host the output of a purely front-end project.
409
409
 
410
- ```conf title="nginx.conf"
410
+ ```nginx title="nginx.conf"
411
411
  # user [user] [group];
412
412
  worker_processes 1;
413
413
 
@@ -96,34 +96,6 @@ dist
96
96
  └── qux.[hash].mp4
97
97
  ```
98
98
 
99
- ## Node.js Output Directory
100
-
101
- When you enable SSR or SSG features in Modern.js, Modern.js will generate a Node.js bundle after the build and output it to the `bundles` directory.
102
-
103
- ```bash
104
- dist
105
- ├── bundles
106
- │ └── [name].js
107
- ├── static
108
- └── html
109
- ```
110
-
111
- Node.js files usually only contain JS files, no HTML or CSS. Also, JS file names will not contain hash.
112
-
113
- You can modify the output path of Node.js files through the [output.distPath.server](/configure/app/output/dist-path) config.
114
-
115
- For example, output Node.js files to the `server` directory:
116
-
117
- ```ts
118
- export default {
119
- output: {
120
- distPath: {
121
- server: 'server',
122
- },
123
- },
124
- };
125
- ```
126
-
127
99
  ## Flatten the Directory
128
100
 
129
101
  Sometimes you don't want the dist directory to have too many levels, you can set the directory to an empty string to flatten the generated directory.
@@ -217,7 +217,7 @@ document.addEventListener('load', () => {
217
217
  export const doSomething = () => {}
218
218
  ```
219
219
 
220
- Directly referencing this in a component will cause CSR to throw errors, even if you use environment variables to conditionally load the code. The side effects in the dependency will still execute.
220
+ Directly referencing this in a component will cause SSR to throw errors, even if you use environment variables to conditionally load the code. The side effects in the dependency will still execute.
221
221
 
222
222
  ```tsx title="routes/page.tsx"
223
223
  import { doSomething } from 'packageA';
@@ -68,7 +68,7 @@ Here, `user` is a Promise object representing asynchronously fetched data, proce
68
68
  Additionally, `defer` can receive both asynchronous and synchronous data. In the example below, short-duration requests are returned using object data, while longer-duration requests are returned using a Promise:
69
69
 
70
70
  ```ts title="user/[id]/page.data.ts"
71
- export const loader = ({ params }: LoaderFunctionArgs) => {
71
+ export const loader = async ({ params }: LoaderFunctionArgs) => {
72
72
  const userId = params.id;
73
73
 
74
74
  const user = new Promise<User>(resolve => {
@@ -227,4 +227,4 @@ import StreamSSRPerformance from '@site-docs-en/components/stream-ssr-performanc
227
227
  ## Related Documentation
228
228
 
229
229
  1. [Deferred Data](https://reactrouter.com/en/main/guides/deferred)
230
- 2. [New Suspense SSR Architecture in React 18](https://github.com/reactwg/react-18/discussions/37)
230
+ 2. [New Suspense SSR Architecture in React 18](https://github.com/reactwg/react-18/discussions/37)
@@ -490,6 +490,76 @@ import Motivation from '@site-docs-en/components/convention-routing-motivation';
490
490
 
491
491
  <Motivation />
492
492
 
493
+ ## Upgrading to React Router v7
494
+
495
+ React Router v7 reduces bundle size (approximately 15% smaller) compared to React Router v6, provides a more efficient route matching algorithm, and offers better support for React 19 and TypeScript. There are very few breaking changes compared to React Router v6, and Modern.js has made both versions compatible, allowing for a seamless upgrade by simply installing and registering the appropriate plugin.
496
+
497
+ :::info
498
+
499
+ For more changes from React Router v6 to React Router v7, check the [documentation](https://reactrouter.com/upgrading/v6#upgrade-to-v7)
500
+
501
+ :::
502
+
503
+ ### Requirements
504
+
505
+ React Router v7 has certain environment requirements:
506
+
507
+ - Node.js 20+
508
+ - React 18+
509
+ - React DOM 18+
510
+
511
+ ### Install the Plugin
512
+
513
+ First, install the Modern.js React Router v7 plugin:
514
+
515
+ ```bash
516
+ pnpm add @modern-js/plugin-router-v7
517
+ ```
518
+
519
+ ### Configure the Plugin
520
+
521
+ Register the plugin in `modern.config.ts`:
522
+
523
+ ```ts title="modern.config.ts"
524
+ import { routerPlugin } from '@modern-js/plugin-router-v7';
525
+
526
+ export default {
527
+ runtime: {
528
+ router: true,
529
+ },
530
+ plugins: [routerPlugin()],
531
+ };
532
+ ```
533
+
534
+ ### Code Changes
535
+
536
+ In React Router v7, you no longer need to use the `defer` API; you can directly return data in the data loader:
537
+
538
+ ```ts title="routes/page.data.ts"
539
+ import { defer } from '@modern-js/runtime/router';
540
+
541
+ export const loader = async ({ params }) => {
542
+ // Recommended v7 style
543
+ const user = fetchUser(params.id)
544
+ return { user };
545
+
546
+ // v6 style, still compatible with Modern.js
547
+ return defer({ data: 'hello' });
548
+ };
549
+ ```
550
+
551
+ React Router v7 has also deprecated the `json` API:
552
+
553
+ ```ts title="routes/page.data.ts"
554
+ export const loader = async ({ params }) => {
555
+ // Recommended v7 style
556
+ return { data: 'hello' };
557
+
558
+ // v6 style, still compatible with Modern.js
559
+ return json({ data: 'hello' });
560
+ };
561
+ ```
562
+
493
563
  ## FAQ
494
564
 
495
565
  1. Why there is `@modern-js/runtime/router` to re-export React Router API
@@ -535,3 +605,5 @@ export const init = () => {
535
605
  // initialization logic
536
606
  };
537
607
  ```
608
+
609
+
@@ -12,7 +12,7 @@ WebAssembly (Wasm) is a portable, high-performance binary format designed to exe
12
12
 
13
13
  ## Import
14
14
 
15
- You can import a WebAssembly module directly in a JavaScript file:
15
+ You can import a WebAssembly module via named import in a JavaScript file:
16
16
 
17
17
  ```js title="index.js"
18
18
  import { add } from './add.wasm';
@@ -1,8 +1,17 @@
1
1
  # Deployment
2
2
 
3
- Typically, deploying a Module Federation application requires adjusting the remote module address on the consumer side to its online address.
3
+ In general, when deploying a Module Federation application, there are two key points to consider:
4
4
 
5
- For example, if the producer is deployed to the domain `https://my-remote-module`, you can modify the consumer's `module-federation.config.ts` file as follows:
5
+ 1. Ensure that the remote module addresses in the consumer's configuration file are correct, and that the consumer can correctly access the producer's `manifest` file.
6
+ 2. Ensure that all resources in the producer's `manifest` file can be accessed correctly.
7
+
8
+ We recommend using Modern.js's [Node Server](/guides/basic-features/deploy.html#using-modernjs-built-in-nodejs-server) to deploy Module Federation applications for an out-of-the-box experience.
9
+
10
+ ## Consumer
11
+
12
+ For the consumer of Module Federation, its connection with the producer is the remote module address in the configuration file.
13
+
14
+ For example, if the producer is deployed under the domain `https://my-remote-module`, the developer needs to modify the consumer's configuration file:
6
15
 
7
16
  ```ts title="module-federation.config.ts"
8
17
  import { createModuleFederationConfig } from '@module-federation/modern-js';
@@ -10,7 +19,7 @@ import { createModuleFederationConfig } from '@module-federation/modern-js';
10
19
  export default createModuleFederationConfig({
11
20
  name: 'host',
12
21
  remotes: {
13
- remote: 'remote@http://my-remote-module/mf-manifest.json',
22
+ remote: 'remote@https://my-remote-module/static/mf-manifest.json',
14
23
  },
15
24
  shared: {
16
25
  react: { singleton: true },
@@ -19,10 +28,77 @@ export default createModuleFederationConfig({
19
28
  });
20
29
  ```
21
30
 
22
- At this point, the consumer will load the `manifest` configuration file of the `remote` module in the production environment.
31
+ At this point, the consumer will load the `manifest` configuration file of the remote module production environment.
32
+
33
+ :::note
34
+ In the above code, the address of the remote module is `/static/mf-manifest.json`, which is just an example using the default output path of Modern.js. In actual projects, developers need to configure according to the actual access path.
35
+ :::
36
+
37
+ ## Producer
38
+
39
+ For the producer of Module Federation, developers need to correctly configure the [`output.assetPrefix`](/configure/app/output/asset-prefix) configuration, which affects:
40
+
41
+ 1. The `publicPath` defined in `mf-manifest.json`, which determines the access path of other resources of the remote module.
42
+ 2. The access path of the `mf-manifest.json` file when hosted directly by the Modern.js server.
43
+
44
+ In the production environment, developers need to configure `output.assetPrefix` as the access path of the production environment. For example, if we deploy the producer under the domain `https://my-remote-module`, we need to configure `output.assetPrefix` as `https://my-remote-module`.
45
+
46
+ ```ts title="modern.config.ts"
47
+ import { defineConfig } from '@modern-js/app-tools';
48
+
49
+ export default defineConfig({
50
+ output: {
51
+ assetPrefix: 'https://my-remote-module',
52
+ },
53
+ });
54
+ ```
55
+
56
+ At this point, the `publicPath` defined in the producer's build output `mf-manifest.json` is `https://my-remote-module`, for example:
57
+
58
+ ```json
59
+ {
60
+ "id": "remote",
61
+ "name": "remote",
62
+ "metaData": {
63
+ "name": "remote",
64
+ "publicPath": "https://my-remote-module/"
65
+ },
66
+ "shared": [ /* xxx */ ],
67
+ "remotes": [],
68
+ "exposes": [ /* xxx */ ]
69
+ }
70
+ ```
71
+
72
+ When the consumer accesses the remote module, it will automatically prepend the `publicPath` to the resource path of the remote module.
73
+
74
+ This configuration will also affect the access path of the producer's `mf-manifest.json`. For example, if this value is set to `MyDomain/module-a`, the hosting path of `mf-manifest.json` becomes `MyDomain/module-a/static/mf-manifest.json`.
75
+
76
+ At this point, the consumer needs to configure the following address when configuring the remote module:
77
+
78
+ ```ts title="module-federation.config.ts"
79
+ import { createModuleFederationConfig } from '@module-federation/modern-js';
80
+
81
+ export default createModuleFederationConfig({
82
+ name: 'host',
83
+ remotes: {
84
+ remote: 'remote@MyDomain/module-a/static/mf-manifest.json',
85
+ },
86
+ });
87
+ ```
88
+
89
+ ## Local Deployment Verification
23
90
 
24
- ## Deployment via Platform
91
+ Modern.js provides the `modern deploy` command, which can easily generate products that can run in a Node.js environment.
25
92
 
26
- The above deployment method is merely the simplest practice. In real-world scenarios, there are many constraints, such as version management, release sequencing, and more. Within ByteDance, we have set up a deployment process for Module Federation applications on our deployment platform, which helps developers address these issues.
93
+ ```bash
94
+ modern deploy
95
+ ```
96
+
97
+ After executing the command, you can see the following output in the console:
98
+
99
+ ```bash
100
+ Static directory: .output/static
101
+ You can preview this build by node .output/index
102
+ ```
27
103
 
28
- We will continue to keep an eye on platforms with similar functionalities in the community and, in the future, enhance the documentation for deploying Modern.js + Module Federation on these types of platforms.
104
+ At this point, the developer only needs to run `node .output/index` to preview the effect locally. Whether it is a CSR or an SSR application, all Module Federation files can be accessed correctly.
@@ -190,8 +190,6 @@ If we want to simulate the production environment in local, but not configure `o
190
190
  import { appTools, defineConfig } from '@modern-js/app-tools';
191
191
  import { moduleFederationPlugin } from '@module-federation/modern-js';
192
192
 
193
- const isLocal = process.env.IS_LOCAL === 'true';
194
-
195
193
  // https://modernjs.dev/en/configure/app/usage
196
194
  export default defineConfig({
197
195
  server: {
@@ -204,7 +202,7 @@ export default defineConfig({
204
202
  // Now this configuration is only used in the local when you run modern serve command.
205
203
  // If you want to deploy the application to the platform, use your own domain name.
206
204
  // Module federation will automatically write it to mf-manifest.json, which influences consumer to fetch remoteEntry.js.
207
- assetPrefix: isLocal ? 'http://127.0.0.1:3051' : '/',
205
+ assetPrefix: 'http://127.0.0.1:3051',
208
206
  },
209
207
  plugins: [
210
208
  appTools({
@@ -215,7 +213,7 @@ export default defineConfig({
215
213
  });
216
214
  ```
217
215
 
218
- Now, in the producer, run `IS_LOCAL=true modern build && modern serve`, and in the consumer, run `modern build && modern serve` to simulate the production environment locally and access the remote modules.
216
+ Now, in the producer, run `modern build && modern serve`, and in the consumer, run `modern build && modern serve` to simulate the production environment locally and access the remote modules.
219
217
 
220
218
  You can refer to this example: [Modern.js & Module Federation Basic Example](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/module-federation/base).
221
219
 
@@ -324,7 +324,7 @@ Modify the server routing configuration.
324
324
  ```typescript
325
325
  api.modifyServerRoutes(routes => {
326
326
  // Add a new API route
327
- routes.concat({
327
+ routes.push({
328
328
  urlPath: '/api',
329
329
  isApi: true,
330
330
  entryPath: '',
@@ -118,10 +118,11 @@ import { Radio } from 'antd';
118
118
 
119
119
  Then modify the top of the UI to add a set of radio group:
120
120
 
121
- ```tsx {4-9}
121
+ ```tsx
122
122
  export default function Layout() {
123
123
  return (
124
124
  <div>
125
+ // [!code highlight:6]
125
126
  <div className="h-16 p-2 flex items-center justify-center">
126
127
  <Radio.Group onChange={handleSetList} value={currentList}>
127
128
  <Radio value="/">All</Radio>
@@ -146,8 +147,9 @@ import { Outlet, useLocation, useNavigate } from '@modern-js/runtime/router';
146
147
 
147
148
  Finally, add local state and related logic to the Layout component:
148
149
 
149
- ```tsx {2-9}
150
+ ```tsx
150
151
  export default function Layout() {
152
+ // [!code highlight:8]
151
153
  const navigate = useNavigate();
152
154
  const location = useLocation();
153
155
  const [currentList, setList] = useState(location.pathname || '/');
@@ -56,11 +56,13 @@ Data Loader doesn't just work for SSR. In CSR projects, Data Loader can also avo
56
56
 
57
57
  Modern.js also provides a hooks API called `useLoaderData`, we modify the exported component of `src/routes/page.tsx`:
58
58
 
59
- ```tsx {1,2,5,13}
59
+ ```tsx
60
+ // [!code highlight:2]
60
61
  import { useLoaderData } from '@modern-js/runtime/router';
61
62
  import type { LoaderData } from './page.data';
62
63
 
63
64
  function Index() {
65
+ // [!code highlight:1]
64
66
  const { data } = useLoaderData() as LoaderData;
65
67
 
66
68
  return (
@@ -68,6 +70,7 @@ function Index() {
68
70
  <Helmet>
69
71
  <title>All</title>
70
72
  </Helmet>
73
+ // [!code highlight:1]
71
74
  <List
72
75
  dataSource={data}
73
76
  renderItem={info => <Item key={info.name} info={info} />}
@@ -0,0 +1,10 @@
1
+ ---
2
+ title: modern.server.[tj]s
3
+ sidebar_position: 1
4
+ ---
5
+
6
+ # modern.server.[tj]s
7
+
8
+ 扩展 Modern.js Server 的文件,在此文件中可以给 Modern.js 工程启动的 Server 配置 [Middleware](/guides/advanced-features/web-server.html#middleware) 、 [RenderMiddleware](/guides/advanced-features/web-server.html#rendermiddleware) 或 [Plugin](/guides/advanced-features/web-server.html#plugin)。
9
+
10
+ 可以对请求和响应进行拦截处理,鉴权与角色、请求预处理、异常兜底等。也可在内置处理逻辑(包括路由匹配、资源寻址、头部注入、页面渲染,静态 Web 托管)插入特定的业务逻辑。
@@ -10,11 +10,11 @@ sidebar_position: 2
10
10
 
11
11
  任何在 `src/routes` 下的 `layout.[tj]sx` 和 `page.[tj]sx` 都会作为应用的路由:
12
12
 
13
- ```bash {3,4}
13
+ ```bash
14
14
  .
15
15
  └── routes
16
- ├── layout.tsx
17
- ├── page.tsx
16
+ ├── layout.tsx # [!code highlight]
17
+ ├── page.tsx # [!code highlight]
18
18
  └── user
19
19
  ├── layout.tsx
20
20
  └── page.tsx
@@ -0,0 +1,31 @@
1
+ ---
2
+ title: useHonoContext
3
+ ---
4
+ # useHonoContext
5
+
6
+ 用于在一体化 BFF 函数中获取 Hono 上下文。
7
+
8
+
9
+ ## 使用姿势
10
+
11
+ ```ts
12
+ import { useHonoContext } from '@modern-js/plugin-bff/hono';
13
+ ```
14
+
15
+ ## 函数签名
16
+
17
+ `function useHonoContext(): Context`
18
+
19
+ ## 示例
20
+
21
+ 开发者可以通过 `context` 获取更多的请求信息,例如设置响应头:
22
+
23
+ ```ts
24
+ import { useHonoContext } from '@modern-js/plugin-bff/hono';
25
+
26
+ export async function get() {
27
+ const c = useHonoContext();
28
+ c.res.headers.set('x-bff-api', 'true');
29
+ // ...
30
+ }
31
+ ```
@@ -9,40 +9,15 @@ import { PackageManagerTabs } from '@theme';
9
9
  ```bash
10
10
  ? 请选择你想要的操作 启用可选功能
11
11
  ? 请选择功能名称 启用「BFF」功能
12
- ? 请选择 BFF 类型 框架模式
13
12
  ```
14
13
 
15
- :::note
16
- 目前推荐使用框架模式创建 BFF,后续我们将会移除 BFF 类型的概念。
17
- :::
14
+ 3. 将下面的代码添加到 `modern.config.[tj]s` 中:
18
15
 
19
- 3. 根据选择的运行时框架,将下面的代码添加到 `modern.config.[tj]s` 中:
20
-
21
- import { Tabs, Tab as TabItem } from "@theme";
22
-
23
- <Tabs>
24
- <TabItem value="express" label="Express.js" default>
25
16
 
26
17
  ```ts title="modern.config.ts"
27
- import { expressPlugin } from '@modern-js/plugin-express';
28
18
  import { bffPlugin } from '@modern-js/plugin-bff';
29
19
 
30
20
  export default defineConfig({
31
- plugins: [expressPlugin(), bffPlugin()],
21
+ plugins: [bffPlugin()],
32
22
  });
33
23
  ```
34
-
35
- </TabItem>
36
- <TabItem value="koa" label="Koa.js">
37
-
38
- ```ts title="modern.config.ts"
39
- import { koaPlugin } from '@modern-js/plugin-koa';
40
- import { bffPlugin } from '@modern-js/plugin-bff';
41
-
42
- export default defineConfig({
43
- plugins: [koaPlugin(), bffPlugin()],
44
- });
45
- ```
46
-
47
- </TabItem>
48
- </Tabs>
@@ -1,5 +1,5 @@
1
- import RsbuildLInk from '@site/src/components/RsbuildLink';
1
+ import RsbuildLink from '@site/src/components/RsbuildLink';
2
2
 
3
3
  :::info
4
- 该配置项的使用方式与 Rsbuild 完全一致。详细信息请参考 <RsbuildLInk configName={frontmatter.configName}/>。
4
+ 该配置项的使用方式与 Rsbuild 完全一致。详细信息请参考 <RsbuildLink configName={props.configName}/>。
5
5
  :::
@@ -1 +1 @@
1
- Modern.js 支持 [Express.js](https://expressjs.com/) [Koa.js](https://koajs.com/) 作为可选的 BFF 运行时框架,请参考[「BFF - 运行时框架」](/guides/advanced-features/bff/frameworks.html)。
1
+ Modern.js Server 和 BFF 是以 [Hono.js](https://hono.dev/) 作为运行时框架,可以基于 Hono.js 生态扩展 Server,请参考 [自定义 Web Server](/guides/advanced-features/web-server.html)。
@@ -1,6 +1,5 @@
1
1
  ---
2
2
  title: assetPrefix
3
- configName: dev.assetPrefix
4
3
  ---
5
4
 
6
5
  # dev.assetPrefix
@@ -10,9 +9,9 @@ configName: dev.assetPrefix
10
9
 
11
10
  此配置项用于设置 **开发模式** 下的静态资源 URL 前缀。
12
11
 
13
- import RsbuildConig from '@site-docs/components/rsbuild-config-tooltip';
12
+ import RsbuildConfig from '@site-docs/components/rsbuild-config-tooltip';
14
13
 
15
- <RsbuildConig />
14
+ <RsbuildConfig configName="dev.assetPrefix" />
16
15
 
17
16
  :::warning
18
17
  请注意,该配置项仅适用于开发模式。在生产模式下,请使用 [output.assetPrefix](/configure/app/output/asset-prefix) 配置项进行设置。
@@ -1,6 +1,5 @@
1
1
  ---
2
2
  title: client
3
- configName: dev.client
4
3
  ---
5
4
 
6
5
  # dev.client
@@ -41,6 +40,6 @@ const defaultConfig = {
41
40
 
42
41
  配置 Modern.js 在开发过程中注入的 client 代码,可以用于设置热更新对应的 WebSocket URL。
43
42
 
44
- import RsbuildConig from '@site-docs/components/rsbuild-config-tooltip';
43
+ import RsbuildConfig from '@site-docs/components/rsbuild-config-tooltip';
45
44
 
46
- <RsbuildConig />
45
+ <RsbuildConfig configName="dev.client" />
@@ -1,6 +1,5 @@
1
1
  ---
2
2
  title: hmr
3
- configName: dev.hmr
4
3
  ---
5
4
 
6
5
  # dev.hmr
@@ -10,6 +9,6 @@ configName: dev.hmr
10
9
 
11
10
  是否开启 Hot Module Replacement 热更新能力。
12
11
 
13
- import RsbuildConig from '@site-docs/components/rsbuild-config-tooltip';
12
+ import RsbuildConfig from '@site-docs/components/rsbuild-config-tooltip';
14
13
 
15
- <RsbuildConig />
14
+ <RsbuildConfig configName="dev.hmr" />
@@ -1,6 +1,5 @@
1
1
  ---
2
2
  title: liveReload
3
- configName: dev.liveReload
4
3
  ---
5
4
 
6
5
  # dev.liveReload
@@ -10,6 +9,6 @@ configName: dev.liveReload
10
9
 
11
10
  是否在源文件变更时自动刷新页面。
12
11
 
13
- import RsbuildConig from '@site-docs/components/rsbuild-config-tooltip';
12
+ import RsbuildConfig from '@site-docs/components/rsbuild-config-tooltip';
14
13
 
15
- <RsbuildConig />
14
+ <RsbuildConfig configName="dev.liveReload" />
@@ -1,6 +1,5 @@
1
1
  ---
2
2
  title: progressBar
3
- configName: dev.progressBar
4
3
  ---
5
4
 
6
5
  # dev.progressBar
@@ -19,6 +18,6 @@ type ProgressBar =
19
18
 
20
19
  是否在编译过程中展示进度条。
21
20
 
22
- import RsbuildConig from '@site-docs/components/rsbuild-config-tooltip';
21
+ import RsbuildConfig from '@site-docs/components/rsbuild-config-tooltip';
23
22
 
24
- <RsbuildConig />
23
+ <RsbuildConfig configName="dev.progressBar" />
@@ -1,6 +1,5 @@
1
1
  ---
2
2
  title: setupMiddlewares
3
- configName: dev.setupMiddlewares
4
3
  ---
5
4
 
6
5
  # dev.setupMiddlewares
@@ -51,6 +50,6 @@ type SetupMiddlewares = Array<
51
50
 
52
51
  提供执行自定义函数和应用自定义中间件的能力。
53
52
 
54
- import RsbuildConig from '@site-docs/components/rsbuild-config-tooltip';
53
+ import RsbuildConfig from '@site-docs/components/rsbuild-config-tooltip';
55
54
 
56
- <RsbuildConig />
55
+ <RsbuildConfig configName="dev.setupMiddlewares" />
@@ -1,6 +1,5 @@
1
1
  ---
2
2
  title: watchFiles
3
- configName: dev.watchFiles
4
3
  ---
5
4
 
6
5
  # dev.watchFiles
@@ -27,6 +26,6 @@ type WatchFilesConfig = WatchFiles | WatchFiles[];
27
26
 
28
27
  监听指定文件和目录的变化。当文件发生变化时,可以触发页面的重新加载,或者触发 dev server 重新启动。
29
28
 
30
- import RsbuildConig from '@site-docs/components/rsbuild-config-tooltip';
29
+ import RsbuildConfig from '@site-docs/components/rsbuild-config-tooltip';
31
30
 
32
- <RsbuildConig />
31
+ <RsbuildConfig configName="dev.watchFiles" />
@@ -1,6 +1,5 @@
1
1
  ---
2
2
  title: writeToDisk
3
- configName: dev.writeToDisk
4
3
  ---
5
4
 
6
5
  # dev.writeToDisk
@@ -10,6 +9,6 @@ configName: dev.writeToDisk
10
9
 
11
10
  用于控制是否将开发环境的构建产物写入到磁盘上。
12
11
 
13
- import RsbuildConig from '@site-docs/components/rsbuild-config-tooltip';
12
+ import RsbuildConfig from '@site-docs/components/rsbuild-config-tooltip';
14
13
 
15
- <RsbuildConig />
14
+ <RsbuildConfig configName="dev.writeToDisk" />