@modern-js/main-doc 2.67.6 → 2.67.8

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 (112) hide show
  1. package/docs/en/apis/app/commands.mdx +3 -3
  2. package/docs/en/apis/app/hooks/src/routes.mdx +0 -70
  3. package/docs/en/community/blog/v2-release-note.mdx +2 -2
  4. package/docs/en/community/contributing-guide.mdx +1 -1
  5. package/docs/en/components/builder.mdx +1 -1
  6. package/docs/en/components/bundler.mdx +1 -1
  7. package/docs/en/components/rsbuild.mdx +1 -1
  8. package/docs/en/components/rspack.mdx +1 -1
  9. package/docs/en/components/rspackPrecautions.mdx +2 -2
  10. package/docs/en/configure/app/builder-plugins.mdx +1 -1
  11. package/docs/en/configure/app/output/assets-retry.mdx +1 -1
  12. package/docs/en/configure/app/output/copy.mdx +1 -1
  13. package/docs/en/configure/app/performance/build-cache.mdx +1 -1
  14. package/docs/en/configure/app/performance/transform-lodash.mdx +4 -1
  15. package/docs/en/configure/app/security/sri.mdx +1 -1
  16. package/docs/en/configure/app/source/exclude.mdx +2 -2
  17. package/docs/en/configure/app/source/include.mdx +1 -1
  18. package/docs/en/configure/app/source/module-scopes.mdx +4 -1
  19. package/docs/en/configure/app/source/transform-import.mdx +2 -2
  20. package/docs/en/configure/app/tools/babel.mdx +5 -5
  21. package/docs/en/configure/app/tools/bundler-chain.mdx +2 -2
  22. package/docs/en/configure/app/tools/css-extract.mdx +1 -1
  23. package/docs/en/configure/app/tools/dev-server.mdx +1 -1
  24. package/docs/en/configure/app/tools/lightningcss-loader.mdx +1 -1
  25. package/docs/en/configure/app/tools/rspack.mdx +1 -1
  26. package/docs/en/configure/app/tools/swc.mdx +3 -3
  27. package/docs/en/configure/app/tools/terser.mdx +4 -2
  28. package/docs/en/configure/app/tools/ts-loader.mdx +4 -1
  29. package/docs/en/configure/app/tools/webpack-chain.mdx +22 -19
  30. package/docs/en/configure/app/tools/webpack.mdx +4 -1
  31. package/docs/en/guides/advanced-features/build-performance.mdx +1 -1
  32. package/docs/en/guides/advanced-features/compatibility.mdx +1 -1
  33. package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +3 -3
  34. package/docs/en/guides/advanced-features/rspack-start.mdx +2 -2
  35. package/docs/en/guides/advanced-features/web-server.mdx +16 -4
  36. package/docs/en/guides/basic-features/css/css.mdx +4 -4
  37. package/docs/en/guides/basic-features/data/data-cache.mdx +1 -1
  38. package/docs/en/guides/basic-features/debug/rsdoctor.mdx +1 -1
  39. package/docs/en/guides/basic-features/render/ssr.mdx +1 -1
  40. package/docs/en/guides/basic-features/render/streaming-ssr.mdx +2 -2
  41. package/docs/en/guides/basic-features/routes.mdx +75 -3
  42. package/docs/en/guides/basic-features/static-assets/wasm-assets.mdx +1 -1
  43. package/docs/en/guides/basic-features/static-assets.mdx +1 -1
  44. package/docs/en/guides/concept/builder.mdx +3 -3
  45. package/docs/en/guides/concept/entries.mdx +1 -1
  46. package/docs/en/guides/get-started/tech-stack.mdx +3 -3
  47. package/docs/en/guides/topic-detail/module-federation/deploy.mdx +83 -7
  48. package/docs/en/guides/topic-detail/module-federation/usage.mdx +2 -4
  49. package/docs/en/guides/troubleshooting/builder.mdx +4 -5
  50. package/docs/en/plugin/cli-plugins/api.mdx +141 -135
  51. package/docs/en/plugin/introduction.mdx +27 -24
  52. package/docs/en/tutorials/examples/csr-auth.mdx +15 -198
  53. package/docs/zh/apis/app/commands.mdx +3 -3
  54. package/docs/zh/community/blog/v2-release-note.mdx +2 -2
  55. package/docs/zh/community/contributing-guide.mdx +1 -1
  56. package/docs/zh/components/builder.mdx +1 -1
  57. package/docs/zh/components/bundler.mdx +1 -2
  58. package/docs/zh/components/rsbuild.mdx +1 -1
  59. package/docs/zh/components/rspack.mdx +1 -1
  60. package/docs/zh/components/rspackPrecautions.mdx +2 -2
  61. package/docs/zh/configure/app/builder-plugins.mdx +1 -1
  62. package/docs/zh/configure/app/output/assets-retry.mdx +1 -1
  63. package/docs/zh/configure/app/output/copy.mdx +1 -1
  64. package/docs/zh/configure/app/performance/build-cache.mdx +1 -1
  65. package/docs/zh/configure/app/performance/transform-lodash.mdx +4 -1
  66. package/docs/zh/configure/app/security/sri.mdx +1 -1
  67. package/docs/zh/configure/app/source/exclude.mdx +2 -2
  68. package/docs/zh/configure/app/source/include.mdx +1 -1
  69. package/docs/zh/configure/app/source/module-scopes.mdx +4 -1
  70. package/docs/zh/configure/app/source/transform-import.mdx +2 -2
  71. package/docs/zh/configure/app/tools/babel.mdx +5 -6
  72. package/docs/zh/configure/app/tools/bundler-chain.mdx +2 -2
  73. package/docs/zh/configure/app/tools/css-extract.mdx +1 -1
  74. package/docs/zh/configure/app/tools/dev-server.mdx +1 -1
  75. package/docs/zh/configure/app/tools/lightningcss-loader.mdx +1 -1
  76. package/docs/zh/configure/app/tools/rspack.mdx +1 -1
  77. package/docs/zh/configure/app/tools/swc.mdx +3 -3
  78. package/docs/zh/configure/app/tools/terser.mdx +4 -2
  79. package/docs/zh/configure/app/tools/ts-loader.mdx +4 -1
  80. package/docs/zh/configure/app/tools/webpack-chain.mdx +23 -20
  81. package/docs/zh/configure/app/tools/webpack.mdx +4 -1
  82. package/docs/zh/guides/advanced-features/compatibility.mdx +1 -1
  83. package/docs/zh/guides/advanced-features/page-performance/optimize-bundle.mdx +2 -2
  84. package/docs/zh/guides/advanced-features/rspack-start.mdx +2 -2
  85. package/docs/zh/guides/advanced-features/web-server.mdx +17 -4
  86. package/docs/zh/guides/basic-features/css/css.mdx +4 -4
  87. package/docs/zh/guides/basic-features/data/data-cache.mdx +1 -1
  88. package/docs/zh/guides/basic-features/debug/rsdoctor.mdx +1 -1
  89. package/docs/zh/guides/basic-features/render/ssr.mdx +1 -1
  90. package/docs/zh/guides/basic-features/render/streaming-ssr.mdx +1 -1
  91. package/docs/zh/guides/basic-features/static-assets/wasm-assets.mdx +1 -1
  92. package/docs/zh/guides/basic-features/static-assets.mdx +2 -2
  93. package/docs/zh/guides/concept/builder.mdx +3 -3
  94. package/docs/zh/guides/concept/entries.mdx +1 -1
  95. package/docs/zh/guides/get-started/tech-stack.mdx +3 -3
  96. package/docs/zh/guides/topic-detail/module-federation/deploy.mdx +83 -7
  97. package/docs/zh/guides/topic-detail/module-federation/usage.mdx +2 -4
  98. package/docs/zh/guides/troubleshooting/builder.mdx +4 -5
  99. package/docs/zh/plugin/cli-plugins/api.mdx +123 -121
  100. package/docs/zh/plugin/introduction.mdx +18 -15
  101. package/docs/zh/tutorials/examples/csr-auth.mdx +15 -198
  102. package/package.json +6 -6
  103. package/rspress.config.ts +12 -1
  104. package/src/components/RsbuildLink/index.tsx +1 -1
  105. package/src/components/Sandpack/index.tsx +1 -11
  106. package/src/components/ShowcaseList/useShowcases.ts +1 -1
  107. package/src/sandbox/csr-auth/src/routes/Auth-tsx.txt +74 -0
  108. package/src/sandbox/csr-auth/src/routes/fakeAuth-ts.txt +16 -0
  109. package/src/sandbox/csr-auth/src/routes/layout-tsx.txt +21 -0
  110. package/src/sandbox/csr-auth/src/routes/login/page-tsx.txt +40 -0
  111. package/src/sandbox/csr-auth/src/routes/page-tsx.txt +17 -0
  112. package/src/sandbox/csr-auth/src/routes/protected/page-tsx.txt +11 -0
@@ -12,20 +12,20 @@ Modern.js has built-in popular community CSS preprocessors, including Less and S
12
12
 
13
13
  By default, you don't need to configure Less and Sass. If you have custom loader configuration requirements, you can set them up by configuring [tools.less](/configure/app/tools/less) and [tools.sass](/configure/app/tools/sass).
14
14
 
15
- You can also use Stylus in Modern.js by installing the Stylus plugin provided by Rsbuild. For usage, please refer to [Stylus Plugin](https://rsbuild.dev/plugins/list/plugin-stylus).
15
+ You can also use Stylus in Modern.js by installing the Stylus plugin provided by Rsbuild. For usage, please refer to [Stylus Plugin](https://rsbuild.rs/plugins/list/plugin-stylus).
16
16
 
17
17
  ## Using PostCSS
18
18
 
19
19
  Modern.js has built-in [PostCSS](https://postcss.org/) to transform CSS code.
20
20
 
21
- Please refer to [Rsbuild - Using PostCSS](https://rsbuild.dev/guide/basic/css-usage#using-postcss) for detailed usage.
21
+ Please refer to [Rsbuild - Using PostCSS](https://rsbuild.rs/guide/basic/css-usage#using-postcss) for detailed usage.
22
22
 
23
23
  ## Using Lightning CSS
24
24
 
25
25
  Modern.js supports using [Lightning CSS](https://lightningcss.dev/) to convert CSS code. This feature can be turned on by configuring [tools.lightningcssLoader](/configure/app/tools/lightningcss-loader).
26
26
 
27
- Please refer to [Rsbuild - Using Lightning CSS](https://rsbuild.dev/guide/basic/css-usage#lightning-css) for detailed usage.
27
+ Please refer to [Rsbuild - Using Lightning CSS](https://rsbuild.rs/guide/basic/css-usage#lightning-css) for detailed usage.
28
28
 
29
29
  ## Using Uno CSS
30
30
 
31
- Please read the [Rsbuild - Using UnoCSS](https://rsbuild.dev/zh/guide/basic/unocss) for detailed usage.
31
+ Please read the [Rsbuild - Using UnoCSS](https://rsbuild.rs/zh/guide/basic/unocss) for detailed usage.
@@ -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
 
@@ -54,4 +54,4 @@ RSDOCTOR=true npm run build
54
54
 
55
55
  ## Related Documentation
56
56
 
57
- For more information, please refer to the [Rsdoctor Website](https://rsdoctor.dev/).
57
+ For more information, please refer to the [Rsdoctor Website](https://rsdoctor.rs/).
@@ -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,13 +490,83 @@ 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
- 1. Why there is `@modern-js/runtime/router` to re-export React Router API
565
+ 1. Why is there `@modern-js/runtime/router` to re-export React Router API?
496
566
 
497
- Notice that all the code examples in the documentation use API exported from the `@modern-js/runtime/router` package instead of directly using the API exported from the React Router package. So, what is the difference?
567
+ Notice that all the code examples in the documentation uses APIs exported from the `@modern-js/runtime/router` package instead of directly using the API exported from the React Router package. So, what is the difference?
498
568
 
499
- The API exported from `@modern-js/runtime/router` is entirely consistent with the API from the React Router package. If you encounter issues while using an API, check the React Router documentation and issues first.
569
+ The API exported from `@modern-js/runtime/router` is the same as the API from the React Router package. If you encounter issues while using an API, check the React Router documentation and issues first.
500
570
 
501
571
  Additionally, when using conventional routing, make sure to use the API from `@modern-js/runtime/router` instead of directly using the React Router API. Modern.js internally installs React Router, and using the React Router API directly in your application may result in two versions of React Router being present, causing unexpected behavior.
502
572
 
@@ -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';
@@ -150,7 +150,7 @@ console.log(myFile); // "/static/myFile.6c12aba3.pdf"
150
150
 
151
151
  For more information about asset modules, please refer to:
152
152
 
153
- - [Rspack Documentation - Asset modules](https://www.rspack.dev/guide/asset-module.html#asset-modules)
153
+ - [Rspack Documentation - Asset modules](https://rspack.rs/guide/asset-module.html#asset-modules)
154
154
  - [webpack Documentation - Asset modules](https://webpack.js.org/guides/asset-modules/)
155
155
 
156
156
  ## Image Format
@@ -4,7 +4,7 @@ sidebar_position: 2
4
4
 
5
5
  # Build Engine
6
6
 
7
- Modern.js internally encapsulates [Rsbuild](https://rsbuild.dev/), and supports seamless switching between Webpack and Rspack bundlers.
7
+ Modern.js internally encapsulates [Rsbuild](https://rsbuild.rs/), 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.
@@ -25,7 +25,7 @@ From the building perspective, Modern.js can be divided into three-layers, from
25
25
 
26
26
  ## Build Documentation
27
27
 
28
- The documentation address of Rsbuild is: https://rsbuild.dev/
28
+ The documentation address of Rsbuild is: https://rsbuild.rs/
29
29
 
30
30
  In this documentation, you can learn about the detailed introduction of Rsbuild, and you can also find complete usage guides for various building capabilities.
31
31
 
@@ -42,4 +42,4 @@ In Modern.js, you can register Webpack plugins, Rspack plugins, or Rsbuild plugi
42
42
 
43
43
  Rsbuild provides rich build capabilities, including JavaScript compilation, CSS compilation, static assets processing, code hot update, code compression, TS type checking, and dozens of other capabilities.
44
44
 
45
- We recommend that you read [「Rsbuild - All Features」](https://rsbuild.dev/guide/start/features) to learn about all the features provided by Rsbuild.
45
+ We recommend that you read [「Rsbuild - All Features」](https://rsbuild.rs/guide/start/features) to learn about all the features provided by Rsbuild.
@@ -290,7 +290,7 @@ Note that even if SSR is used, React still needs to go through the hydration pha
290
290
 
291
291
  4. **What are the exceptions to generating multiple HTML files?**
292
292
 
293
- You can configure [html-rspack-plugin](https://rspack.dev/plugins/rspack/html-rspack-plugin#generate-multiple-html-files) to generate multiple HTML files for each entry, or let multiple entries share the same HTML file.
293
+ You can configure [html-rspack-plugin](https://rspack.rs/plugins/rspack/html-rspack-plugin#generate-multiple-html-files) to generate multiple HTML files for each entry, or let multiple entries share the same HTML file.
294
294
 
295
295
  5. **What is a Multi-Page Application (MPA)?**
296
296
 
@@ -12,7 +12,7 @@ In this document, you can learn about the main technology stack involved in the
12
12
 
13
13
  Modern.js uses [React 18](https://react.dev/) to build user interfaces and is also compatible with React 17.
14
14
 
15
- Rsbuild supports building Vue applications. If you need to use Vue, you can refer to ["Rsbuild - Vue"](https://rsbuild.dev/guide/framework/vue).
15
+ Rsbuild supports building Vue applications. If you need to use Vue, you can refer to ["Rsbuild - Vue"](https://rsbuild.rs/guide/framework/vue).
16
16
 
17
17
  ## Routing
18
18
 
@@ -38,7 +38,7 @@ We recommend using pnpm for faster installation speed.
38
38
 
39
39
  ## Bundler
40
40
 
41
- Modern.js uses [Webpack 5](https://webpack.js.org/) or [Rspack](https://www.rspack.dev/) to bundle your web applications.
41
+ Modern.js uses [Webpack 5](https://webpack.js.org/) or [Rspack](https://rspack.rs/) to bundle your web applications.
42
42
 
43
43
  The default bundler used is Webpack 5. You can refer to ["Using Rspack"](/en/guides/advanced-features/rspack-start) to switch to the faster Rspack.
44
44
 
@@ -69,7 +69,7 @@ Modern.js supports enabling ["Tailwind CSS"](/guides/basic-features/css/tailwind
69
69
  Modern.js supports three CSS preprocessors: [Sass](https://sass-lang.com/), [Less](https://lesscss.org/), and [Stylus](https://stylus-lang.com/):
70
70
 
71
71
  - Sass and Less are supported by default and ready to use.
72
- - Stylus is optional and can be used by referring to the ["Stylus Plugin"](https://rsbuild.dev/plugins/list/plugin-stylus).
72
+ - Stylus is optional and can be used by referring to the ["Stylus Plugin"](https://rsbuild.rs/plugins/list/plugin-stylus).
73
73
 
74
74
  ## CSS Modules
75
75
 
@@ -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
 
@@ -10,12 +10,11 @@ If you encounter any build-related issues, you can refer to the current document
10
10
 
11
11
  ### Rsbuild FAQ
12
12
 
13
- Modern.js is internally based on [Rsbuild](https://rsbuild.dev/) and encapsulates its own build tool, so you can directly refer to the FAQ document of Rsbuild:
14
-
15
- - [Rsbuild - Features FAQ](https://rsbuild.dev/guide/faq/features)
16
- - [Rsbuild - Exceptions FAQ](https://rsbuild.dev/guide/faq/exceptions)
17
- - [Rsbuild - HMR FAQ](https://rsbuild.dev/guide/faq/hmr)
13
+ Modern.js is internally based on [Rsbuild](https://rsbuild.rs/) and encapsulates its own build tool, so you can directly refer to the FAQ document of Rsbuild:
18
14
 
15
+ - [Rsbuild - Features FAQ](https://rsbuild.rs/guide/faq/features)
16
+ - [Rsbuild - Exceptions FAQ](https://rsbuild.rs/guide/faq/exceptions)
17
+ - [Rsbuild - HMR FAQ](https://rsbuild.rs/guide/faq/hmr)
19
18
 
20
19
  ---
21
20