@modern-js/app-tools 3.7.0 → 3.8.0

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 (306) hide show
  1. package/bin/modern-bundle-docs.js +7 -0
  2. package/dist/cjs/builder/generator/createBuilderProviderConfig.js +5 -1
  3. package/dist/cjs/bundleDocs.js +114 -0
  4. package/dist/cjs/commands/build.js +2 -1
  5. package/dist/cjs/commands/deploy.js +4 -2
  6. package/dist/cjs/commands/index.js +0 -4
  7. package/dist/cjs/config/default.js +2 -0
  8. package/dist/cjs/index.js +52 -14
  9. package/dist/cjs/plugins/analyze/index.js +2 -2
  10. package/dist/cjs/plugins/analyze/utils.js +3 -2
  11. package/dist/cjs/plugins/initialize/index.js +4 -3
  12. package/dist/cjs/plugins/serverBuild.js +3 -2
  13. package/dist/esm/builder/generator/createBuilderProviderConfig.mjs +5 -1
  14. package/dist/esm/bundleDocs.mjs +62 -0
  15. package/dist/esm/commands/build.mjs +2 -1
  16. package/dist/esm/commands/deploy.mjs +4 -2
  17. package/dist/esm/commands/index.mjs +0 -4
  18. package/dist/esm/config/default.mjs +2 -0
  19. package/dist/esm/index.mjs +15 -1
  20. package/dist/esm/plugins/analyze/index.mjs +2 -2
  21. package/dist/esm/plugins/analyze/utils.mjs +3 -2
  22. package/dist/esm/plugins/initialize/index.mjs +4 -3
  23. package/dist/esm/plugins/serverBuild.mjs +3 -2
  24. package/dist/esm-node/builder/generator/createBuilderProviderConfig.mjs +5 -1
  25. package/dist/esm-node/bundleDocs.mjs +63 -0
  26. package/dist/esm-node/commands/build.mjs +2 -1
  27. package/dist/esm-node/commands/deploy.mjs +4 -2
  28. package/dist/esm-node/commands/index.mjs +0 -4
  29. package/dist/esm-node/config/default.mjs +2 -0
  30. package/dist/esm-node/index.mjs +15 -1
  31. package/dist/esm-node/plugins/analyze/index.mjs +2 -2
  32. package/dist/esm-node/plugins/analyze/utils.mjs +3 -2
  33. package/dist/esm-node/plugins/initialize/index.mjs +4 -3
  34. package/dist/esm-node/plugins/serverBuild.mjs +3 -2
  35. package/dist/types/bundleDocs.d.ts +20 -0
  36. package/dist/types/commands/deploy.d.ts +2 -1
  37. package/dist/types/index.d.ts +4 -1
  38. package/dist/types/plugins/analyze/utils.d.ts +1 -1
  39. package/dist/types/types/config/dev.d.ts +6 -0
  40. package/docs/apis/app/commands.md +241 -0
  41. package/docs/apis/app/hooks/api/lambda.md +9 -0
  42. package/docs/apis/app/hooks/config/favicon.md +24 -0
  43. package/docs/apis/app/hooks/config/html.md +5 -0
  44. package/docs/apis/app/hooks/config/icon.md +24 -0
  45. package/docs/apis/app/hooks/config/mock.md +6 -0
  46. package/docs/apis/app/hooks/config/public.md +26 -0
  47. package/docs/apis/app/hooks/config/upload.md +50 -0
  48. package/docs/apis/app/hooks/modern-config.md +5 -0
  49. package/docs/apis/app/hooks/server/server.md +5 -0
  50. package/docs/apis/app/hooks/shared.md +3 -0
  51. package/docs/apis/app/hooks/src/app.md +30 -0
  52. package/docs/apis/app/hooks/src/entry.md +34 -0
  53. package/docs/apis/app/hooks/src/entry.server.md +51 -0
  54. package/docs/apis/app/hooks/src/modern.runtime.md +5 -0
  55. package/docs/apis/app/hooks/src/routes.md +86 -0
  56. package/docs/apis/app/hooks/src/server.md +3 -0
  57. package/docs/apis/app/runtime/bff/use-hono-context.md +27 -0
  58. package/docs/apis/app/runtime/core/create-root.md +19 -0
  59. package/docs/apis/app/runtime/core/render.md +39 -0
  60. package/docs/apis/app/runtime/core/runtime-context.md +156 -0
  61. package/docs/apis/app/runtime/router/router.md +280 -0
  62. package/docs/apis/app/runtime/ssr/no-ssr.md +35 -0
  63. package/docs/apis/app/runtime/ssr/renderStreaming.md +67 -0
  64. package/docs/apis/app/runtime/ssr/renderString.md +60 -0
  65. package/docs/apis/app/runtime/ssr/requestHandler.md +44 -0
  66. package/docs/apis/app/runtime/utility/css-in-js.md +40 -0
  67. package/docs/apis/app/runtime/utility/head.md +35 -0
  68. package/docs/apis/app/runtime/utility/loadable.md +82 -0
  69. package/docs/community/blog/2022-0708-updates.md +91 -0
  70. package/docs/community/blog/2022-0910-updates.md +76 -0
  71. package/docs/community/blog/overview.md +63 -0
  72. package/docs/community/blog/v2-release-note.md +238 -0
  73. package/docs/community/blog/v3-release-note.md +622 -0
  74. package/docs/community/contributing-guide.md +253 -0
  75. package/docs/community/releases.md +27 -0
  76. package/docs/community/showcase.md +34 -0
  77. package/docs/community/team.md +14 -0
  78. package/docs/configure/app/bff/cross-project.md +20 -0
  79. package/docs/configure/app/bff/prefix.md +29 -0
  80. package/docs/configure/app/builder-plugins.md +66 -0
  81. package/docs/configure/app/dev/asset-prefix.md +13 -0
  82. package/docs/configure/app/dev/before-start-url.md +17 -0
  83. package/docs/configure/app/dev/client.md +41 -0
  84. package/docs/configure/app/dev/hmr.md +10 -0
  85. package/docs/configure/app/dev/host.md +18 -0
  86. package/docs/configure/app/dev/https.md +77 -0
  87. package/docs/configure/app/dev/lazy-compilation.md +39 -0
  88. package/docs/configure/app/dev/live-reload.md +10 -0
  89. package/docs/configure/app/dev/mock-dir.md +31 -0
  90. package/docs/configure/app/dev/progress-bar.md +19 -0
  91. package/docs/configure/app/dev/server.md +124 -0
  92. package/docs/configure/app/dev/setup-middlewares.md +32 -0
  93. package/docs/configure/app/dev/start-url.md +48 -0
  94. package/docs/configure/app/dev/watch-files.md +27 -0
  95. package/docs/configure/app/dev/write-to-disk.md +10 -0
  96. package/docs/configure/app/experiments/source-build.md +31 -0
  97. package/docs/configure/app/html/app-icon.md +28 -0
  98. package/docs/configure/app/html/crossorigin.md +10 -0
  99. package/docs/configure/app/html/favicon.md +16 -0
  100. package/docs/configure/app/html/inject.md +10 -0
  101. package/docs/configure/app/html/meta.md +24 -0
  102. package/docs/configure/app/html/mount-id.md +10 -0
  103. package/docs/configure/app/html/output-structure.md +10 -0
  104. package/docs/configure/app/html/script-loading.md +10 -0
  105. package/docs/configure/app/html/tags.md +15 -0
  106. package/docs/configure/app/html/template-parameters.md +33 -0
  107. package/docs/configure/app/html/template.md +10 -0
  108. package/docs/configure/app/html/title.md +18 -0
  109. package/docs/configure/app/output/asset-prefix.md +11 -0
  110. package/docs/configure/app/output/assets-retry.md +77 -0
  111. package/docs/configure/app/output/charset.md +10 -0
  112. package/docs/configure/app/output/clean-dist-path.md +16 -0
  113. package/docs/configure/app/output/convert-to-rem.md +79 -0
  114. package/docs/configure/app/output/copy.md +10 -0
  115. package/docs/configure/app/output/css-modules.md +48 -0
  116. package/docs/configure/app/output/data-uri-limit.md +26 -0
  117. package/docs/configure/app/output/disable-css-module-extension.md +55 -0
  118. package/docs/configure/app/output/disable-inline-runtime-chunk.md +41 -0
  119. package/docs/configure/app/output/disable-svgr.md +16 -0
  120. package/docs/configure/app/output/disable-ts-checker.md +49 -0
  121. package/docs/configure/app/output/dist-path.md +43 -0
  122. package/docs/configure/app/output/enable-asset-manifest.md +36 -0
  123. package/docs/configure/app/output/enable-css-module-tsdeclaration.md +28 -0
  124. package/docs/configure/app/output/enable-inline-route-manifests.md +16 -0
  125. package/docs/configure/app/output/externals.md +20 -0
  126. package/docs/configure/app/output/filename-hash.md +10 -0
  127. package/docs/configure/app/output/filename.md +55 -0
  128. package/docs/configure/app/output/inject-styles.md +10 -0
  129. package/docs/configure/app/output/inline-scripts.md +29 -0
  130. package/docs/configure/app/output/inline-styles.md +29 -0
  131. package/docs/configure/app/output/legal-comments.md +18 -0
  132. package/docs/configure/app/output/minify.md +22 -0
  133. package/docs/configure/app/output/override-browserslist.md +22 -0
  134. package/docs/configure/app/output/polyfill.md +12 -0
  135. package/docs/configure/app/output/source-map.md +30 -0
  136. package/docs/configure/app/output/split-route-chunks.md +16 -0
  137. package/docs/configure/app/output/ssg.md +81 -0
  138. package/docs/configure/app/output/ssgByEntries.md +90 -0
  139. package/docs/configure/app/output/svg-default-export.md +30 -0
  140. package/docs/configure/app/output/temp-dir.md +20 -0
  141. package/docs/configure/app/performance/build-cache.md +39 -0
  142. package/docs/configure/app/performance/chunk-split.md +40 -0
  143. package/docs/configure/app/performance/dns-prefetch.md +15 -0
  144. package/docs/configure/app/performance/preconnect.md +16 -0
  145. package/docs/configure/app/performance/prefetch.md +21 -0
  146. package/docs/configure/app/performance/preload.md +23 -0
  147. package/docs/configure/app/performance/print-file-size.md +40 -0
  148. package/docs/configure/app/performance/profile.md +10 -0
  149. package/docs/configure/app/performance/remove-console.md +10 -0
  150. package/docs/configure/app/performance/remove-moment-locale.md +10 -0
  151. package/docs/configure/app/plugins.md +59 -0
  152. package/docs/configure/app/resolve/alias-strategy.md +10 -0
  153. package/docs/configure/app/resolve/alias.md +9 -0
  154. package/docs/configure/app/resolve/condition-names.md +13 -0
  155. package/docs/configure/app/resolve/dedupe.md +9 -0
  156. package/docs/configure/app/resolve/extensions.md +13 -0
  157. package/docs/configure/app/runtime/0-intro.md +58 -0
  158. package/docs/configure/app/runtime/plugins.md +58 -0
  159. package/docs/configure/app/runtime/router.md +35 -0
  160. package/docs/configure/app/security/check-syntax.md +69 -0
  161. package/docs/configure/app/security/nonce.md +15 -0
  162. package/docs/configure/app/security/sri.md +20 -0
  163. package/docs/configure/app/server/base-url.md +26 -0
  164. package/docs/configure/app/server/port.md +18 -0
  165. package/docs/configure/app/server/public-routes.md +22 -0
  166. package/docs/configure/app/server/routes.md +86 -0
  167. package/docs/configure/app/server/rsc.md +26 -0
  168. package/docs/configure/app/server/ssr-by-entries.md +25 -0
  169. package/docs/configure/app/server/ssr.md +78 -0
  170. package/docs/configure/app/server/tsconfig-path.md +59 -0
  171. package/docs/configure/app/source/alias-strategy.md +14 -0
  172. package/docs/configure/app/source/alias.md +23 -0
  173. package/docs/configure/app/source/config-dir.md +20 -0
  174. package/docs/configure/app/source/decorators.md +25 -0
  175. package/docs/configure/app/source/define.md +16 -0
  176. package/docs/configure/app/source/disable-default-entries.md +28 -0
  177. package/docs/configure/app/source/enable-async-entry.md +54 -0
  178. package/docs/configure/app/source/enable-async-pre-entry.md +26 -0
  179. package/docs/configure/app/source/entries-dir.md +35 -0
  180. package/docs/configure/app/source/entries.md +179 -0
  181. package/docs/configure/app/source/exclude.md +10 -0
  182. package/docs/configure/app/source/global-vars.md +106 -0
  183. package/docs/configure/app/source/include.md +36 -0
  184. package/docs/configure/app/source/main-entry-name.md +24 -0
  185. package/docs/configure/app/source/pre-entry.md +10 -0
  186. package/docs/configure/app/source/react-compiler.md +68 -0
  187. package/docs/configure/app/source/transform-import.md +27 -0
  188. package/docs/configure/app/split-chunks.md +17 -0
  189. package/docs/configure/app/tools/autoprefixer.md +44 -0
  190. package/docs/configure/app/tools/bundler-chain.md +26 -0
  191. package/docs/configure/app/tools/css-extract.md +33 -0
  192. package/docs/configure/app/tools/css-loader.md +17 -0
  193. package/docs/configure/app/tools/dev-server.md +113 -0
  194. package/docs/configure/app/tools/html-plugin.md +41 -0
  195. package/docs/configure/app/tools/less.md +81 -0
  196. package/docs/configure/app/tools/lightningcss-loader.md +35 -0
  197. package/docs/configure/app/tools/minify-css.md +53 -0
  198. package/docs/configure/app/tools/postcss.md +34 -0
  199. package/docs/configure/app/tools/rspack.md +10 -0
  200. package/docs/configure/app/tools/sass.md +78 -0
  201. package/docs/configure/app/tools/style-loader.md +10 -0
  202. package/docs/configure/app/tools/swc.md +65 -0
  203. package/docs/configure/app/tools/ts-checker.md +109 -0
  204. package/docs/configure/app/usage.md +276 -0
  205. package/docs/guides/advanced-features/bff/cross-project.md +109 -0
  206. package/docs/guides/advanced-features/bff/extend-server.md +120 -0
  207. package/docs/guides/advanced-features/bff/frameworks.md +124 -0
  208. package/docs/guides/advanced-features/bff/function.md +314 -0
  209. package/docs/guides/advanced-features/bff/operators.md +554 -0
  210. package/docs/guides/advanced-features/bff/sdk.md +116 -0
  211. package/docs/guides/advanced-features/bff/upload.md +101 -0
  212. package/docs/guides/advanced-features/bff.md +18 -0
  213. package/docs/guides/advanced-features/build-performance.md +130 -0
  214. package/docs/guides/advanced-features/compatibility.md +120 -0
  215. package/docs/guides/advanced-features/international/advanced.md +128 -0
  216. package/docs/guides/advanced-features/international/api.md +231 -0
  217. package/docs/guides/advanced-features/international/best-practices.md +286 -0
  218. package/docs/guides/advanced-features/international/configuration.md +227 -0
  219. package/docs/guides/advanced-features/international/locale-detection.md +126 -0
  220. package/docs/guides/advanced-features/international/quick-start.md +128 -0
  221. package/docs/guides/advanced-features/international/resource-loading.md +154 -0
  222. package/docs/guides/advanced-features/international/routing.md +130 -0
  223. package/docs/guides/advanced-features/international.md +27 -0
  224. package/docs/guides/advanced-features/low-level.md +46 -0
  225. package/docs/guides/advanced-features/page-performance/code-split.md +77 -0
  226. package/docs/guides/advanced-features/page-performance/inline-assets.md +159 -0
  227. package/docs/guides/advanced-features/page-performance/optimize-bundle.md +97 -0
  228. package/docs/guides/advanced-features/page-performance/react-compiler.md +69 -0
  229. package/docs/guides/advanced-features/server-monitor/logger.md +41 -0
  230. package/docs/guides/advanced-features/server-monitor/metrics.md +58 -0
  231. package/docs/guides/advanced-features/server-monitor/monitors.md +242 -0
  232. package/docs/guides/advanced-features/source-build.md +164 -0
  233. package/docs/guides/advanced-features/web-server.md +288 -0
  234. package/docs/guides/basic-features/alias.md +102 -0
  235. package/docs/guides/basic-features/css/css-in-js.md +72 -0
  236. package/docs/guides/basic-features/css/css-modules.md +212 -0
  237. package/docs/guides/basic-features/css/css.md +27 -0
  238. package/docs/guides/basic-features/css/tailwindcss.md +27 -0
  239. package/docs/guides/basic-features/data/data-cache.md +510 -0
  240. package/docs/guides/basic-features/data/data-fetch.md +415 -0
  241. package/docs/guides/basic-features/data/data-write.md +227 -0
  242. package/docs/guides/basic-features/debug/mock.md +109 -0
  243. package/docs/guides/basic-features/debug/proxy.md +21 -0
  244. package/docs/guides/basic-features/debug/rsdoctor.md +62 -0
  245. package/docs/guides/basic-features/debug/using-storybook.md +112 -0
  246. package/docs/guides/basic-features/deploy.md +458 -0
  247. package/docs/guides/basic-features/env-vars.md +177 -0
  248. package/docs/guides/basic-features/html.md +255 -0
  249. package/docs/guides/basic-features/output-files.md +141 -0
  250. package/docs/guides/basic-features/render/before-render.md +108 -0
  251. package/docs/guides/basic-features/render/overview.md +47 -0
  252. package/docs/guides/basic-features/render/rsc.md +525 -0
  253. package/docs/guides/basic-features/render/ssg.md +228 -0
  254. package/docs/guides/basic-features/render/ssr-cache.md +201 -0
  255. package/docs/guides/basic-features/render/ssr.md +321 -0
  256. package/docs/guides/basic-features/render/streaming-ssr.md +264 -0
  257. package/docs/guides/basic-features/routes/config-routes.md +426 -0
  258. package/docs/guides/basic-features/routes/routes.md +498 -0
  259. package/docs/guides/basic-features/static-assets/json-files.md +120 -0
  260. package/docs/guides/basic-features/static-assets/svg-assets.md +168 -0
  261. package/docs/guides/basic-features/static-assets/wasm-assets.md +62 -0
  262. package/docs/guides/basic-features/static-assets.md +160 -0
  263. package/docs/guides/basic-features/testing/playwright.md +120 -0
  264. package/docs/guides/basic-features/testing/rstest.md +251 -0
  265. package/docs/guides/concept/builder.md +37 -0
  266. package/docs/guides/concept/entries.md +319 -0
  267. package/docs/guides/concept/server.md +35 -0
  268. package/docs/guides/get-started/ai-coding-agents.md +58 -0
  269. package/docs/guides/get-started/glossary.md +63 -0
  270. package/docs/guides/get-started/introduction.md +36 -0
  271. package/docs/guides/get-started/quick-start.md +236 -0
  272. package/docs/guides/get-started/tech-stack.md +82 -0
  273. package/docs/guides/get-started/upgrade.md +123 -0
  274. package/docs/guides/topic-detail/module-federation/application.md +116 -0
  275. package/docs/guides/topic-detail/module-federation/deploy.md +104 -0
  276. package/docs/guides/topic-detail/module-federation/i18n.md +670 -0
  277. package/docs/guides/topic-detail/module-federation/introduce.md +35 -0
  278. package/docs/guides/topic-detail/module-federation/ssr.md +118 -0
  279. package/docs/guides/topic-detail/module-federation/usage.md +219 -0
  280. package/docs/guides/troubleshooting/builder.md +110 -0
  281. package/docs/guides/troubleshooting/cli.md +35 -0
  282. package/docs/guides/troubleshooting/dependencies.md +119 -0
  283. package/docs/guides/troubleshooting/hmr.md +144 -0
  284. package/docs/guides/upgrade/config.md +963 -0
  285. package/docs/guides/upgrade/entry.md +463 -0
  286. package/docs/guides/upgrade/other.md +183 -0
  287. package/docs/guides/upgrade/overview.md +33 -0
  288. package/docs/guides/upgrade/tailwindcss.md +91 -0
  289. package/docs/guides/upgrade/web-server.md +109 -0
  290. package/docs/index.md +33 -0
  291. package/docs/llms.txt +285 -0
  292. package/docs/plugin/cli-plugins/api.md +573 -0
  293. package/docs/plugin/cli-plugins/life-cycle.md +2 -0
  294. package/docs/plugin/introduction.md +152 -0
  295. package/docs/plugin/official/cli-plugins/plugin-bff.md +5 -0
  296. package/docs/plugin/official/cli-plugins/plugin-ssg.md +5 -0
  297. package/docs/plugin/official/cli-plugins/plugin-styled-components.md +5 -0
  298. package/docs/plugin/official/cli-plugins.md +4 -0
  299. package/docs/plugin/plugin-system.md +238 -0
  300. package/docs/plugin/runtime-plugins/api.md +194 -0
  301. package/docs/plugin/runtime-plugins/life-cycle.md +2 -0
  302. package/docs/plugin/server-plugins/api.md +209 -0
  303. package/docs/plugin/server-plugins/life-cycle.md +13 -0
  304. package/docs/tutorials/examples/csr-auth.md +9 -0
  305. package/docs/tutorials/foundations/introduction.md +16 -0
  306. package/package.json +46 -13
@@ -0,0 +1,118 @@
1
+ # Server-Side Rendering
2
+
3
+ `@module-federation/modern-js-v3` offers powerful capabilities, enabling developers to easily combine Module Federation with server-side rendering (SSR) in Modern.js applications.
4
+
5
+ ## Enable SSR
6
+
7
+ Using the application created in [Using Module Federation](/guides/topic-detail/module-federation/usage.md) as an example, you only need to add the `server.ssr` configuration to both the producer and the consumer:
8
+
9
+ ```ts title="modern.config.ts"
10
+ import { appTools, defineConfig } from '@modern-js/app-tools';
11
+
12
+ export default defineConfig({
13
+ server: {
14
+ ssr: {
15
+ mode: 'stream',
16
+ },
17
+ },
18
+ });
19
+ ```
20
+
21
+ For better performance, we only support using this capability combination in Streaming SSR scenarios.
22
+
23
+ :::warning
24
+ Application-level modules (modules using `createBridgeComponent` and `createRemoteAppComponent`) do not support server-side rendering (SSR). If you need to use SSR functionality, please use component-level module export methods instead.
25
+ :::
26
+
27
+ ## Data Fetching
28
+
29
+ :::tip
30
+ Currently, this feature is experimental and has not been fully practiced. Please use it with caution.
31
+ :::
32
+
33
+ Module Federation now supports [data fetching](https://module-federation.io/zh/guide/basic/data-fetch/index.html#%E7%AE%80%E4%BB%8B) capabilities. Each producer file can have a corresponding data fetching file, with the file name format of `[name].data.ts`.
34
+
35
+ In Modern.js, data fetching can be used with SSR. Using the example in the previous chapter, create a data fetching file:
36
+
37
+ ```ts title="src/components/Button.data.ts"
38
+ import type { DataFetchParams } from '@module-federation/modern-js-v3/react';
39
+
40
+ export type Data = {
41
+ data: string;
42
+ };
43
+
44
+ export const fetchData = async (params: DataFetchParams): Promise<Data> => {
45
+ return new Promise(resolve => {
46
+ setTimeout(() => {
47
+ resolve({
48
+ data: `data: ${new Date()}`,
49
+ });
50
+ }, 1000);
51
+ });
52
+ };
53
+ ```
54
+
55
+ In Button, we get the data from the `Props`:
56
+
57
+ ```ts title="src/components/Button.tsx"
58
+ import React from 'react';
59
+ import type { Data } from './Button.data';
60
+
61
+ export const Button = (props: { mfData: Data }) => {
62
+ const { mfData } = props;
63
+ return (
64
+ <button type="button" className="test">
65
+ Remote Button {mfData?.data}
66
+ </button>
67
+ );
68
+ };
69
+ ```
70
+
71
+ ## Consuming Components
72
+
73
+ Consumers must use [`createLazyComponent`](https://module-federation.io/practice/bridge/react-bridge/load-component.html#what-is-createlazycomponent) to load remote components and specify the export as the component name.
74
+
75
+ ```tsx title="src/routes/page.tsx"
76
+ import type { JSX } from 'react';
77
+ import { getInstance } from '@module-federation/modern-js-v3/runtime';
78
+ import {
79
+ ERROR_TYPE,
80
+ lazyLoadComponentPlugin,
81
+ } from '@module-federation/modern-js-v3/react';
82
+
83
+ const instance = getInstance();
84
+ instance!.registerPlugins([lazyLoadComponentPlugin()]);
85
+
86
+ const Button = instance!.createLazyComponent({
87
+ loader: () => {
88
+ return import('remote/Button');
89
+ },
90
+ loading: 'loading...',
91
+ export: 'Button', // Configure this as the export name of the remote component
92
+ fallback: ({ error, errorType, dataFetchMapKey }) => {
93
+ console.error(error);
94
+ if (errorType === ERROR_TYPE.LOAD_REMOTE) {
95
+ return <div>load remote failed</div>;
96
+ }
97
+ if (errorType === ERROR_TYPE.DATA_FETCH) {
98
+ return (
99
+ <div>
100
+ data fetch failed, the dataFetchMapKey key is: {dataFetchMapKey}
101
+ </div>
102
+ );
103
+ }
104
+ return <div>error type is unknown</div>;
105
+ },
106
+ });
107
+
108
+ const Index = (): JSX.Element => {
109
+ return (
110
+ <div>
111
+ <h1>Basic usage with data fetch</h1>
112
+ <Button />
113
+ </div>
114
+ );
115
+ };
116
+
117
+ export default Index;
118
+ ```
@@ -0,0 +1,219 @@
1
+ # Getting Started
2
+
3
+ To use Module Federation in Modern.js, we recommend using the official plugin `@module-federation/modern-js-v3`.
4
+
5
+ This section will introduce how to set up both producer and consumer applications using the official plugin. First, create two applications by following the [Modern.js Quick Start](/guides/get-started/quick-start.md).
6
+
7
+ ## Install the Plugin
8
+
9
+ After creating the applications, install the plugin for both projects:
10
+
11
+
12
+ ```sh [npm]
13
+ npm add @module-federation/modern-js-v3
14
+ ```
15
+
16
+ ```sh [yarn]
17
+ yarn add @module-federation/modern-js-v3
18
+ ```
19
+
20
+ ```sh [pnpm]
21
+ pnpm add @module-federation/modern-js-v3
22
+ ```
23
+
24
+ ```sh [bun]
25
+ bun add @module-federation/modern-js-v3
26
+ ```
27
+
28
+ ```sh [deno]
29
+ deno add npm:@module-federation/modern-js-v3
30
+ ```
31
+
32
+ ## Register the Plugin
33
+
34
+ After installing the plugin, you need to register it in the `modern.config.js` file:
35
+
36
+ ```ts
37
+ import { appTools, defineConfig } from '@modern-js/app-tools';
38
+ import { moduleFederationPlugin } from '@module-federation/modern-js-v3';
39
+
40
+ export default defineConfig({
41
+ plugins: [appTools(), moduleFederationPlugin()],
42
+ });
43
+ ```
44
+
45
+ ## Export Modules from Producer
46
+
47
+ Next, modify the producer's code to export the Module Federation module.
48
+
49
+ Create the `src/components/Button.tsx` file and export a Button component:
50
+
51
+ ```tsx title="src/components/Button.tsx"
52
+ import React from 'react';
53
+
54
+ export const Button = () => {
55
+ return <button type="button">Remote Button</button>;
56
+ };
57
+ ```
58
+
59
+ Then, add the `module-federation.config.ts` file at the project root to configure the Module Federation module's name, shared dependencies, and exports:
60
+
61
+ ```ts title="module-federation.config.ts"
62
+ import { createModuleFederationConfig } from '@module-federation/modern-js-v3';
63
+
64
+ export default createModuleFederationConfig({
65
+ name: 'remote',
66
+ manifest: {
67
+ filePath: 'static',
68
+ },
69
+ filename: 'static/remoteEntry.js',
70
+ exposes: {
71
+ './Button': './src/components/Button.tsx',
72
+ },
73
+ shared: {
74
+ react: { singleton: true },
75
+ 'react-dom': { singleton: true },
76
+ },
77
+ });
78
+ ```
79
+
80
+ :::tip
81
+ In the above code block, we have prefixed both the manifest and remoteEntry.js exported by Module Federation with `static`. This is because Modern.js requires all resources that need to be exposed to be placed in the `static/` directory, and Modern.js's server will only host the `static/` directory in production environments.
82
+ :::
83
+
84
+ Additionally, modify `modern.config.ts` to provide a development environment port for the producer, allowing the consumer to access the producer's resources through this port:
85
+
86
+ ```ts title="modern.config.ts"
87
+ import { appTools, defineConfig } from '@modern-js/app-tools';
88
+ import { moduleFederationPlugin } from '@module-federation/modern-js-v3';
89
+
90
+ export default defineConfig({
91
+ server: {
92
+ port: 3051,
93
+ },
94
+ plugins: [appTools(), moduleFederationPlugin()],
95
+ });
96
+ ```
97
+
98
+ ## Use Modules in Consumer
99
+
100
+ Now, modify the consumer's code to use the module exported by the producer.
101
+
102
+ Add the `module-federation.config.ts` file at the project root to configure the Module Federation module's name, shared dependencies, and the remote module to use:
103
+
104
+ ```ts title="module-federation.config.ts"
105
+ import { createModuleFederationConfig } from '@module-federation/modern-js-v3';
106
+
107
+ export default createModuleFederationConfig({
108
+ name: 'host',
109
+ remotes: {
110
+ remote: 'remote@http://localhost:3051/static/mf-manifest.json',
111
+ },
112
+ shared: {
113
+ react: { singleton: true },
114
+ 'react-dom': { singleton: true },
115
+ },
116
+ });
117
+ ```
118
+
119
+ `mf-manifest.json` is the file produced by the producer after packaging, containing all the information about the modules exported by the producer.
120
+
121
+ Create a new route file `src/routes/remote/page.tsx` and import the producer module:
122
+
123
+ ```tsx title="src/routes/remote/page.tsx"
124
+ import React, { Suspense, type JSX } from 'react';
125
+ import { Button } from 'remote/Button';
126
+
127
+ const Index = (): JSX.Element => {
128
+ return (
129
+ <div>
130
+ <Suspense fallback={<div>Loading...</div>}>
131
+ <Button />
132
+ </Suspense>
133
+ </div>
134
+ );
135
+ };
136
+
137
+ export default Index;
138
+ ```
139
+
140
+ At this point, importing `remote/Button` will result in a type error because the local environment doesn't have the type for the remote module. Module Federation 2.0 provides [type hints](https://module-federation.io/zh/guide/basic/type-prompt.html), which will automatically generate type definitions for remote modules during the producer's build and download them during the consumer's build.
141
+
142
+ To ensure the types take effect, add a new `path` in `tsconfig.json`:
143
+
144
+ ```json title="tsconfig.json"
145
+ {
146
+ "compilerOptions": {
147
+ "paths": {
148
+ "*": ["./@mf-types/*"]
149
+ }
150
+ }
151
+ }
152
+ ```
153
+
154
+ :::tip
155
+ In the consumer, we reference the remote module using `remote/Button`. Here's a brief explanation of what this path specifically represents. You can abstract it as `[remoteAlias]/[remoteExpose]`.
156
+
157
+ The first part, `remoteAlias`, is the alias of the producer in the consumer. It is the `key` configured in the `remotes` field of the consumer's `module-federation.config.ts`:
158
+
159
+ ```ts
160
+ {
161
+ remotes: {
162
+ [remoteAlias]: '[remoteModuleName]@[URL_ADDRESS]',
163
+ }
164
+ }
165
+ ```
166
+
167
+ Here, we also abstract the remote address as `[remoteModuleName]@[URL_ADDRESS]`. The part before `@` must correspond to the module name of the producer.
168
+
169
+ The second part, `remoteExpose`, is the `key` configured in the `exposes` field of the producer's `module-federation.config.ts`.
170
+ :::
171
+
172
+ ## Start the Applications
173
+
174
+ Now, both the producer and consumer applications are set up. You can run `modern dev` locally to start both applications.
175
+
176
+ Once started, the imports of the producer's modules in the consumer will no longer throw errors, and the types will be downloaded to the consumer application.
177
+
178
+ :::note
179
+ After modifying the producer's code, the consumer will automatically fetch the producer's types.
180
+ :::
181
+
182
+ Access `http://localhost:8080/remote`, and you will see that the page includes the `Button` component from the producer's remote module.
183
+
184
+ We can also execute `modern serve` locally to simulate the production environment.
185
+
186
+ Because the Module Federation plugin will automatically read Modern.js's `output.assetPrefix` configuration as the access address for remote modules, and this value defaults to `/` after building in the production environment.
187
+
188
+ If we want to simulate the production environment in local, but not configure `output.assetPrefix`, consumers will pull the entry file of the remote module from their own domain. So We can add the following configuration:
189
+
190
+ ```ts
191
+ import { appTools, defineConfig } from '@modern-js/app-tools';
192
+ import { moduleFederationPlugin } from '@module-federation/modern-js-v3';
193
+
194
+ // https://modernjs.dev/en/configure/app/usage
195
+ export default defineConfig({
196
+ server: {
197
+ port: 3051,
198
+ },
199
+ output: {
200
+ // Now this configuration is only used in the local when you run modern serve command.
201
+ // If you want to deploy the application to the platform, use your own domain name.
202
+ // Module federation will automatically write it to mf-manifest.json, which influences consumer to fetch remoteEntry.js.
203
+ assetPrefix: 'http://127.0.0.1:3051',
204
+ },
205
+ plugins: [appTools(), moduleFederationPlugin()],
206
+ });
207
+ ```
208
+
209
+ Now, in the producer, run `modern build && MODERN_MF_AUTO_CORS=true modern serve`, and in the consumer, run `modern build && modern serve` to simulate the production environment locally and access the remote modules.
210
+
211
+ :::tip
212
+ When using the `modern serve` command, you need to set the `MODERN_MF_AUTO_CORS=true` environment variable when starting the producer project to automatically handle CORS issues and ensure that consumers can properly access the producer's remote module resources.
213
+ :::
214
+
215
+ You can refer to this example: [Modern.js & Module Federation Basic Example](https://github.com/web-infra-dev/modern.js/tree/main/examples/module-federation/base).
216
+
217
+ ## Related Documentation
218
+
219
+ - [Module Federation Official Documentation](https://module-federation.io/zh/guide/framework/modernjs.html)
@@ -0,0 +1,110 @@
1
+ # Build FAQ
2
+
3
+ If you encounter any build-related issues, you can refer to the current document for troubleshooting.
4
+
5
+ ***
6
+
7
+ ### Rsbuild FAQ
8
+
9
+ Modern.js is internally based on [Rsbuild](https://v2.rsbuild.rs/) and encapsulates its own build tool, so you can directly refer to the FAQ document of Rsbuild:
10
+
11
+ - [Rsbuild - Features FAQ](https://v2.rsbuild.rs/guide/faq/features)
12
+ - [Rsbuild - Exceptions FAQ](https://v2.rsbuild.rs/guide/faq/exceptions)
13
+ - [Rsbuild - HMR FAQ](https://v2.rsbuild.rs/guide/faq/hmr)
14
+
15
+ ***
16
+
17
+ ### How to view the final generated Rspack configuration?
18
+
19
+ Modern.js provides [inspect command](https://modernjs.dev/en/apis/app/commands.html) to view the final Modern.js configuration and Rspack configuration generated by the project.
20
+
21
+ ```bash
22
+ ➜ npx modern inspect
23
+
24
+ Inspect config succeed, open following files to view the content:
25
+
26
+ - Builder Config: /root/my-project/dist/rsbuild.config.mjs
27
+ - Rspack Config (web): /root/my-project/dist/rspack.config.web.mjs
28
+ ```
29
+
30
+ ***
31
+
32
+ ### Failed import other modules in Monorepo?
33
+
34
+ Due to considerations of compilation performance, by default, the Modern.js does not compile files under `node_modules` or files outside the current project directory.
35
+
36
+ Therefore, when you reference the source code of other sub-projects, you may encounter an error similar to `You may need an additional loader to handle the result of these loaders.`
37
+
38
+ There are several solutions to this problem:
39
+
40
+ 1. You can enable the source code build mode to compile other sub-projects within the monorepo. Please refer to [Source Code Build Mode](/guides/advanced-features/source-build.md) for more information.
41
+ 2. You can add the `source.include` configuration option to specify the directories or modules that need to be additionally compiled. Please refer to [Usage of source.include](/configure/app/source/include.md) for more information.
42
+ 3. You can pre-build the sub-projects that need to be referenced, generate the corresponding build artifacts, and then reference the build artifacts in the current project instead of referencing the source code.
43
+
44
+ ***
45
+
46
+ ### Find `exports is not defined` runtime error?
47
+
48
+ If the compilation is succeed, but the `exports is not defined` error appears after opening the page, it is usually because a CommonJS module is compiled by Babel.
49
+
50
+ Under normal circumstances, Modern.js will not use Babel to compile CommonJS modules. If the [source.include](/configure/app/source/include.md) configuration option is used in the project, some CommonJS modules may be added to the Babel compilation.
51
+
52
+ There are two workarounds for this problem:
53
+
54
+ 1. Avoid adding CommonJS modules to Babel compilation.
55
+ 2. Set Babel's `sourceType` configuration to `unambiguous`.
56
+
57
+ ***
58
+
59
+ ### Compile error "Error: ES Modules may not assign module.exports or exports.\*, Use ESM export syntax"?
60
+
61
+ If the following error occurs during compilation, it is usually because a CommonJS module is compiled with Babel in the project, and the solution is same as the above `exports is not defined` problem.
62
+
63
+ ```bash
64
+ Error: ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: 581
65
+ ```
66
+
67
+ For more information, please refer to issue: [babel#12731](https://github.com/babel/babel/issues/12731).
68
+
69
+ ***
70
+
71
+ ### The compilation progress bar is stuck, but there is no Error log in the terminal?
72
+
73
+ When the compilation progress bar is stuck, but there is no Error log on the terminal, it is usually because an exception occurred during the compilation. In some cases, when Error is caught by the build tool or other modules, the error log can not be output correctly. The most common scenario is that there is an exception in the Babel config, which is caught by the build tool, and the build tool swallows the Error in some cases.
74
+
75
+ **Solution:**
76
+
77
+ If this problem occurs after you modify the Babel config, it is recommended to check for the following incorrect usages:
78
+
79
+ 1. You have configured a plugin or preset that does not exist, maybe the name is misspelled, or it is not installed correctly.
80
+ 2. Whether multiple babel-plugin-imports are configured, but the name of each babel-plugin-import is not declared in the third item of the array.
81
+
82
+ ***
83
+
84
+ ### Compilation error after referencing a type from lodash
85
+
86
+ If the `@types/lodash` package is installed in your project, you may import some types from `lodash`, such as the `DebouncedFunc` type:
87
+
88
+ ```ts
89
+ import { debounce, DebouncedFunc } from 'lodash';
90
+ ```
91
+
92
+ Modern.js will throw an error after compiling the above code:
93
+
94
+ ```bash
95
+ Syntax error: /project/src/index.ts: The lodash method `DebouncedFunc` is not a known module.
96
+ Please report bugs to https://github.com/lodash/babel-plugin-lodash/issues.
97
+ ```
98
+
99
+ The reason is that Modern.js has enabled the [babel-plugin-lodash](https://github.com/lodash/babel-plugin-lodash) plugin by default to optimize the bundle size of lodash, but Babel cannot distinguish between "value" and "type", which resulting in an exception in the compiled code.
100
+
101
+ The solution is to use TypeScript's `import type` syntax to explicitly declare the `DebouncedFunc` type:
102
+
103
+ ```ts
104
+ import { debounce } from 'lodash';
105
+ import type { DebouncedFunc } from 'lodash';
106
+ ```
107
+
108
+ :::tip
109
+ In any case, it is recommended to use `import type` to import types, this will help the compiler to identify the type.
110
+ :::
@@ -0,0 +1,35 @@
1
+ # CLI FAQ
2
+
3
+ ### Unable to pass command line arguments correctly when using pnpm?
4
+
5
+ When using pnpm to call the commands in `package.json`, you need to pay attention to how parameters are passed:
6
+
7
+ - **If you need to pass parameters to pnpm**, you need to put the parameters before the command.
8
+
9
+ For example, using the pnpm `--filter` parameter to run the prepare command:
10
+
11
+ ```bash
12
+ pnpm run --filter "./packages/**" prepare
13
+ ```
14
+
15
+ - **If you need to pass parameters to the command**, you need to put the parameters after the command.
16
+
17
+ For example, in the following `package.json` configuration:
18
+
19
+ ```json
20
+ {
21
+ "scripts": {
22
+ "command": "modern command"
23
+ }
24
+ }
25
+ ```
26
+
27
+ The way to pass parameters when running the command is:
28
+
29
+ ```bash
30
+ pnpm run command --options
31
+ ```
32
+
33
+ :::tip
34
+ Modern.js requires Node.js >= 20.19.5, and pnpm v6 does not support Node.js 20, so please use pnpm v7 or higher.
35
+ :::
@@ -0,0 +1,119 @@
1
+ # Dependencies FAQ
2
+
3
+ ### How to check the actual installed version of a dependency in the project?
4
+
5
+ You can use the `ls` command provided by the package manager to view the version of the dependency in the project.
6
+
7
+ Here are some basic examples. For detailed usage, please refer to the documentation of each package manager.
8
+
9
+ **npm / yarn**
10
+
11
+ For projects using npm or yarn, you can use the `npm ls` command.
12
+
13
+ For example, running `npm ls @modern-js/plugin` will show the following result:
14
+
15
+ ```
16
+ project
17
+ └─┬ @modern-js/app-tools@x.y.z
18
+ └── @modern-js/plugin@x.y.z
19
+ ```
20
+
21
+ **pnpm**
22
+
23
+ For projects using pnpm, you can use the `pnpm ls` command.
24
+
25
+ For example, running `pnpm ls @modern-js/plugin --depth Infinity` will show the following result:
26
+
27
+ ```
28
+ devDependencies:
29
+ @modern-js/app-tools x.y.z
30
+ └── @modern-js/plugin x.y.z
31
+ ```
32
+
33
+ ***
34
+
35
+ ### Getting "The engine "node" is incompatible" error during dependency installation?
36
+
37
+ If you encounter the following error message during dependency installation, it means that the current environment is using a Node.js version that is too low, and you need to upgrade Node.js to a higher version.
38
+
39
+ ```bash
40
+ The engine "node" is incompatible with this module.
41
+
42
+ Expected version ">=20.19.5". Got "16.20.1"
43
+ ```
44
+
45
+ Modern.js requires Node.js version >= 20.19.5. We strongly recommend using the latest LTS version (such as [Node.js 22 LTS](https://nodejs.org/)) for the best experience.
46
+
47
+ If the Node.js version of the current environment is lower than the above requirement, you can use tools such as [nvm](https://github.com/nvm-sh/nvm) or [fnm](https://github.com/Schniz/fnm) to switch versions.
48
+
49
+ Here is an example of using nvm:
50
+
51
+ ```bash
52
+ # Install Node.js 22 LTS
53
+ nvm install 22 --lts
54
+
55
+ # Switch to Node.js 22
56
+ nvm use 22
57
+
58
+ # Set Node.js 22 as the default version
59
+ nvm alias default 22
60
+ ```
61
+
62
+ For local development environments, it is recommended to use [fnm](https://github.com/Schniz/fnm), which has better performance than nvm and has similar usage.
63
+
64
+ ***
65
+
66
+ ### Getting a ReactNode type error after upgrading dependencies?
67
+
68
+ After upgrading the dependencies of the project, if the following type error occurs, it means that the wrong version of `@types/react` is installed in the project.
69
+
70
+ ```bash
71
+ The types returned by 'render()' are incompatible between these types.
72
+ Type 'React.ReactNode' is not assignable to type 'import("/node_modules/@types/react/index").ReactNode'.
73
+ Type '{}' is not assignable to type 'ReactNode'.
74
+ ```
75
+
76
+ The reason for this problem is that the ReactNode type definition in React 18/19 is different from that in React 16/17. If there are multiple different versions of `@types/react` in the project, a ReactNode type conflict will occur, resulting in the above error.
77
+
78
+ The solution is to lock the `@types/react` and `@types/react-dom` in the project to a unified version, such as `v17`.
79
+
80
+ ```json
81
+ {
82
+ "@types/react": "^19",
83
+ "@types/react-dom": "^19"
84
+ }
85
+ ```
86
+
87
+ For methods of locking dependency versions, please refer to [Lock nested dependency](/guides/get-started/upgrade.md#lock-nested-dependency).
88
+
89
+ ***
90
+
91
+ ### Getting peer dependencies warnings in the console after running `pnpm install`?
92
+
93
+ The reason for this warning is that the version range of peer dependencies declared by some third-party npm packages is inconsistent with the version range installed in Modern.js.
94
+
95
+ In most cases, peer dependencies warnings will not affect the project operation and do not need to be processed separately. Please ignore the relevant warnings.
96
+
97
+ ***
98
+
99
+ ### What is the minimum supported version of React for the Modern.js framework?
100
+
101
+ **Modern.js framework requires React version >= 18.0.0**.
102
+
103
+ - **If you are using Modern.js runtime capabilities** (including SSR, Streaming SSR, data loading, routing, etc.), you must use React 18 or higher. React 16 and React 17 are no longer supported.
104
+ - **If you are only using Modern.js build capabilities** (without runtime), React 16 or React 17 may theoretically work, but it is strongly recommended to upgrade to React 18 or higher for the best experience and full feature support.
105
+
106
+ ***
107
+
108
+ ### Type error in Modern.js configuration file?
109
+
110
+ ```bash
111
+ Type 'CliPlugin<{}, {}, {}, {}>' is not assignable to type 'CliPlugin<any, {}, {}, {}>'.
112
+ Types of property 'setup' are incompatible.
113
+ ```
114
+
115
+ When you use the Modern.js framework, the above error occurs in the configuration file, it may be due to the inconsistent versions of Modern.js related packages. You need to manually update all `@modern-js/**` packages to the same version.
116
+
117
+ In the monorepo, the above error may also occur due to inconsistent versions of the Modern.js framework used by different sub-projects.
118
+
119
+ For information on how to unify and upgrade dependency versions, please refer to the [Upgrading](/guides/get-started/upgrade.md) documentation.