@modern-js/main-doc 2.69.4 → 3.0.0-alpha.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.
- package/docs/en/{_meta.json → _nav.json} +5 -1
- package/docs/en/apis/app/commands.mdx +2 -3
- package/docs/en/apis/app/hooks/src/entry.mdx +1 -5
- package/docs/en/apis/app/hooks/src/entry.server.mdx +4 -5
- package/docs/en/apis/app/hooks/src/routes.mdx +2 -2
- package/docs/en/apis/app/runtime/_meta.json +0 -18
- package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +2 -2
- package/docs/en/apis/app/runtime/router/router.mdx +1 -1
- package/docs/en/apis/app/runtime/utility/css-in-js.mdx +3 -2
- package/docs/en/community/blog/v2-release-note.mdx +0 -2
- package/docs/en/community/contributing-guide.mdx +10 -12
- package/docs/en/components/bff-upload.mdx +16 -12
- package/docs/en/components/build-output.mdx +45 -0
- package/docs/en/components/debug-app.mdx +1 -1
- package/docs/en/components/enable-bff-caution.mdx +2 -2
- package/docs/en/components/enable-bff.mdx +38 -8
- package/docs/en/components/enable-ssg.mdx +48 -0
- package/docs/en/components/entry-scan-logic.mdx +7 -0
- package/docs/en/components/init-app.mdx +40 -17
- package/docs/en/components/international/install-command.mdx +9 -0
- package/docs/en/components/international/introduce.mdx +2 -0
- package/docs/en/components/module-federation.mdx +4 -4
- package/docs/en/components/new-entry-tooltip.mdx +0 -0
- package/docs/en/components/nodeVersion.mdx +2 -6
- package/docs/en/components/prerequisites.mdx +1 -1
- package/docs/en/components/ua-polyfill.mdx +16 -12
- package/docs/en/components/upgrade-browserslist.mdx +0 -0
- package/docs/en/configure/_meta.json +7 -8
- package/docs/en/configure/app/bff/cross-project.mdx +24 -0
- package/docs/en/configure/app/dev/lazy-compilation.mdx +45 -0
- package/docs/en/configure/app/dev/server.mdx +103 -0
- package/docs/en/configure/app/dev/setup-middlewares.mdx +4 -22
- package/docs/en/configure/app/html/app-icon.mdx +1 -23
- package/docs/en/configure/app/output/inline-scripts.mdx +1 -1
- package/docs/en/configure/app/output/override-browserslist.mdx +6 -4
- package/docs/en/configure/app/output/source-map.mdx +6 -3
- package/docs/en/configure/app/output/ssg.mdx +12 -43
- package/docs/en/configure/app/output/ssgByEntries.mdx +93 -0
- package/docs/en/configure/app/performance/build-cache.mdx +0 -4
- package/docs/en/configure/app/resolve/alias-strategy.mdx +14 -0
- package/docs/en/configure/app/resolve/alias.mdx +13 -0
- package/docs/en/configure/app/resolve/condition-names.mdx +18 -0
- package/docs/en/configure/app/resolve/dedupe.mdx +13 -0
- package/docs/en/configure/app/resolve/extensions.mdx +18 -0
- package/docs/en/configure/app/runtime/0-intro.mdx +2 -51
- package/docs/en/configure/app/security/check-syntax.mdx +1 -1
- package/docs/en/configure/app/server/port.mdx +1 -21
- package/docs/en/configure/app/server/rsc.mdx +30 -0
- package/docs/en/configure/app/server/ssr.mdx +20 -9
- package/docs/en/configure/app/source/decorators.mdx +4 -2
- package/docs/en/configure/app/source/entries.mdx +0 -2
- package/docs/en/configure/app/source/main-entry-name.mdx +4 -4
- package/docs/en/configure/app/source/transform-import.mdx +1 -59
- package/docs/en/configure/app/tools/bundler-chain.mdx +5 -5
- package/docs/en/configure/app/tools/css-extract.mdx +1 -1
- package/docs/en/configure/app/tools/dev-server.mdx +14 -248
- package/docs/en/configure/app/tools/html-plugin.mdx +3 -3
- package/docs/en/configure/app/tools/lightningcss-loader.mdx +0 -1
- package/docs/en/configure/app/tools/swc.mdx +1 -43
- package/docs/en/configure/app/usage.mdx +7 -17
- package/docs/en/guides/_meta.json +1 -2
- package/docs/en/guides/advanced-features/_meta.json +6 -0
- package/docs/en/guides/advanced-features/bff/cross-project.mdx +1 -7
- package/docs/en/guides/advanced-features/bff/extend-server.mdx +18 -3
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +1 -1
- package/docs/en/guides/advanced-features/bff/function.mdx +2 -6
- package/docs/en/guides/advanced-features/bff/sdk.mdx +3 -3
- package/docs/en/guides/advanced-features/build-performance.mdx +23 -26
- package/docs/en/guides/advanced-features/compatibility.mdx +53 -9
- package/docs/en/guides/advanced-features/international/_meta.json +11 -0
- package/docs/en/guides/advanced-features/international/advanced.mdx +193 -0
- package/docs/en/guides/advanced-features/international/api.mdx +400 -0
- package/docs/en/guides/advanced-features/international/basic.mdx +417 -0
- package/docs/en/guides/advanced-features/international/best-practices.mdx +135 -0
- package/docs/en/guides/advanced-features/international/configuration.mdx +437 -0
- package/docs/en/guides/advanced-features/international/locale-detection.mdx +276 -0
- package/docs/en/guides/advanced-features/international/quick-start.mdx +154 -0
- package/docs/en/guides/advanced-features/international/resource-loading.mdx +417 -0
- package/docs/en/guides/advanced-features/international/routing.mdx +212 -0
- package/docs/en/guides/advanced-features/international.mdx +37 -0
- package/docs/en/guides/advanced-features/low-level.mdx +21 -16
- package/docs/en/guides/advanced-features/page-performance/code-split.mdx +4 -4
- package/docs/en/guides/advanced-features/page-performance/inline-assets.mdx +4 -4
- package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +7 -21
- package/docs/en/guides/advanced-features/page-performance/react-compiler.mdx +1 -8
- package/docs/en/guides/advanced-features/rspack-start.mdx +2 -22
- package/docs/en/guides/advanced-features/server-monitor/logger.mdx +0 -4
- package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +62 -34
- package/docs/en/guides/advanced-features/web-server.mdx +82 -299
- package/docs/en/guides/basic-features/_meta.json +6 -1
- package/docs/en/guides/basic-features/css/css-in-js.mdx +46 -11
- package/docs/en/guides/basic-features/css/css-modules.mdx +5 -17
- package/docs/en/guides/basic-features/css/css.mdx +3 -3
- package/docs/en/guides/basic-features/css/tailwindcss.mdx +5 -89
- package/docs/en/guides/basic-features/data/data-cache.mdx +5 -1
- package/docs/en/guides/basic-features/data/data-fetch.mdx +4 -4
- package/docs/en/guides/basic-features/data/data-write.mdx +2 -2
- package/docs/en/guides/basic-features/debug/mock.mdx +4 -1
- package/docs/en/guides/basic-features/debug/proxy.mdx +0 -8
- package/docs/en/guides/basic-features/debug/rsdoctor.mdx +5 -5
- package/docs/en/guides/basic-features/deploy.mdx +25 -18
- package/docs/en/guides/basic-features/env-vars.mdx +1 -1
- package/docs/en/guides/basic-features/html.mdx +1 -1
- package/docs/en/guides/basic-features/output-files.mdx +3 -3
- package/docs/en/guides/basic-features/render/_meta.json +1 -1
- package/docs/en/guides/basic-features/render/before-render.mdx +16 -23
- package/docs/en/guides/basic-features/render/overview.mdx +51 -0
- package/docs/en/guides/basic-features/render/rsc.mdx +394 -0
- package/docs/en/guides/basic-features/render/ssg.mdx +26 -62
- package/docs/en/guides/basic-features/render/ssr-cache.mdx +6 -6
- package/docs/en/guides/basic-features/render/ssr.mdx +31 -31
- package/docs/en/guides/basic-features/render/streaming-ssr.mdx +29 -9
- package/docs/en/guides/basic-features/routes/_meta.json +1 -0
- package/docs/en/guides/basic-features/routes/config-routes.mdx +427 -0
- package/docs/en/guides/basic-features/{routes.mdx → routes/routes.mdx} +7 -110
- package/docs/en/guides/basic-features/static-assets/json-files.mdx +21 -3
- package/docs/en/guides/basic-features/static-assets.mdx +2 -2
- package/docs/en/guides/concept/builder.mdx +24 -9
- package/docs/en/guides/concept/entries.mdx +139 -147
- package/docs/en/guides/get-started/glossary.mdx +0 -18
- package/docs/en/guides/get-started/introduction.mdx +1 -4
- package/docs/en/guides/get-started/quick-start.mdx +8 -73
- package/docs/en/guides/get-started/tech-stack.mdx +7 -25
- package/docs/en/guides/get-started/upgrade.mdx +30 -23
- package/docs/en/guides/topic-detail/_meta.json +0 -12
- package/docs/en/guides/topic-detail/module-federation/_meta.json +1 -1
- package/docs/en/guides/topic-detail/module-federation/application.mdx +16 -15
- package/docs/en/guides/topic-detail/module-federation/i18n.mdx +670 -0
- package/docs/en/guides/topic-detail/module-federation/introduce.mdx +5 -4
- package/docs/en/guides/topic-detail/module-federation/ssr.mdx +50 -2
- package/docs/en/guides/topic-detail/module-federation/usage.mdx +10 -30
- package/docs/en/guides/troubleshooting/builder.mdx +3 -82
- package/docs/en/guides/troubleshooting/cli.mdx +6 -30
- package/docs/en/guides/troubleshooting/dependencies.mdx +22 -22
- package/docs/en/plugin/cli-plugins/api.mdx +4 -5
- package/docs/en/plugin/cli-plugins/migration.mdx +33 -48
- package/docs/en/plugin/introduction.mdx +39 -27
- package/docs/en/plugin/official/_meta.json +0 -5
- package/docs/en/plugin/official/cli-plugins/_meta.json +1 -1
- package/docs/en/plugin/official/cli-plugins/plugin-styled-components.mdx +5 -0
- package/docs/en/plugin/official/cli-plugins.mdx +0 -2
- package/docs/en/plugin/plugin-system.mdx +68 -61
- package/docs/en/plugin/runtime-plugins/api.mdx +62 -59
- package/docs/en/plugin/runtime-plugins/migration.mdx +29 -20
- package/docs/en/tutorials/_meta.json +0 -10
- package/docs/en/tutorials/examples/csr-auth.mdx +1 -1
- package/docs/en/tutorials/foundations/introduction.mdx +9 -25
- package/docs/zh/{_meta.json → _nav.json} +10 -6
- package/docs/zh/apis/app/commands.mdx +2 -3
- package/docs/zh/apis/app/hooks/src/entry.mdx +1 -5
- package/docs/zh/apis/app/hooks/src/entry.server.mdx +4 -5
- package/docs/zh/apis/app/hooks/src/routes.mdx +2 -2
- package/docs/zh/apis/app/runtime/_meta.json +0 -18
- package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +2 -2
- package/docs/zh/apis/app/runtime/utility/css-in-js.mdx +3 -2
- package/docs/zh/community/blog/v2-release-note.mdx +0 -2
- package/docs/zh/community/contributing-guide.mdx +10 -12
- package/docs/zh/components/auto-upgrade.mdx +0 -0
- package/docs/zh/components/bff-upload.mdx +8 -5
- package/docs/zh/components/build-output.mdx +45 -0
- package/docs/zh/components/debug-app.mdx +1 -1
- package/docs/zh/components/enable-bff-caution.mdx +1 -1
- package/docs/zh/components/enable-bff.mdx +37 -8
- package/docs/zh/components/enable-ssg.mdx +47 -0
- package/docs/zh/components/entry-scan-logic.mdx +7 -0
- package/docs/zh/components/init-app.mdx +40 -18
- package/docs/zh/components/international/install-command.mdx +8 -0
- package/docs/zh/components/international/introduce.mdx +2 -0
- package/docs/zh/components/international/platform-support.mdx +0 -0
- package/docs/zh/components/module-federation.mdx +4 -4
- package/docs/zh/components/new-entry-tooltip.mdx +0 -0
- package/docs/zh/components/nodeVersion.mdx +3 -7
- package/docs/zh/components/prerequisites.mdx +1 -1
- package/docs/zh/components/self-route-example.mdx +3 -3
- package/docs/zh/components/ua-polyfill.mdx +11 -6
- package/docs/zh/components/upgrade-browserslist.mdx +0 -0
- package/docs/zh/configure/_meta.json +7 -8
- package/docs/zh/configure/app/bff/cross-project.mdx +24 -0
- package/docs/zh/configure/app/dev/lazy-compilation.mdx +44 -0
- package/docs/zh/configure/app/dev/server.mdx +104 -0
- package/docs/zh/configure/app/dev/setup-middlewares.mdx +4 -23
- package/docs/zh/configure/app/html/app-icon.mdx +1 -23
- package/docs/zh/configure/app/output/inline-scripts.mdx +1 -1
- package/docs/zh/configure/app/output/override-browserslist.mdx +3 -3
- package/docs/zh/configure/app/output/source-map.mdx +10 -3
- package/docs/zh/configure/app/output/ssg.mdx +13 -45
- package/docs/zh/configure/app/output/ssgByEntries.mdx +94 -0
- package/docs/zh/configure/app/performance/build-cache.mdx +0 -4
- package/docs/zh/configure/app/resolve/alias-strategy.mdx +14 -0
- package/docs/zh/configure/app/resolve/alias.mdx +13 -0
- package/docs/zh/configure/app/resolve/condition-names.mdx +18 -0
- package/docs/zh/configure/app/resolve/dedupe.mdx +14 -0
- package/docs/zh/configure/app/resolve/extensions.mdx +18 -0
- package/docs/zh/configure/app/runtime/0-intro.mdx +2 -53
- package/docs/zh/configure/app/security/check-syntax.mdx +1 -1
- package/docs/zh/configure/app/server/port.mdx +2 -21
- package/docs/zh/configure/app/server/rsc.mdx +30 -0
- package/docs/zh/configure/app/server/ssr.mdx +21 -11
- package/docs/zh/configure/app/source/decorators.mdx +4 -4
- package/docs/zh/configure/app/source/entries.mdx +0 -2
- package/docs/zh/configure/app/source/main-entry-name.mdx +4 -4
- package/docs/zh/configure/app/source/transform-import.mdx +1 -59
- package/docs/zh/configure/app/tools/bundler-chain.mdx +6 -6
- package/docs/zh/configure/app/tools/css-extract.mdx +1 -1
- package/docs/zh/configure/app/tools/dev-server.mdx +14 -248
- package/docs/zh/configure/app/tools/html-plugin.mdx +3 -2
- package/docs/zh/configure/app/tools/lightningcss-loader.mdx +0 -1
- package/docs/zh/configure/app/tools/swc.mdx +1 -43
- package/docs/zh/configure/app/usage.mdx +8 -18
- package/docs/zh/guides/_meta.json +5 -1
- package/docs/zh/guides/advanced-features/_meta.json +6 -1
- package/docs/zh/guides/advanced-features/bff/cross-project.mdx +8 -16
- package/docs/zh/guides/advanced-features/bff/extend-server.mdx +25 -8
- package/docs/zh/guides/advanced-features/bff/frameworks.mdx +1 -1
- package/docs/zh/guides/advanced-features/bff/function.mdx +7 -12
- package/docs/zh/guides/advanced-features/bff/sdk.mdx +4 -4
- package/docs/zh/guides/advanced-features/build-performance.mdx +23 -30
- package/docs/zh/guides/advanced-features/compatibility.mdx +44 -0
- package/docs/zh/guides/advanced-features/international/_meta.json +11 -0
- package/docs/zh/guides/advanced-features/international/advanced.mdx +193 -0
- package/docs/zh/guides/advanced-features/international/api.mdx +400 -0
- package/docs/zh/guides/advanced-features/international/basic.mdx +416 -0
- package/docs/zh/guides/advanced-features/international/best-practices.mdx +135 -0
- package/docs/zh/guides/advanced-features/international/configuration.mdx +441 -0
- package/docs/zh/guides/advanced-features/international/locale-detection.mdx +304 -0
- package/docs/zh/guides/advanced-features/international/quick-start.mdx +149 -0
- package/docs/zh/guides/advanced-features/international/resource-loading.mdx +417 -0
- package/docs/zh/guides/advanced-features/international/routing.mdx +212 -0
- package/docs/zh/guides/advanced-features/international.mdx +36 -0
- package/docs/zh/guides/advanced-features/low-level.mdx +21 -16
- package/docs/zh/guides/advanced-features/page-performance/code-split.mdx +3 -3
- package/docs/zh/guides/advanced-features/page-performance/inline-assets.mdx +4 -4
- package/docs/zh/guides/advanced-features/page-performance/optimize-bundle.mdx +7 -21
- package/docs/zh/guides/advanced-features/page-performance/react-compiler.mdx +1 -8
- package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +0 -4
- package/docs/zh/guides/advanced-features/server-monitor/monitors.mdx +63 -35
- package/docs/zh/guides/advanced-features/web-server.mdx +79 -300
- package/docs/zh/guides/basic-features/_meta.json +6 -1
- package/docs/zh/guides/basic-features/css/css-in-js.mdx +40 -5
- package/docs/zh/guides/basic-features/css/css-modules.mdx +6 -17
- package/docs/zh/guides/basic-features/css/css.mdx +2 -2
- package/docs/zh/guides/basic-features/css/tailwindcss.mdx +6 -90
- package/docs/zh/guides/basic-features/data/data-cache.mdx +8 -5
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +6 -5
- package/docs/zh/guides/basic-features/data/data-write.mdx +4 -4
- package/docs/zh/guides/basic-features/debug/mock.mdx +4 -1
- package/docs/zh/guides/basic-features/debug/proxy.mdx +0 -8
- package/docs/zh/guides/basic-features/debug/rsdoctor.mdx +6 -6
- package/docs/zh/guides/basic-features/deploy.mdx +24 -20
- package/docs/zh/guides/basic-features/env-vars.mdx +1 -1
- package/docs/zh/guides/basic-features/html.mdx +2 -2
- package/docs/zh/guides/basic-features/output-files.mdx +3 -3
- package/docs/zh/guides/basic-features/render/_meta.json +1 -1
- package/docs/zh/guides/basic-features/render/before-render.mdx +17 -24
- package/docs/zh/guides/basic-features/render/overview.mdx +52 -0
- package/docs/zh/guides/basic-features/render/rsc.mdx +413 -0
- package/docs/zh/guides/basic-features/render/ssg.mdx +27 -69
- package/docs/zh/guides/basic-features/render/ssr-cache.mdx +5 -5
- package/docs/zh/guides/basic-features/render/ssr.mdx +34 -31
- package/docs/zh/guides/basic-features/render/streaming-ssr.mdx +34 -14
- package/docs/zh/guides/basic-features/routes/_meta.json +1 -0
- package/docs/zh/guides/basic-features/routes/config-routes.mdx +426 -0
- package/docs/zh/guides/basic-features/{routes.mdx → routes/routes.mdx} +8 -114
- package/docs/zh/guides/basic-features/static-assets/json-files.mdx +21 -3
- package/docs/zh/guides/basic-features/static-assets.mdx +2 -2
- package/docs/zh/guides/basic-features/testing/cypress.mdx +5 -5
- package/docs/zh/guides/basic-features/testing/jest.mdx +12 -12
- package/docs/zh/guides/concept/builder.mdx +24 -9
- package/docs/zh/guides/concept/entries.mdx +95 -92
- package/docs/zh/guides/get-started/glossary.mdx +0 -18
- package/docs/zh/guides/get-started/introduction.mdx +1 -5
- package/docs/zh/guides/get-started/quick-start.mdx +5 -72
- package/docs/zh/guides/get-started/tech-stack.mdx +8 -26
- package/docs/zh/guides/get-started/upgrade.mdx +30 -23
- package/docs/zh/guides/topic-detail/_meta.json +0 -12
- package/docs/zh/guides/topic-detail/module-federation/_meta.json +1 -1
- package/docs/zh/guides/topic-detail/module-federation/application.mdx +18 -16
- package/docs/zh/guides/topic-detail/module-federation/i18n.mdx +623 -0
- package/docs/zh/guides/topic-detail/module-federation/introduce.mdx +4 -4
- package/docs/zh/guides/topic-detail/module-federation/ssr.mdx +51 -5
- package/docs/zh/guides/topic-detail/module-federation/usage.mdx +11 -32
- package/docs/zh/guides/troubleshooting/builder.mdx +3 -84
- package/docs/zh/guides/troubleshooting/cli.mdx +6 -30
- package/docs/zh/guides/troubleshooting/dependencies.mdx +23 -23
- package/docs/zh/guides/upgrade/_meta.json +1 -0
- package/docs/zh/guides/upgrade/config.mdx +809 -0
- package/docs/zh/guides/upgrade/entry.mdx +463 -0
- package/docs/zh/guides/upgrade/other.md +90 -0
- package/docs/zh/guides/upgrade/overview.mdx +36 -0
- package/docs/zh/guides/upgrade/tailwindcss.mdx +130 -0
- package/docs/zh/guides/upgrade/web-server.md +93 -0
- package/docs/zh/plugin/cli-plugins/api.mdx +4 -5
- package/docs/zh/plugin/cli-plugins/migration.mdx +30 -45
- package/docs/zh/plugin/introduction.mdx +36 -24
- package/docs/zh/plugin/official/_meta.json +0 -5
- package/docs/zh/plugin/official/cli-plugins/_meta.json +1 -1
- package/docs/zh/plugin/official/cli-plugins/plugin-styled-components.mdx +5 -0
- package/docs/zh/plugin/official/cli-plugins.mdx +0 -2
- package/docs/zh/plugin/plugin-system.mdx +45 -42
- package/docs/zh/plugin/runtime-plugins/api.mdx +58 -56
- package/docs/zh/plugin/runtime-plugins/migration.mdx +26 -17
- package/docs/zh/tutorials/_meta.json +0 -10
- package/docs/zh/tutorials/examples/csr-auth.mdx +1 -1
- package/docs/zh/tutorials/foundations/introduction.mdx +8 -25
- package/i18n.json +0 -16
- package/package.json +12 -12
- package/rspress.config.ts +5 -8
- package/src/components/ContentCard/index.module.scss +11 -7
- package/src/components/ContentCard/index.tsx +1 -1
- package/src/components/FeatureLayout/index.module.css +1 -1
- package/src/components/Footer/index.tsx +2 -14
- package/src/components/Footer/styles.module.scss +5 -5
- package/src/components/ListCard/index.tsx +1 -1
- package/src/components/RandomMemberList/index.tsx +1 -1
- package/src/components/RsbuildLink/index.tsx +1 -1
- package/src/components/Sandpack/index.tsx +1 -1
- package/src/custom.scss +15 -0
- package/src/i18n/enUS.ts +2 -4
- package/src/i18n/index.ts +1 -1
- package/src/i18n/zhCN.ts +2 -4
- package/src/index.ts +2 -1
- package/src/pages/index.module.scss +59 -41
- package/src/pages/index.tsx +9 -24
- package/docs/en/apis/app/hooks/server/index_.mdx +0 -10
- package/docs/en/apis/app/hooks/src/index_.mdx +0 -38
- package/docs/en/apis/app/hooks/src/stories.mdx +0 -16
- package/docs/en/apis/app/runtime/app/define-config.mdx +0 -67
- package/docs/en/apis/app/runtime/core/bootstrap.mdx +0 -74
- package/docs/en/apis/app/runtime/core/create-app.mdx +0 -49
- package/docs/en/apis/app/runtime/core/use-loader.mdx +0 -89
- package/docs/en/apis/app/runtime/core/use-module-apps.mdx +0 -140
- package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +0 -116
- package/docs/en/apis/app/runtime/model/Provider.mdx +0 -36
- package/docs/en/apis/app/runtime/model/auto-actions.mdx +0 -122
- package/docs/en/apis/app/runtime/model/connect.mdx +0 -146
- package/docs/en/apis/app/runtime/model/create-app.mdx +0 -75
- package/docs/en/apis/app/runtime/model/create-store.mdx +0 -61
- package/docs/en/apis/app/runtime/model/handle-effect.mdx +0 -107
- package/docs/en/apis/app/runtime/model/model_.mdx +0 -198
- package/docs/en/apis/app/runtime/model/use-local-model.mdx +0 -29
- package/docs/en/apis/app/runtime/model/use-model.mdx +0 -89
- package/docs/en/apis/app/runtime/model/use-static-model.mdx +0 -51
- package/docs/en/apis/app/runtime/model/use-store.mdx +0 -26
- package/docs/en/apis/app/runtime/ssr/pre-render.mdx +0 -96
- package/docs/en/apis/app/runtime/web-server/hook.mdx +0 -134
- package/docs/en/apis/app/runtime/web-server/middleware.mdx +0 -113
- package/docs/en/apis/app/runtime/web-server/unstable_middleware.mdx +0 -167
- package/docs/en/components/bff-proxy-path-rewrite.mdx +0 -16
- package/docs/en/components/bff-proxy-principle.mdx +0 -1
- package/docs/en/components/builder.mdx +0 -3
- package/docs/en/components/create-bff-api-app.mdx +0 -25
- package/docs/en/components/custom-router-micro-frontend.mdx +0 -40
- package/docs/en/components/enable-micro-frontend.mdx +0 -30
- package/docs/en/components/enableSwc.mdx +0 -17
- package/docs/en/components/global-proxy-config.mdx +0 -85
- package/docs/en/components/global-proxy.mdx +0 -29
- package/docs/en/components/package-manager.mdx +0 -11
- package/docs/en/components/reduck-notify.mdx +0 -27
- package/docs/en/components/reduck-tip.mdx +0 -8
- package/docs/en/configure/app/auto-load-plugin.mdx +0 -66
- package/docs/en/configure/app/deploy/microFrontend.mdx +0 -53
- package/docs/en/configure/app/dev/port.mdx +0 -25
- package/docs/en/configure/app/dev/proxy.mdx +0 -9
- package/docs/en/configure/app/experiments/lazy-compilation.mdx +0 -106
- package/docs/en/configure/app/html/disable-html-folder.mdx +0 -46
- package/docs/en/configure/app/html/favicon-by-entries.mdx +0 -36
- package/docs/en/configure/app/html/inject-by-entries.mdx +0 -36
- package/docs/en/configure/app/html/meta-by-entries.mdx +0 -48
- package/docs/en/configure/app/html/tags-by-entries.mdx +0 -44
- package/docs/en/configure/app/html/template-by-entries.mdx +0 -33
- package/docs/en/configure/app/html/template-parameters-by-entries.mdx +0 -35
- package/docs/en/configure/app/html/title-by-entries.mdx +0 -37
- package/docs/en/configure/app/output/css-module-local-ident-name.mdx +0 -21
- package/docs/en/configure/app/output/disable-css-extract.mdx +0 -16
- package/docs/en/configure/app/output/disable-filename-hash.mdx +0 -16
- package/docs/en/configure/app/output/disable-minimize.mdx +0 -14
- package/docs/en/configure/app/output/disable-node-polyfill.mdx +0 -22
- package/docs/en/configure/app/output/disable-source-map.mdx +0 -31
- package/docs/en/configure/app/output/enable-asset-fallback.mdx +0 -36
- package/docs/en/configure/app/output/enable-inline-scripts.mdx +0 -22
- package/docs/en/configure/app/output/enable-inline-styles.mdx +0 -22
- package/docs/en/configure/app/output/enable-latest-decorators.mdx +0 -14
- package/docs/en/configure/app/performance/transform-lodash.mdx +0 -52
- package/docs/en/configure/app/runtime/master-app.mdx +0 -36
- package/docs/en/configure/app/runtime/state.mdx +0 -52
- package/docs/en/configure/app/source/disable-entry-dirs.mdx +0 -38
- package/docs/en/configure/app/source/enable-custom-entry.mdx +0 -68
- package/docs/en/configure/app/source/module-scopes.mdx +0 -72
- package/docs/en/configure/app/source/resolve-extension-prefix.mdx +0 -55
- package/docs/en/configure/app/source/resolve-main-fields.mdx +0 -46
- package/docs/en/configure/app/tools/esbuild.mdx +0 -44
- package/docs/en/configure/app/tools/pug.mdx +0 -54
- package/docs/en/configure/app/tools/styled-components.mdx +0 -55
- package/docs/en/configure/app/tools/tailwindcss.mdx +0 -98
- package/docs/en/configure/app/tools/terser.mdx +0 -58
- package/docs/en/configure/app/tools/ts-loader.mdx +0 -76
- package/docs/en/configure/app/tools/webpack-chain.mdx +0 -249
- package/docs/en/configure/app/tools/webpack.mdx +0 -305
- package/docs/en/guides/deprecated.md +0 -17
- package/docs/en/guides/topic-detail/micro-frontend/c01-introduction.mdx +0 -27
- package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +0 -290
- package/docs/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +0 -298
- package/docs/en/guides/topic-detail/micro-frontend/c04-communicate.mdx +0 -58
- package/docs/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +0 -26
- package/docs/en/guides/topic-detail/model/_meta.json +0 -14
- package/docs/en/guides/topic-detail/model/auto-actions.mdx +0 -85
- package/docs/en/guides/topic-detail/model/computed-state.mdx +0 -148
- package/docs/en/guides/topic-detail/model/define-model.mdx +0 -62
- package/docs/en/guides/topic-detail/model/faq.mdx +0 -35
- package/docs/en/guides/topic-detail/model/manage-effects.mdx +0 -247
- package/docs/en/guides/topic-detail/model/model-communicate.mdx +0 -217
- package/docs/en/guides/topic-detail/model/performance.mdx +0 -167
- package/docs/en/guides/topic-detail/model/quick-start.mdx +0 -117
- package/docs/en/guides/topic-detail/model/redux-integration.mdx +0 -20
- package/docs/en/guides/topic-detail/model/typescript-best-practice.mdx +0 -68
- package/docs/en/guides/topic-detail/model/use-model.mdx +0 -243
- package/docs/en/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -46
- package/docs/en/plugin/official/cli-plugins/plugin-swc.mdx +0 -363
- package/docs/en/plugin/official/cli-plugins/plugin-tailwind.mdx +0 -5
- package/docs/en/plugin/official/rsbuild-plugins/_meta.json +0 -1
- package/docs/en/plugin/official/rsbuild-plugins/plugin-esbuild.mdx +0 -205
- package/docs/en/plugin/official/rsbuild-plugins.mdx +0 -3
- package/docs/en/tutorials/first-app/c01-start.mdx +0 -99
- package/docs/en/tutorials/first-app/c02-component.mdx +0 -60
- package/docs/en/tutorials/first-app/c03-css.mdx +0 -324
- package/docs/en/tutorials/first-app/c04-routes.mdx +0 -172
- package/docs/en/tutorials/first-app/c05-loader.mdx +0 -87
- package/docs/en/tutorials/first-app/c06-model.mdx +0 -278
- package/docs/en/tutorials/first-app/c07-container.mdx +0 -281
- package/docs/en/tutorials/first-app/c08-entries.mdx +0 -135
- package/docs/zh/apis/app/hooks/server/index_.mdx +0 -10
- package/docs/zh/apis/app/hooks/src/index_.mdx +0 -39
- package/docs/zh/apis/app/hooks/src/stories.mdx +0 -16
- package/docs/zh/apis/app/runtime/app/define-config.mdx +0 -67
- package/docs/zh/apis/app/runtime/core/bootstrap.mdx +0 -74
- package/docs/zh/apis/app/runtime/core/create-app.mdx +0 -35
- package/docs/zh/apis/app/runtime/core/use-loader.mdx +0 -89
- package/docs/zh/apis/app/runtime/core/use-module-apps.mdx +0 -179
- package/docs/zh/apis/app/runtime/core/use-runtime-context.mdx +0 -116
- package/docs/zh/apis/app/runtime/model/Provider.mdx +0 -36
- package/docs/zh/apis/app/runtime/model/auto-actions.mdx +0 -122
- package/docs/zh/apis/app/runtime/model/connect.mdx +0 -143
- package/docs/zh/apis/app/runtime/model/create-app.mdx +0 -75
- package/docs/zh/apis/app/runtime/model/create-store.mdx +0 -61
- package/docs/zh/apis/app/runtime/model/handle-effect.mdx +0 -108
- package/docs/zh/apis/app/runtime/model/model_.mdx +0 -201
- package/docs/zh/apis/app/runtime/model/use-local-model.mdx +0 -29
- package/docs/zh/apis/app/runtime/model/use-model.mdx +0 -89
- package/docs/zh/apis/app/runtime/model/use-static-model.mdx +0 -49
- package/docs/zh/apis/app/runtime/model/use-store.mdx +0 -26
- package/docs/zh/apis/app/runtime/ssr/pre-render.mdx +0 -96
- package/docs/zh/apis/app/runtime/web-server/hook.mdx +0 -136
- package/docs/zh/apis/app/runtime/web-server/middleware.mdx +0 -114
- package/docs/zh/apis/app/runtime/web-server/unstable_middleware.mdx +0 -165
- package/docs/zh/components/bff-proxy-path-rewrite.mdx +0 -16
- package/docs/zh/components/bff-proxy-principle.mdx +0 -1
- package/docs/zh/components/builder.mdx +0 -3
- package/docs/zh/components/create-bff-api-app.mdx +0 -25
- package/docs/zh/components/custom-router-micro-frontend.mdx +0 -40
- package/docs/zh/components/enable-micro-frontend.mdx +0 -30
- package/docs/zh/components/enableSwc.mdx +0 -17
- package/docs/zh/components/global-proxy-config.mdx +0 -85
- package/docs/zh/components/global-proxy.mdx +0 -29
- package/docs/zh/components/package-manager.mdx +0 -11
- package/docs/zh/components/reduck-notify.mdx +0 -27
- package/docs/zh/components/reduck-tip.mdx +0 -8
- package/docs/zh/configure/app/auto-load-plugin.mdx +0 -66
- package/docs/zh/configure/app/deploy/microFrontend.mdx +0 -55
- package/docs/zh/configure/app/dev/port.mdx +0 -25
- package/docs/zh/configure/app/dev/proxy.mdx +0 -9
- package/docs/zh/configure/app/experiments/lazy-compilation.mdx +0 -105
- package/docs/zh/configure/app/html/disable-html-folder.mdx +0 -45
- package/docs/zh/configure/app/html/favicon-by-entries.mdx +0 -37
- package/docs/zh/configure/app/html/inject-by-entries.mdx +0 -37
- package/docs/zh/configure/app/html/meta-by-entries.mdx +0 -48
- package/docs/zh/configure/app/html/tags-by-entries.mdx +0 -44
- package/docs/zh/configure/app/html/template-by-entries.mdx +0 -33
- package/docs/zh/configure/app/html/template-parameters-by-entries.mdx +0 -36
- package/docs/zh/configure/app/html/title-by-entries.mdx +0 -37
- package/docs/zh/configure/app/output/css-module-local-ident-name.mdx +0 -21
- package/docs/zh/configure/app/output/disable-css-extract.mdx +0 -16
- package/docs/zh/configure/app/output/disable-filename-hash.mdx +0 -16
- package/docs/zh/configure/app/output/disable-minimize.mdx +0 -14
- package/docs/zh/configure/app/output/disable-node-polyfill.mdx +0 -22
- package/docs/zh/configure/app/output/disable-source-map.mdx +0 -31
- package/docs/zh/configure/app/output/enable-asset-fallback.mdx +0 -36
- package/docs/zh/configure/app/output/enable-inline-scripts.mdx +0 -22
- package/docs/zh/configure/app/output/enable-inline-styles.mdx +0 -22
- package/docs/zh/configure/app/output/enable-latest-decorators.mdx +0 -14
- package/docs/zh/configure/app/performance/transform-lodash.mdx +0 -52
- package/docs/zh/configure/app/runtime/master-app.mdx +0 -38
- package/docs/zh/configure/app/runtime/state.mdx +0 -52
- package/docs/zh/configure/app/source/disable-entry-dirs.mdx +0 -38
- package/docs/zh/configure/app/source/enable-custom-entry.mdx +0 -67
- package/docs/zh/configure/app/source/module-scopes.mdx +0 -72
- package/docs/zh/configure/app/source/resolve-extension-prefix.mdx +0 -57
- package/docs/zh/configure/app/source/resolve-main-fields.mdx +0 -46
- package/docs/zh/configure/app/tools/esbuild.mdx +0 -44
- package/docs/zh/configure/app/tools/pug.mdx +0 -54
- package/docs/zh/configure/app/tools/styled-components.mdx +0 -54
- package/docs/zh/configure/app/tools/tailwindcss.mdx +0 -98
- package/docs/zh/configure/app/tools/terser.mdx +0 -58
- package/docs/zh/configure/app/tools/ts-loader.mdx +0 -76
- package/docs/zh/configure/app/tools/webpack-chain.mdx +0 -253
- package/docs/zh/configure/app/tools/webpack.mdx +0 -305
- package/docs/zh/guides/advanced-features/rspack-start.mdx +0 -154
- package/docs/zh/guides/deprecated.md +0 -19
- package/docs/zh/guides/topic-detail/micro-frontend/c01-introduction.mdx +0 -26
- package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +0 -332
- package/docs/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +0 -296
- package/docs/zh/guides/topic-detail/micro-frontend/c04-communicate.mdx +0 -58
- package/docs/zh/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +0 -27
- package/docs/zh/guides/topic-detail/model/_meta.json +0 -14
- package/docs/zh/guides/topic-detail/model/auto-actions.mdx +0 -88
- package/docs/zh/guides/topic-detail/model/computed-state.mdx +0 -147
- package/docs/zh/guides/topic-detail/model/define-model.mdx +0 -63
- package/docs/zh/guides/topic-detail/model/faq.mdx +0 -36
- package/docs/zh/guides/topic-detail/model/manage-effects.mdx +0 -256
- package/docs/zh/guides/topic-detail/model/model-communicate.mdx +0 -217
- package/docs/zh/guides/topic-detail/model/performance.mdx +0 -167
- package/docs/zh/guides/topic-detail/model/quick-start.mdx +0 -117
- package/docs/zh/guides/topic-detail/model/redux-integration.mdx +0 -20
- package/docs/zh/guides/topic-detail/model/typescript-best-practice.mdx +0 -67
- package/docs/zh/guides/topic-detail/model/use-model.mdx +0 -248
- package/docs/zh/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -46
- package/docs/zh/plugin/official/cli-plugins/plugin-swc.mdx +0 -351
- package/docs/zh/plugin/official/cli-plugins/plugin-tailwind.mdx +0 -5
- package/docs/zh/plugin/official/rsbuild-plugins/_meta.json +0 -1
- package/docs/zh/plugin/official/rsbuild-plugins/plugin-esbuild.mdx +0 -201
- package/docs/zh/plugin/official/rsbuild-plugins.mdx +0 -3
- package/docs/zh/tutorials/first-app/c01-start.mdx +0 -99
- package/docs/zh/tutorials/first-app/c02-component.mdx +0 -60
- package/docs/zh/tutorials/first-app/c03-css.mdx +0 -323
- package/docs/zh/tutorials/first-app/c04-routes.mdx +0 -172
- package/docs/zh/tutorials/first-app/c05-loader.mdx +0 -89
- package/docs/zh/tutorials/first-app/c06-model.mdx +0 -274
- package/docs/zh/tutorials/first-app/c07-container.mdx +0 -281
- package/docs/zh/tutorials/first-app/c08-entries.mdx +0 -135
- /package/docs/en/components/{reduck-migration.mdx → auto-upgrade.mdx} +0 -0
- /package/docs/{zh/components/reduck-migration.mdx → en/components/international/platform-support.mdx} +0 -0
|
@@ -1,332 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 2
|
|
3
|
-
title: 体验微前端
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# 体验微前端
|
|
7
|
-
|
|
8
|
-
通过本章你可以了解到:
|
|
9
|
-
|
|
10
|
-
- 如何创建微前端项目的主应用、子应用。
|
|
11
|
-
- 微前端项目开发的基本流程。
|
|
12
|
-
|
|
13
|
-
## 创建应用
|
|
14
|
-
|
|
15
|
-
目前项目的路由模式分为以下三种
|
|
16
|
-
|
|
17
|
-
- [约定式路由](/guides/concept/entries.html#约定式路由)
|
|
18
|
-
- [自控式路由](/guides/concept/entries.html#自控式路由)
|
|
19
|
-
- 其他 (项目自行安装和使用 `react-router-dom`)
|
|
20
|
-
|
|
21
|
-
在本教程中我们会为主应用创建两个子应用 Table 和 Dashboard (Table 为约定式路由,Dashboard 为自控式路由)
|
|
22
|
-
|
|
23
|
-
### 创建约定式路由主应用
|
|
24
|
-
|
|
25
|
-
通过命令行工具初始化项目:
|
|
26
|
-
|
|
27
|
-
```bash
|
|
28
|
-
mkdir masterApp && cd masterApp
|
|
29
|
-
npx @modern-js/create@latest
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
import DefaultMWAGenerate from '@site-docs/components/default-mwa-generate';
|
|
33
|
-
|
|
34
|
-
<DefaultMWAGenerate />
|
|
35
|
-
|
|
36
|
-
完成项目创建后我们可以通过 `pnpm run new` 来开启 `微前端` 功能:
|
|
37
|
-
|
|
38
|
-
```bash
|
|
39
|
-
? 请选择你想要的操作 启用可选功能
|
|
40
|
-
? 请选择功能名称 启用「微前端」模式
|
|
41
|
-
```
|
|
42
|
-
|
|
43
|
-
接下来,让我们注册微前端插件并添加开启微前端主应用,并增加子应用列表:
|
|
44
|
-
|
|
45
|
-
import EnableMicroFrontend from '@site-docs/components/enable-micro-frontend';
|
|
46
|
-
|
|
47
|
-
<EnableMicroFrontend />
|
|
48
|
-
|
|
49
|
-
然后我们在 routes 文件夹下新建两个目录
|
|
50
|
-
|
|
51
|
-
- table (用于加载约定式路由子应用)
|
|
52
|
-
- dashboard (用于加载自控式路由子应用)
|
|
53
|
-
|
|
54
|
-
在这两个目录下我们需要新建一个 `$.tsx` 文件作为主应用约定式路由的入口($ 代表模糊匹配,即 `/table` 和 `/table/test` 都会匹配到这个 `$.tsx` 作为该路由的入口文件,这会保证在微前端场景下正确加载子应用路由)
|
|
55
|
-
|
|
56
|
-
#### 加载约定式路由子应用
|
|
57
|
-
|
|
58
|
-
```js title="src/routes/table/$.tsx"
|
|
59
|
-
import { useModuleApps } from '@modern-js/plugin-garfish/runtime';
|
|
60
|
-
|
|
61
|
-
const Index = () => {
|
|
62
|
-
const { Table } = useModuleApps();
|
|
63
|
-
|
|
64
|
-
return (
|
|
65
|
-
<div>
|
|
66
|
-
<Table />
|
|
67
|
-
</div>
|
|
68
|
-
);
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
export default Index;
|
|
72
|
-
```
|
|
73
|
-
|
|
74
|
-
#### 加载自控式路由子应用
|
|
75
|
-
|
|
76
|
-
```js title="src/routes/dashboard/$.tsx"
|
|
77
|
-
import { useModuleApps } from '@modern-js/plugin-garfish/runtime';
|
|
78
|
-
|
|
79
|
-
const Index = () => {
|
|
80
|
-
const { Dashboard } = useModuleApps();
|
|
81
|
-
|
|
82
|
-
return (
|
|
83
|
-
<div>
|
|
84
|
-
<Dashboard />
|
|
85
|
-
</div>
|
|
86
|
-
);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
export default Index;
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
#### 路由跳转
|
|
93
|
-
|
|
94
|
-
此时主应用配置已经完成,通过路由即可加载子应用,修改主应用的 `layout.tsx` 来跳转路由
|
|
95
|
-
|
|
96
|
-
```js title="src/route/layout.tsx"
|
|
97
|
-
import { Outlet, Link } from '@modern-js/runtime/router';
|
|
98
|
-
|
|
99
|
-
const Layout = () => (
|
|
100
|
-
<div>
|
|
101
|
-
<div>
|
|
102
|
-
<Link to={'/table'}>加载约定式路由子应用</Link>
|
|
103
|
-
</div>
|
|
104
|
-
<div>
|
|
105
|
-
<Link to={'/dashboard'}>加载自控式路由子应用</Link>
|
|
106
|
-
</div>
|
|
107
|
-
<div>
|
|
108
|
-
<Link to={'/'}>卸载子应用</Link>
|
|
109
|
-
</div>
|
|
110
|
-
<Outlet />
|
|
111
|
-
</div>
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
export default Layout;
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
### 创建自控式路由主应用
|
|
118
|
-
|
|
119
|
-
通过命令行工具初始化项目:
|
|
120
|
-
|
|
121
|
-
```bash
|
|
122
|
-
mkdir masterApp && cd masterApp
|
|
123
|
-
npx @modern-js/create@latest
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
<DefaultMWAGenerate />
|
|
127
|
-
|
|
128
|
-
完成项目创建后我们可以通过 `pnpm run new` 来开启 `微前端` 功能:
|
|
129
|
-
|
|
130
|
-
```bash
|
|
131
|
-
? 请选择你想要的操作 启用可选功能
|
|
132
|
-
? 请选择功能名称 启用「微前端」模式
|
|
133
|
-
```
|
|
134
|
-
|
|
135
|
-
接下来,让我们注册微前端插件并添加开启微前端主应用,并增加子应用列表:
|
|
136
|
-
|
|
137
|
-
<EnableMicroFrontend />
|
|
138
|
-
|
|
139
|
-
由于是自控式路由,我们删除掉 `routes` 文件夹并在 `src` 目录下增加 `App.tsx` 文件,此处如果使用的 `非 MApp` 组件,需要通过 `React Router v6` 的 `createBrowserRouter` API 来创建路由
|
|
140
|
-
|
|
141
|
-
#### 加载子应用
|
|
142
|
-
|
|
143
|
-
import CustomRouterMicroFrontend from '@site-docs/components/custom-router-micro-frontend';
|
|
144
|
-
|
|
145
|
-
<CustomRouterMicroFrontend />
|
|
146
|
-
|
|
147
|
-
### 创建其他主应用
|
|
148
|
-
|
|
149
|
-
项目内自己安装和使用 `react-router-dom` , 与自控式路由唯一的区别是, 设置 `router: false` 后 plugin-garfish 无法获得 `useLocation` `useHref` 等 hook 来辅助计算 basename 和主子应用路由同步
|
|
150
|
-
|
|
151
|
-
import { Tab, Tabs } from 'rspress/theme';
|
|
152
|
-
|
|
153
|
-
<Tabs>
|
|
154
|
-
<Tab label="react-router-dom@6">
|
|
155
|
-
```tsx
|
|
156
|
-
import { useLocation, useHref } from 'react-router-dom';
|
|
157
|
-
const App = () => {
|
|
158
|
-
const basename = useHref('/table');
|
|
159
|
-
const { Table } = useModuleApps();
|
|
160
|
-
return <Table useLocation={useLocation} basename={basename} />;
|
|
161
|
-
};
|
|
162
|
-
```
|
|
163
|
-
</Tab>
|
|
164
|
-
<Tab label="react-router-dom@5">
|
|
165
|
-
```tsx
|
|
166
|
-
import { useLocation, useHistory } from 'react-router-dom';
|
|
167
|
-
const App = () => {
|
|
168
|
-
const history = useHistory();
|
|
169
|
-
const basename = history.createHref({ pathname: '/table' });
|
|
170
|
-
const { Table } = useModuleApps();
|
|
171
|
-
return <Table useLocation={useLocation} basename={basename} />;
|
|
172
|
-
};
|
|
173
|
-
```
|
|
174
|
-
</Tab>
|
|
175
|
-
</Tabs>
|
|
176
|
-
|
|
177
|
-
### 创建约定式路由子应用
|
|
178
|
-
|
|
179
|
-
通过命令行工具初始化项目:
|
|
180
|
-
|
|
181
|
-
```bash
|
|
182
|
-
mkdir table && cd table
|
|
183
|
-
npx @modern-js/create@latest
|
|
184
|
-
```
|
|
185
|
-
|
|
186
|
-
按照如下选择,生成项目:
|
|
187
|
-
|
|
188
|
-
<DefaultMWAGenerate />
|
|
189
|
-
|
|
190
|
-
我们执行 `pnpm run new` 来开启 `微前端` 功能:
|
|
191
|
-
|
|
192
|
-
```bash
|
|
193
|
-
? 请选择你想要的操作 启用可选功能
|
|
194
|
-
? 请选择功能名称 启用「微前端」模式
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
接下来,让我们注册微前端插件并修改 `modern.config.ts`,添加微前端子应用的配置 `deploy.microFrontend`:
|
|
198
|
-
|
|
199
|
-
```js title="modern.config.ts"
|
|
200
|
-
import { appTools, defineConfig } from '@modern-js/app-tools';
|
|
201
|
-
import { garfishPlugin } from '@modern-js/plugin-garfish';
|
|
202
|
-
|
|
203
|
-
export default defineConfig({
|
|
204
|
-
dev: {
|
|
205
|
-
port: 8081,
|
|
206
|
-
},
|
|
207
|
-
runtime: {
|
|
208
|
-
router: true,
|
|
209
|
-
},
|
|
210
|
-
deploy: {
|
|
211
|
-
microFrontend: true,
|
|
212
|
-
},
|
|
213
|
-
plugins: [appTools(), garfishPlugin()],
|
|
214
|
-
});
|
|
215
|
-
```
|
|
216
|
-
|
|
217
|
-
添加 `src/routes/page.tsx` 代码
|
|
218
|
-
|
|
219
|
-
```js title="src/routes/page.tsx"
|
|
220
|
-
const Index = () => {
|
|
221
|
-
return (
|
|
222
|
-
<div className="container-box">subApp: 约定式路由的子应用的根路由</div>
|
|
223
|
-
);
|
|
224
|
-
};
|
|
225
|
-
|
|
226
|
-
export default Index;
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
### 创建自控式路由子应用
|
|
230
|
-
|
|
231
|
-
通过命令行工具初始化项目:
|
|
232
|
-
|
|
233
|
-
```bash
|
|
234
|
-
mkdir dashboard && cd dashboard
|
|
235
|
-
npx @modern-js/create@latest
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
按照如下选择,生成项目:
|
|
239
|
-
|
|
240
|
-
<DefaultMWAGenerate />
|
|
241
|
-
|
|
242
|
-
我们执行 `pnpm run new` 来开启 `微前端`:
|
|
243
|
-
|
|
244
|
-
```bash
|
|
245
|
-
? 请选择你想要的操作 启用可选功能
|
|
246
|
-
? 请选择功能名称 启用「微前端」模式
|
|
247
|
-
```
|
|
248
|
-
|
|
249
|
-
接下来,让我们注册微前端插件并修改 `modern.config.ts`,添加微前端子应用的配置 `deploy.microFrontend`:
|
|
250
|
-
|
|
251
|
-
```js title="modern.config.ts"
|
|
252
|
-
import { appTools, defineConfig } from '@modern-js/app-tools';
|
|
253
|
-
import { garfishPlugin } from '@modern-js/plugin-garfish';
|
|
254
|
-
|
|
255
|
-
export default defineConfig({
|
|
256
|
-
dev: {
|
|
257
|
-
port: 8082,
|
|
258
|
-
},
|
|
259
|
-
runtime: {
|
|
260
|
-
router: true,
|
|
261
|
-
},
|
|
262
|
-
deploy: {
|
|
263
|
-
microFrontend: true,
|
|
264
|
-
},
|
|
265
|
-
plugins: [appTools(), garfishPlugin()],
|
|
266
|
-
});
|
|
267
|
-
```
|
|
268
|
-
|
|
269
|
-
自控式路由需要删除掉 `routes` 文件夹并在 `src` 目录下新建 `App.tsx`
|
|
270
|
-
|
|
271
|
-
并在 `src/App.tsx` 添加代码,注意需要从 `props` 中解析并传递 `basename` 给 `BrowserRouter`
|
|
272
|
-
|
|
273
|
-
```js title="src/App.tsx"
|
|
274
|
-
import { BrowserRouter, Route, Routes } from '@modern-js/runtime/router';
|
|
275
|
-
|
|
276
|
-
export default (props: { basename: string }) => {
|
|
277
|
-
const { basename } = props;
|
|
278
|
-
|
|
279
|
-
return (
|
|
280
|
-
<BrowserRouter basename={basename}>
|
|
281
|
-
<Routes>
|
|
282
|
-
<Route index element={<div>自控式路由子应用根路由</div>} />
|
|
283
|
-
<Route path={'path'} element={<div>自控式路由子应用子路由</div>} />
|
|
284
|
-
</Routes>
|
|
285
|
-
</BrowserRouter>
|
|
286
|
-
);
|
|
287
|
-
};
|
|
288
|
-
```
|
|
289
|
-
|
|
290
|
-
## 调试
|
|
291
|
-
|
|
292
|
-
按顺序在目录执行 `pnpm run dev` 命令启动应用:
|
|
293
|
-
|
|
294
|
-
- masterApp 主应用 `http://localhost:8080`
|
|
295
|
-
- table 子应用(约定式路由) `http://localhost:8081`
|
|
296
|
-
- dashboard 子应用(自控式路由) `http://localhost:8082`
|
|
297
|
-
|
|
298
|
-
访问主应用地址 `http://localhost:8080`
|
|
299
|
-
|
|
300
|
-
在完成了微前端整体开发流程的体验后,你可以进一步了解如何 [开发主应用](/guides/topic-detail/micro-frontend/c03-main-app)
|
|
301
|
-
|
|
302
|
-
## Modern.js 微前端和直接使用 Garfish 的区别
|
|
303
|
-
|
|
304
|
-
使用纯 `Garfish` API 开发微前端应用时
|
|
305
|
-
|
|
306
|
-
- 主应用:
|
|
307
|
-
- 安装 Garfish 依赖并使用 `Garfish.run` 注册子应用 [参考](https://www.garfishjs.org/api/run.html)
|
|
308
|
-
- 提供一个常驻的 `DOM` 节点供子应用挂载 [参考](https://www.garfishjs.org/api/registerApp.html)
|
|
309
|
-
- 子应用:
|
|
310
|
-
- 导出 `provider` [参考](https://www.garfishjs.org/guide/quick-start/start.html#2%E5%AF%BC%E5%87%BA-provider-%E5%87%BD%E6%95%B0)
|
|
311
|
-
- 设置应用的 `basename` [参考](https://www.garfishjs.org/guide/quick-start/start.html#3-%E8%AE%BE%E7%BD%AE%E5%BA%94%E7%94%A8%E8%B7%AF%E7%94%B1-basename)
|
|
312
|
-
|
|
313
|
-
区别于直接使用 `Garfish` 运行时 API 开发微前端项目,`Modern.js` 的微前端方案更加开箱即用。
|
|
314
|
-
使用 `pnpm new` 启用微前端模式后会自动在 `Modern.js` 应用中集成 `Garfish` 插件,在 `Garfish`
|
|
315
|
-
插件的加持下,你只需要
|
|
316
|
-
|
|
317
|
-
- 主应用:
|
|
318
|
-
- 配置 `runtime.masterApp.apps` 参数注册子应用
|
|
319
|
-
- 使用 `useModuleApps` API 获取子应用实例并在组件中完成渲染
|
|
320
|
-
- 子应用:
|
|
321
|
-
- 配置 `deploy.microFrontend`
|
|
322
|
-
|
|
323
|
-
所以插件中为你做了如下事情
|
|
324
|
-
|
|
325
|
-
- 帮助你通过 `Garfish` 运行时 API 自动注册子应用(主应用)
|
|
326
|
-
- `useModulesApps` 函数的返回值提供了一个常驻的 `DOM` 节点供子应用挂载(主应用)
|
|
327
|
-
- 帮助你正确导出了 `provider`(子应用)
|
|
328
|
-
- 帮助你正确设置了 `basename` 给 `Modern.js` 运行时提供 `Router` 实例,如果是`自控式路由`或`手动引入的 react-router-dom` 那么需要从 `App.tsx` 的 `props` 中获取 `basename` 手动传递给引入的 `Router 实例`(子应用)
|
|
329
|
-
|
|
330
|
-
## 常见问题
|
|
331
|
-
|
|
332
|
-
自查手册: https://www.garfishjs.org/issues/
|
|
@@ -1,296 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 3
|
|
3
|
-
title: 开发主应用
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# 开发主应用
|
|
7
|
-
|
|
8
|
-
在上一章 [体验微前端](/guides/topic-detail/micro-frontend/c02-development) 通过一个示例演示了如何创建和配置微前端子应用,通过本章你可以进一步了解如何开发主应用,以及它的常见配置。
|
|
9
|
-
|
|
10
|
-
在通过 `@modern-js/create` 命令创建 Modern.js 工程后,可以在项目中执行 `pnpm run new`(实际执行了 `modern new` 命令),在选择了「微前端」模式后,会安装微前端依赖依赖,只需手动注册插件即可。
|
|
11
|
-
|
|
12
|
-
import EnableMicroFrontend from '@site-docs/components/enable-micro-frontend';
|
|
13
|
-
|
|
14
|
-
<EnableMicroFrontend />
|
|
15
|
-
|
|
16
|
-
## 注册子应用信息
|
|
17
|
-
|
|
18
|
-
当在 `masterApp` 配置上提供了信息后,将会认为该应用为主应用,目前存在两种子应用信息的配置方式,这两种方式分别应用于不同的场景。
|
|
19
|
-
|
|
20
|
-
### 直接注册子应用信息
|
|
21
|
-
|
|
22
|
-
可以直接通过配置注册子应用信息:
|
|
23
|
-
|
|
24
|
-
:::tip 提示
|
|
25
|
-
可以通过 API [defineConfig](/apis/app/runtime/app/define-config) 在运行时进行配置。
|
|
26
|
-
当参数为函数时无法被序列化到产物代码,所以在涉及到函数之类的配置时请通过 defineConfig 来进行配置
|
|
27
|
-
|
|
28
|
-
:::
|
|
29
|
-
|
|
30
|
-
import MicroRuntimeConfig from '@site-docs/components/micro-runtime-config';
|
|
31
|
-
|
|
32
|
-
<MicroRuntimeConfig />
|
|
33
|
-
|
|
34
|
-
### 自定义远程应用列表
|
|
35
|
-
|
|
36
|
-
通过该函数可以拉取远程的子应用列表,并将其注册至运行时框架:
|
|
37
|
-
|
|
38
|
-
```ts title="src/modern.runtime.ts"
|
|
39
|
-
import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
40
|
-
|
|
41
|
-
export default defineRuntimeConfig({
|
|
42
|
-
masterApp: {
|
|
43
|
-
manifest: {
|
|
44
|
-
getAppList: async () => {
|
|
45
|
-
// 可以从其他远程接口获取
|
|
46
|
-
return [
|
|
47
|
-
{
|
|
48
|
-
name: 'Table',
|
|
49
|
-
entry: 'http://localhost:8081',
|
|
50
|
-
// activeWhen: '/table'
|
|
51
|
-
},
|
|
52
|
-
{
|
|
53
|
-
name: 'Dashboard',
|
|
54
|
-
entry: 'http://localhost:8082',
|
|
55
|
-
// activeWhen: '/dashboard'
|
|
56
|
-
},
|
|
57
|
-
];
|
|
58
|
-
},
|
|
59
|
-
},
|
|
60
|
-
},
|
|
61
|
-
});
|
|
62
|
-
```
|
|
63
|
-
|
|
64
|
-
## 渲染子应用
|
|
65
|
-
|
|
66
|
-
在微前端中分为两种加载子应用的方式:
|
|
67
|
-
|
|
68
|
-
1. **子应用组件** 获取到每个子应用的组件,之后就可以像使用普通的 `React` 组件一样渲染微前端的子应用。
|
|
69
|
-
2. **集中式路由** 通过集中式的路由配置,自动根据当前页面 `pathname` 激活渲染对应的子应用。
|
|
70
|
-
|
|
71
|
-
### 子应用组件
|
|
72
|
-
|
|
73
|
-
开发者使用 `useModuleApps` 方法可以获取到各个子应用的组件。
|
|
74
|
-
|
|
75
|
-
再通过 `router` 组件的结合运用,开发者可以自控式的根据不同的路由渲染不同的子应用。
|
|
76
|
-
|
|
77
|
-
假设我们的子应用列表配置如下:
|
|
78
|
-
|
|
79
|
-
<EnableMicroFrontend />
|
|
80
|
-
|
|
81
|
-
编辑主应用 `App.tsx` 文件如下:
|
|
82
|
-
|
|
83
|
-
```js title="App.tsx"
|
|
84
|
-
import { useModuleApps } from '@modern-js/plugin-garfish/runtime';
|
|
85
|
-
|
|
86
|
-
import {
|
|
87
|
-
RouterProvider,
|
|
88
|
-
Route,
|
|
89
|
-
createBrowserRouter,
|
|
90
|
-
createRoutesFromElements,
|
|
91
|
-
BrowserRouter,
|
|
92
|
-
Link,
|
|
93
|
-
Outlet,
|
|
94
|
-
} from '@modern-js/runtime/router';
|
|
95
|
-
|
|
96
|
-
const AppLayout = () => (
|
|
97
|
-
<>
|
|
98
|
-
<div>
|
|
99
|
-
<Link to={'/table'}>加载约定式路由子应用</Link>
|
|
100
|
-
</div>
|
|
101
|
-
<div>
|
|
102
|
-
<Link to={'/dashboard'}>加载自控式路由子应用</Link>
|
|
103
|
-
</div>
|
|
104
|
-
<div>
|
|
105
|
-
<Link to={'/'}>卸载子应用</Link>
|
|
106
|
-
</div>
|
|
107
|
-
<Outlet />
|
|
108
|
-
</>
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
export default () => {
|
|
112
|
-
const { apps, MApp } = useModuleApps();
|
|
113
|
-
|
|
114
|
-
// 使用的不是 MApp 组件,需要使用 createBrowserRouter 来创建路由
|
|
115
|
-
const router = createBrowserRouter(
|
|
116
|
-
createRoutesFromElements(
|
|
117
|
-
<Route path="/" element={<AppLayout />}>
|
|
118
|
-
{apps.map(app => {
|
|
119
|
-
const { Component } = app;
|
|
120
|
-
// 模糊匹配,path 需要写成类似 abc/* 的模式
|
|
121
|
-
return (
|
|
122
|
-
<Route
|
|
123
|
-
key={app.name}
|
|
124
|
-
path={`${app.name.toLowerCase()}/*`}
|
|
125
|
-
element={
|
|
126
|
-
<Component
|
|
127
|
-
loadable={{
|
|
128
|
-
loading: ({ pastDelay, error }: any) => {
|
|
129
|
-
if (error) {
|
|
130
|
-
return <div>error: {error?.message}</div>;
|
|
131
|
-
} else if (pastDelay) {
|
|
132
|
-
return <div>loading</div>;
|
|
133
|
-
} else {
|
|
134
|
-
return null;
|
|
135
|
-
}
|
|
136
|
-
},
|
|
137
|
-
}}
|
|
138
|
-
/>
|
|
139
|
-
}
|
|
140
|
-
/>
|
|
141
|
-
);
|
|
142
|
-
})}
|
|
143
|
-
</Route>,
|
|
144
|
-
),
|
|
145
|
-
);
|
|
146
|
-
|
|
147
|
-
return (
|
|
148
|
-
// 方法一:使用 MApp 自动根据配置的 activeWhen 参数加载子应用(本项目配置在 modern.config.ts 中)
|
|
149
|
-
// <BrowserRouter>
|
|
150
|
-
// <MApp />
|
|
151
|
-
// </BrowserRouter>
|
|
152
|
-
|
|
153
|
-
// 方法二:手动写 Route 组件方式加载子应用,方便于需要鉴权等需要前置操作的场景
|
|
154
|
-
<>
|
|
155
|
-
<RouterProvider router={router} />
|
|
156
|
-
</>
|
|
157
|
-
);
|
|
158
|
-
};
|
|
159
|
-
```
|
|
160
|
-
|
|
161
|
-
这里通过 `Route` 组件自定义了 **Table** 的激活路由为 **/table**, **Dashboard** 的激活路由为 **/dashboard**。
|
|
162
|
-
|
|
163
|
-
### 集中式路由
|
|
164
|
-
|
|
165
|
-
**集中式路由** 是将子应用的激活路由集中配置的方式。我们给子应用列表信息添加 `activeWhen` 字段来启用 **集中式路由**。
|
|
166
|
-
|
|
167
|
-
<MicroRuntimeConfig />
|
|
168
|
-
|
|
169
|
-
然后在主应用中使用 `useModuleApp` 方法获取 `MApp` 组件, 并在主应用渲染 `MApp`。
|
|
170
|
-
|
|
171
|
-
```tsx title=主应用:App.tsx
|
|
172
|
-
import { useModuleApp } from '@modern-js/plugin-garfish/runtime';
|
|
173
|
-
|
|
174
|
-
function App() {
|
|
175
|
-
const { MApp } = useModuleApps();
|
|
176
|
-
|
|
177
|
-
return (
|
|
178
|
-
<div>
|
|
179
|
-
<MApp />
|
|
180
|
-
</div>
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
```
|
|
184
|
-
|
|
185
|
-
这样启动应用后,访问 `/table` 路由,会渲染 `Table` 子应用,访问 `/dashboard` 路由,会渲染 `Dashboard` 子应用。
|
|
186
|
-
|
|
187
|
-
### 两种模式混用
|
|
188
|
-
|
|
189
|
-
当然 **子应用组件** 和 **集中式路由** 是可以混合使用的。
|
|
190
|
-
|
|
191
|
-
- 一部分子应用作为 **子应用组件** 激活,另外一部分作为 **集中式路由** 激活。
|
|
192
|
-
- 一部分子应用既可以作为 **集中式路由** 激活,也可以作为 **子应用组件** 激活。
|
|
193
|
-
|
|
194
|
-
### 添加 loading
|
|
195
|
-
|
|
196
|
-
通过配置 `loadable` 配置,可以为「集中式路由」、「子应用」添加 loading 组件,并可以考虑错误、超时、闪烁等情况的出现,从而为用户提供更好的用户体验。该功能的设计与实现参考至 [react-loadable](https://github.com/jamiebuilds/react-loadable),基本功能较为相似。
|
|
197
|
-
|
|
198
|
-
```tsx
|
|
199
|
-
function Loading() {
|
|
200
|
-
return <div>Loading...</div>;
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
function App(){
|
|
204
|
-
return <>
|
|
205
|
-
<Table
|
|
206
|
-
loadable={{
|
|
207
|
-
loading: Loading,
|
|
208
|
-
}}
|
|
209
|
-
/>
|
|
210
|
-
<>
|
|
211
|
-
}
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
#### 增加错误状态
|
|
215
|
-
|
|
216
|
-
当微前端子应用加载失败或渲染失败时,`loading component` 将会接收 `error` 参数(若没有错误时 error 是 null)
|
|
217
|
-
|
|
218
|
-
```tsx
|
|
219
|
-
function Loading({ error }) {
|
|
220
|
-
if (error) {
|
|
221
|
-
return <div>Error msg {error?.message}</div>;
|
|
222
|
-
} else {
|
|
223
|
-
return <div>Loading...</div>;
|
|
224
|
-
}
|
|
225
|
-
}
|
|
226
|
-
```
|
|
227
|
-
|
|
228
|
-
#### 避免 loading 闪退
|
|
229
|
-
|
|
230
|
-
有时 loading 组件的显示时间可能小于 200ms,这个时候会出现 loading 组件闪退的情况。许多用户研究证明,loading 闪退的情况会导致用户感知加载内容的耗时比实际耗时更长,在 loading 小于 200ms 时,不展示内容,用户会认为它更快。
|
|
231
|
-
|
|
232
|
-
所以 loading 组件还提供了 `pastDelay` 参数,超过设置的延迟展示时才会为 true,可以通过 `delay` 参数设置延迟的时长
|
|
233
|
-
|
|
234
|
-
```tsx
|
|
235
|
-
function Loading({ error, pastDelay }) {
|
|
236
|
-
if (error) {
|
|
237
|
-
return <div>Error! {error?.message}</div>;
|
|
238
|
-
} else if (pastDelay) {
|
|
239
|
-
return <div>Loading...</div>;
|
|
240
|
-
} else {
|
|
241
|
-
return null;
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
```
|
|
245
|
-
|
|
246
|
-
`delay` 的默认值为 `200ms`,可以通过 `loadable` 中的 `delay` 来设置延迟展示的时间
|
|
247
|
-
|
|
248
|
-
```tsx
|
|
249
|
-
|
|
250
|
-
function App(){
|
|
251
|
-
return <>
|
|
252
|
-
<Table
|
|
253
|
-
loadable={{
|
|
254
|
-
loading: Loading,
|
|
255
|
-
delay: 300 // 0.3 seconds
|
|
256
|
-
}}
|
|
257
|
-
/>
|
|
258
|
-
<>
|
|
259
|
-
}
|
|
260
|
-
```
|
|
261
|
-
|
|
262
|
-
#### 增加超时状态
|
|
263
|
-
|
|
264
|
-
有时因为网络的原因,从而导致微前端子应用加载失败,从而导致一直展示 loading 的状态,这对于用户而言非常糟糕,因为他们不知道合适才会获得具体的响应,他们是否需要刷新页面,通过增加超时状态可以很好的解决该问题。
|
|
265
|
-
|
|
266
|
-
loading 组件在超时时会获得 `timeOut` 参数,当微前端应用加载超时时将会获得 `timeOut` 属性值为 true
|
|
267
|
-
|
|
268
|
-
```tsx
|
|
269
|
-
function Loading({ error, timeOut, pastDelay }) {
|
|
270
|
-
if (error) {
|
|
271
|
-
return <div>Error! {error?.message}</div>;
|
|
272
|
-
} else if (timeOut) {
|
|
273
|
-
return <div>Loading timed out, please refresh the page... </div>;
|
|
274
|
-
} else if (pastDelay) {
|
|
275
|
-
return <div>Loading...</div>;
|
|
276
|
-
} else {
|
|
277
|
-
return null;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
```
|
|
281
|
-
|
|
282
|
-
超时状态是关闭的,可以通过在 `loadable` 中设置 `timeout` 参数开启
|
|
283
|
-
|
|
284
|
-
```tsx
|
|
285
|
-
|
|
286
|
-
function App(){
|
|
287
|
-
return <>
|
|
288
|
-
<Table
|
|
289
|
-
loadable={{
|
|
290
|
-
loading: Loading,
|
|
291
|
-
timeOut: 10000 // 10s
|
|
292
|
-
}}
|
|
293
|
-
/>
|
|
294
|
-
<>
|
|
295
|
-
}
|
|
296
|
-
```
|
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 4
|
|
3
|
-
title: 主子应用通信
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# 主子应用通信
|
|
7
|
-
|
|
8
|
-
## props 通信
|
|
9
|
-
|
|
10
|
-
Modern.js 中,会将子应用包裹成一个 React 组件,直接通过给 React 组件传递 `props` 即可实现主应用和子应用通信的目的。
|
|
11
|
-
|
|
12
|
-
```tsx title=主应用:App.tsx
|
|
13
|
-
function App() {
|
|
14
|
-
const { MApp } = useModuleApps();
|
|
15
|
-
|
|
16
|
-
return (
|
|
17
|
-
<div>
|
|
18
|
-
<MApp count={100} />
|
|
19
|
-
</div>
|
|
20
|
-
);
|
|
21
|
-
}
|
|
22
|
-
```
|
|
23
|
-
|
|
24
|
-
```tsx title=子应用:App.tsx
|
|
25
|
-
function App(props) {
|
|
26
|
-
console.log(props);
|
|
27
|
-
return ...
|
|
28
|
-
}
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
子应用将会打印 `{count: 0}`,目前尚未支持子应用渲染响应式,及时在主应用上更改 `count` 的数据也不会触发视图更新
|
|
32
|
-
|
|
33
|
-
## channel 通信
|
|
34
|
-
|
|
35
|
-
[Garfish.channel](https://www.garfishjs.org/api/channel) 用于应用间的通信。它是 `EventEmitter2` 的实例
|
|
36
|
-
|
|
37
|
-
```ts
|
|
38
|
-
// 子应用监听登录事件
|
|
39
|
-
const App = () => {
|
|
40
|
-
const handleLogin = userInfo => {
|
|
41
|
-
console.log(`${userInfo.name} has login`);
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
window?.Garfish.channel.on('login', handleLogin);
|
|
46
|
-
return () => {
|
|
47
|
-
window?.Garfish.channel.removeListener('login', handleLogin);
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
// 主应用触发监听事件
|
|
53
|
-
api.getLoginInfo.then(res => {
|
|
54
|
-
if (res.code === 0) {
|
|
55
|
-
window.Garfish.channel.emit('login', res.data);
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
```
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
sidebar_position: 5
|
|
3
|
-
title: 混合技术栈
|
|
4
|
-
---
|
|
5
|
-
|
|
6
|
-
# 混合技术栈
|
|
7
|
-
|
|
8
|
-
Modern.js 微前端方案是基于 [Garfish](https://garfishjs.org/) 封装的,提供了一些更开箱即用的使用方式。
|
|
9
|
-
|
|
10
|
-
当你的主应用和子应用不全是 Modern.js 应用的时候,可以参考这篇文档。
|
|
11
|
-
|
|
12
|
-
1. 子应用是 **Modern.js**,主应用使用的原生 Garfish 微前端。
|
|
13
|
-
2. 主应用是 **Modern.js**,子应用有的是其它技术栈。
|
|
14
|
-
|
|
15
|
-
## 子应用是 Modern.js
|
|
16
|
-
|
|
17
|
-
**Modern.js** 子应用编译后会生成标准的 [Garfish 子应用导出](https://www.garfishjs.org/guide/start#2%E5%AF%BC%E5%87%BA-provider-%E5%87%BD%E6%95%B0)。
|
|
18
|
-
所以可以直接接入标准的微前端主应用。
|
|
19
|
-
|
|
20
|
-
:::info
|
|
21
|
-
子应用是 **Modern.js**,主应用使用的原生 Garfish 微前端时,**子应用调试模式** 不可用。
|
|
22
|
-
|
|
23
|
-
:::
|
|
24
|
-
|
|
25
|
-
## 主应用是 Modern.js
|
|
26
|
-
|
|
27
|
-
主应用是 **Modern.js**,子应用用的其它技术栈。子应用按照 [Garfish 子应用标准](https://www.garfishjs.org/guide/demo/react) 开发即可。
|