@modern-js/main-doc 2.69.7 → 3.0.0-alpha.1
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 +8 -33
- 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 +19 -17
- package/docs/en/components/build-output.mdx +45 -0
- package/docs/en/components/bundler.mdx +1 -1
- 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 +42 -8
- package/docs/en/components/enable-ssg.mdx +49 -0
- package/docs/en/components/entry-scan-logic.mdx +7 -0
- package/docs/en/components/esbuild.mdx +2 -2
- package/docs/en/components/extend-bff-function.mdx +2 -4
- package/docs/en/components/hono.mdx +119 -0
- package/docs/en/components/init-app.mdx +40 -17
- package/docs/en/components/international/custom-instance-code.mdx +16 -0
- package/docs/en/components/international/init-options-desc.mdx +1 -0
- package/docs/en/components/international/install-command.mdx +23 -0
- package/docs/en/components/international/instance-code.mdx +26 -0
- package/docs/en/components/international/introduce.mdx +2 -0
- package/docs/en/components/module-federation.mdx +4 -4
- 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-config-deploy.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/builder-plugins.mdx +1 -2
- package/docs/en/configure/app/dev/lazy-compilation.mdx +45 -0
- package/docs/en/configure/app/dev/server.mdx +211 -0
- package/docs/en/configure/app/dev/setup-middlewares.mdx +4 -22
- package/docs/en/configure/app/experiments/source-build.mdx +0 -1
- package/docs/en/configure/app/html/app-icon.mdx +1 -23
- package/docs/en/configure/app/output/assets-retry.mdx +1 -1
- package/docs/en/configure/app/output/disable-inline-runtime-chunk.mdx +2 -2
- package/docs/en/configure/app/output/filename.mdx +2 -4
- 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/output/temp-dir.mdx +3 -3
- package/docs/en/configure/app/performance/build-cache.mdx +1 -5
- package/docs/en/configure/app/performance/profile.mdx +1 -1
- package/docs/en/configure/app/plugins.mdx +1 -3
- 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/runtime/router.mdx +0 -4
- package/docs/en/configure/app/security/check-syntax.mdx +1 -1
- package/docs/en/configure/app/security/sri.mdx +0 -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/alias.mdx +1 -1
- package/docs/en/configure/app/source/decorators.mdx +4 -2
- package/docs/en/configure/app/source/enable-async-entry.mdx +1 -1
- package/docs/en/configure/app/source/entries.mdx +0 -2
- package/docs/en/configure/app/source/include.mdx +2 -14
- 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 +22 -256
- 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 +5 -27
- package/docs/en/guides/_meta.json +5 -1
- package/docs/en/guides/advanced-features/_meta.json +6 -0
- package/docs/en/guides/advanced-features/bff/_meta.json +9 -1
- package/docs/en/guides/advanced-features/bff/cross-project.mdx +2 -8
- package/docs/en/guides/advanced-features/bff/extend-server.mdx +18 -3
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -15
- package/docs/en/guides/advanced-features/bff/function.mdx +6 -10
- package/docs/en/guides/advanced-features/bff/operators.mdx +628 -0
- package/docs/en/guides/advanced-features/bff/sdk.mdx +20 -12
- package/docs/en/guides/advanced-features/bff/upload.mdx +3 -1
- 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 +428 -0
- package/docs/en/guides/advanced-features/international/locale-detection.mdx +276 -0
- package/docs/en/guides/advanced-features/international/quick-start.mdx +126 -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 +8 -22
- package/docs/en/guides/advanced-features/page-performance/react-compiler.mdx +19 -12
- package/docs/en/guides/advanced-features/rspack-start.mdx +3 -23
- package/docs/en/guides/advanced-features/server-monitor/logger.mdx +0 -4
- package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +121 -36
- 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 +65 -77
- package/docs/en/guides/basic-features/data/data-fetch.mdx +19 -18
- 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 +6 -17
- 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 +399 -0
- package/docs/en/guides/basic-features/render/ssg.mdx +26 -67
- package/docs/en/guides/basic-features/render/ssr-cache.mdx +6 -10
- 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/svg-assets.mdx +0 -4
- package/docs/en/guides/basic-features/static-assets.mdx +2 -2
- package/docs/en/guides/concept/builder.mdx +27 -12
- 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 +4 -71
- package/docs/en/guides/get-started/tech-stack.mdx +7 -27
- 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/guides/upgrade/_meta.json +1 -0
- package/docs/en/guides/upgrade/config.mdx +936 -0
- package/docs/en/guides/upgrade/entry.mdx +463 -0
- package/docs/en/guides/upgrade/other.mdx +83 -0
- package/docs/en/guides/upgrade/overview.mdx +33 -0
- package/docs/en/guides/upgrade/tailwindcss.mdx +130 -0
- package/docs/en/guides/upgrade/web-server.mdx +91 -0
- package/docs/en/plugin/_meta.json +5 -0
- package/docs/en/plugin/cli-plugins/_meta.json +1 -1
- package/docs/en/plugin/cli-plugins/api.mdx +17 -68
- package/docs/en/plugin/cli-plugins/life-cycle.mdx +0 -4
- package/docs/en/plugin/introduction.mdx +44 -44
- 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 +69 -62
- package/docs/en/plugin/runtime-plugins/_meta.json +1 -1
- package/docs/en/plugin/runtime-plugins/api.mdx +62 -59
- package/docs/en/plugin/server-plugins/_meta.json +1 -0
- package/docs/en/plugin/server-plugins/api.mdx +210 -1
- package/docs/en/plugin/server-plugins/life-cycle.mdx +41 -1
- 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 +8 -33
- 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-operator-code.mdx +5 -0
- package/docs/zh/components/bff-upload.mdx +8 -7
- package/docs/zh/components/build-output.mdx +45 -0
- package/docs/zh/components/bundler.mdx +1 -1
- 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 +41 -8
- package/docs/zh/components/enable-ssg.mdx +49 -0
- package/docs/zh/components/entry-scan-logic.mdx +7 -0
- package/docs/zh/components/esbuild.mdx +2 -2
- package/docs/zh/components/extend-bff-function.mdx +2 -4
- package/docs/zh/components/hono.mdx +119 -0
- package/docs/zh/components/init-app.mdx +40 -18
- package/docs/zh/components/international/custom-instance-code.mdx +16 -0
- package/docs/zh/components/international/init-options-desc.mdx +1 -0
- package/docs/zh/components/international/install-command.mdx +23 -0
- package/docs/zh/components/international/instance-code.mdx +26 -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/components/upgrade-config-deploy.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/builder-plugins.mdx +1 -2
- package/docs/zh/configure/app/dev/lazy-compilation.mdx +44 -0
- package/docs/zh/configure/app/dev/server.mdx +211 -0
- package/docs/zh/configure/app/dev/setup-middlewares.mdx +4 -23
- package/docs/zh/configure/app/experiments/source-build.mdx +0 -1
- package/docs/zh/configure/app/html/app-icon.mdx +1 -23
- package/docs/zh/configure/app/output/assets-retry.mdx +1 -1
- package/docs/zh/configure/app/output/disable-inline-runtime-chunk.mdx +2 -2
- package/docs/zh/configure/app/output/filename.mdx +2 -4
- 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/output/temp-dir.mdx +3 -3
- package/docs/zh/configure/app/performance/build-cache.mdx +1 -5
- package/docs/zh/configure/app/performance/profile.mdx +1 -1
- package/docs/zh/configure/app/plugins.mdx +1 -2
- 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/runtime/router.mdx +0 -4
- package/docs/zh/configure/app/security/check-syntax.mdx +1 -1
- package/docs/zh/configure/app/security/sri.mdx +0 -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/alias.mdx +1 -1
- package/docs/zh/configure/app/source/decorators.mdx +4 -4
- package/docs/zh/configure/app/source/enable-async-entry.mdx +1 -1
- package/docs/zh/configure/app/source/entries.mdx +0 -2
- package/docs/zh/configure/app/source/include.mdx +2 -16
- 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 +6 -28
- 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/_meta.json +9 -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 +2 -16
- package/docs/zh/guides/advanced-features/bff/function.mdx +7 -12
- package/docs/zh/guides/advanced-features/bff/operators.mdx +628 -0
- package/docs/zh/guides/advanced-features/bff/sdk.mdx +23 -16
- package/docs/zh/guides/advanced-features/bff/upload.mdx +3 -1
- 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 +432 -0
- package/docs/zh/guides/advanced-features/international/locale-detection.mdx +304 -0
- package/docs/zh/guides/advanced-features/international/quick-start.mdx +126 -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 +8 -22
- package/docs/zh/guides/advanced-features/page-performance/react-compiler.mdx +19 -12
- package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +0 -4
- package/docs/zh/guides/advanced-features/server-monitor/monitors.mdx +120 -37
- 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 +55 -59
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +14 -16
- 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 +4 -15
- 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 +399 -0
- package/docs/zh/guides/basic-features/render/ssg.mdx +27 -69
- package/docs/zh/guides/basic-features/render/ssr-cache.mdx +5 -9
- 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/svg-assets.mdx +0 -4
- 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 +26 -11
- 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 -28
- 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 -31
- package/docs/zh/guides/troubleshooting/builder.mdx +4 -85
- 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 +940 -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/_meta.json +5 -0
- package/docs/zh/plugin/cli-plugins/_meta.json +1 -1
- package/docs/zh/plugin/cli-plugins/api.mdx +19 -70
- package/docs/zh/plugin/cli-plugins/life-cycle.mdx +0 -4
- package/docs/zh/plugin/introduction.mdx +40 -40
- 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 +43 -51
- package/docs/zh/plugin/runtime-plugins/_meta.json +1 -1
- package/docs/zh/plugin/runtime-plugins/api.mdx +58 -56
- package/docs/zh/plugin/server-plugins/_meta.json +1 -0
- package/docs/zh/plugin/server-plugins/api.mdx +210 -1
- package/docs/zh/plugin/server-plugins/life-cycle.mdx +41 -1
- 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/FrameworkCode/index.tsx +605 -0
- 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/bundle-analyze.mdx +0 -24
- 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/babel.mdx +0 -225
- 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 -253
- package/docs/en/configure/app/tools/webpack.mdx +0 -309
- 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/cli-plugins/migration.mdx +0 -98
- 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/plugin/runtime-plugins/migration.mdx +0 -101
- 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/default-mwa-generate.mdx +0 -4
- 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/bundle-analyze.mdx +0 -24
- 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/babel.mdx +0 -224
- 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 -257
- package/docs/zh/configure/app/tools/webpack.mdx +0 -309
- 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/cli-plugins/migration.mdx +0 -98
- 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/plugin/runtime-plugins/migration.mdx +0 -101
- 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/en/components/{router-legacy-tip.mdx → international/platform-support.mdx} +0 -0
- /package/docs/{zh/components/reduck-migration.mdx → en/components/new-entry-tooltip.mdx} +0 -0
- /package/docs/{zh/components/router-legacy-tip.mdx → en/components/upgrade-browserslist.mdx} +0 -0
|
@@ -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) 开发即可。
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
# 自动生成 Actions
|
|
2
|
-
|
|
3
|
-
在 [快速上手](/guides/topic-detail/model/quick-start) 中,我们实现最简单的计数器 Model 也需要 10 行代码。
|
|
4
|
-
实际上,Modern.js 支持根据声明的 `state` 类型,自动生成常用的 Actions,从而简化模板代码量。当前支持的类型有:
|
|
5
|
-
|
|
6
|
-
- 原始数据类型
|
|
7
|
-
- 数组类型
|
|
8
|
-
- 简单对象类型(Plain Object)
|
|
9
|
-
|
|
10
|
-
## 原始数据类型
|
|
11
|
-
|
|
12
|
-
```ts
|
|
13
|
-
const countModel = model('count').define({ state: 1 });
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
如上我们仅用一行就完成了一个简单的 `countModel`。使用 Model 的示例代码如下:
|
|
17
|
-
|
|
18
|
-
```tsx
|
|
19
|
-
function Counter() {
|
|
20
|
-
const [state, actions] = useModel(countModel);
|
|
21
|
-
|
|
22
|
-
useEffect(() => {
|
|
23
|
-
// 增加 1
|
|
24
|
-
actions.setState(state + 1);
|
|
25
|
-
}, []);
|
|
26
|
-
}
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
## 数组类型
|
|
30
|
-
|
|
31
|
-
当 State 为数组类型时,自动生成 Actions 的示例代码如下:
|
|
32
|
-
|
|
33
|
-
```ts
|
|
34
|
-
const countModel = model('count').define({ state: [] });
|
|
35
|
-
|
|
36
|
-
function Counter() {
|
|
37
|
-
const [state, actions] = useModel(countModel);
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
actions.push(1);
|
|
41
|
-
actions.pop();
|
|
42
|
-
actions.shift();
|
|
43
|
-
actions.unshift(1);
|
|
44
|
-
actions.concat([1]);
|
|
45
|
-
actions.splice(0, 1, 2);
|
|
46
|
-
actions.filter(value => value > 1);
|
|
47
|
-
}, []);
|
|
48
|
-
}
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
我们可以使用 JavaScript Array 对象的方法,修改 State。
|
|
52
|
-
|
|
53
|
-
## 简单对象类型
|
|
54
|
-
|
|
55
|
-
当 State 为简单对象类型时,自动生成 Actions 的示例代码如下:
|
|
56
|
-
|
|
57
|
-
```ts
|
|
58
|
-
const countModel = model('count').define({
|
|
59
|
-
state: {
|
|
60
|
-
a: 1,
|
|
61
|
-
b: [],
|
|
62
|
-
c: {},
|
|
63
|
-
},
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
function Counter() {
|
|
67
|
-
const [state, actions] = useModel(countModel);
|
|
68
|
-
|
|
69
|
-
useEffect(() => {
|
|
70
|
-
actions.setA(2);
|
|
71
|
-
actions.setB([1]);
|
|
72
|
-
actions.setC({ a: 1 });
|
|
73
|
-
}, []);
|
|
74
|
-
}
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
根据 `a`、`b`、`c` 三个不同的字段分别生成 `setA`、`setB`、`setC` 三个 Actions。
|
|
78
|
-
|
|
79
|
-
:::info
|
|
80
|
-
当用户自定义的 Action 和 Modern.js 自动生成的 Action 名字一致时,用户自定义的 Action 优先级更高。例如,
|
|
81
|
-
在 `countModel` 中已经自定义 `setA` 这个 Action,调用 `actions.setA()` 时,最终执行的是用户自定义的 `setA`。
|
|
82
|
-
|
|
83
|
-
:::
|
|
84
|
-
|
|
85
|
-
:::info 补充信息
|
|
86
|
-
相关 API 的更多介绍,请参考[这里](/apis/app/runtime/model/auto-actions)。
|
|
87
|
-
|
|
88
|
-
:::
|
|
@@ -1,147 +0,0 @@
|
|
|
1
|
-
# 衍生状态
|
|
2
|
-
|
|
3
|
-
一些场景中,组件需要对 Model 中的 State 进行进一步计算,才能在组件中使用,这部分逻辑可以直接写在组件内部,也可以通过 Model 的衍生状态实现。
|
|
4
|
-
衍生状态定义在 Model 中的 `computed` 字段下。根据依赖的 Model 的不同、返回类型的不同,衍生状态的定义方法可以分为以下 3 种。
|
|
5
|
-
|
|
6
|
-
## 只依赖自身的 State
|
|
7
|
-
|
|
8
|
-
衍生状态只依赖当前 Model 的 State,State 会作为第一个参数,传入衍生状态的定义函数中。
|
|
9
|
-
|
|
10
|
-
例如, todo 应用的 State 有 `items` 和 `filter`,`filter` 用于过滤当前页面显示的 todo 项,所以我们定义了一个 `visibleTodos` 的衍生状态可以直接在组件中使用。示例代码如下:
|
|
11
|
-
|
|
12
|
-
```ts
|
|
13
|
-
/**
|
|
14
|
-
* 假设 todo item 结构如下:
|
|
15
|
-
{
|
|
16
|
-
id: string; // id
|
|
17
|
-
text: string; // todo 事项
|
|
18
|
-
completed: boolean; // 完成状态:0 代表未完成,1 代表完成
|
|
19
|
-
}
|
|
20
|
-
**/
|
|
21
|
-
|
|
22
|
-
const todoModel = model('todo').define({
|
|
23
|
-
state: {
|
|
24
|
-
items: [],
|
|
25
|
-
filter: 'ALL', // ALL: 显示全部;COMPLETED:显示完成的事项;ACTIVE:显示未完成的事项
|
|
26
|
-
},
|
|
27
|
-
computed: {
|
|
28
|
-
visibleTodos: state => {
|
|
29
|
-
switch (state.filter) {
|
|
30
|
-
case 'ALL':
|
|
31
|
-
return state.items;
|
|
32
|
-
case 'COMPLETED':
|
|
33
|
-
return todos.filter(t => t.completed);
|
|
34
|
-
case 'ACTIVE':
|
|
35
|
-
return todos.filter(t => !t.completed);
|
|
36
|
-
default:
|
|
37
|
-
return [];
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
},
|
|
41
|
-
});
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
衍生状态最终会和 Model 的 State 进行合并,因此,可以通过 Model 的 State 对象访问到衍生状态,例如,`visibleTodos` 在组件内的使用方式如下:
|
|
45
|
-
|
|
46
|
-
```ts
|
|
47
|
-
function Todo() {
|
|
48
|
-
const [state, actions] = useModel(todoModel);
|
|
49
|
-
|
|
50
|
-
return (
|
|
51
|
-
<div>
|
|
52
|
-
<div>
|
|
53
|
-
{state.visibleTodos.map(item => (
|
|
54
|
-
<div key={item.id}>{item.text}</div>
|
|
55
|
-
))}
|
|
56
|
-
</div>
|
|
57
|
-
</div>
|
|
58
|
-
);
|
|
59
|
-
}
|
|
60
|
-
```
|
|
61
|
-
|
|
62
|
-
## 依赖其他 Model 的 State
|
|
63
|
-
|
|
64
|
-
除了依赖当前 Model 的 State,衍生状态还依赖其他 Model 的 State,这时候衍生状态的定义格式为:
|
|
65
|
-
|
|
66
|
-
```ts
|
|
67
|
-
[stateKey]: [...depModels, (selfState, ...depModels) => computedState]
|
|
68
|
-
```
|
|
69
|
-
|
|
70
|
-
下面的示例,演示了 `barModel` 的衍生状态 `combinedValue` 是如何依赖 `fooModel` 的 State 的。
|
|
71
|
-
|
|
72
|
-
```ts
|
|
73
|
-
const fooModel = model('foo').define({
|
|
74
|
-
state: {
|
|
75
|
-
value: 'foo',
|
|
76
|
-
},
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
const barModel = model('bar').define({
|
|
80
|
-
state: {
|
|
81
|
-
value: 'foo',
|
|
82
|
-
},
|
|
83
|
-
computed: {
|
|
84
|
-
combinedValue: [
|
|
85
|
-
fooModel,
|
|
86
|
-
(state, fooState) => state.value + fooState.value,
|
|
87
|
-
],
|
|
88
|
-
},
|
|
89
|
-
});
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
## 函数类型的衍生状态
|
|
93
|
-
|
|
94
|
-
衍生状态还可以返回一个函数。这时候衍生状态的定义格式为:
|
|
95
|
-
|
|
96
|
-
```ts
|
|
97
|
-
[stateKey]: (state) => (...args) => computedState // 只依赖自身的 state
|
|
98
|
-
[stateKey]: [...depModels, (selfState, ...depModels) => (...args) => computedState] // 依赖其他 Model 的 state
|
|
99
|
-
```
|
|
100
|
-
|
|
101
|
-
假设,todo 应用的 state 不存储 `filter` 状态,而是直接在组件中使用,那么 `visibleTodos` 可以是一个函数类型的值,这个函数在组件中使用的时候,接收 `filter` 参数。如下所示:
|
|
102
|
-
|
|
103
|
-
```ts
|
|
104
|
-
const todoModel = model('todo').define({
|
|
105
|
-
state: {
|
|
106
|
-
items: [],
|
|
107
|
-
},
|
|
108
|
-
computed: {
|
|
109
|
-
visibleTodos: state => filter => {
|
|
110
|
-
switch (filter) {
|
|
111
|
-
case 'ALL':
|
|
112
|
-
return state.items;
|
|
113
|
-
case 'COMPLETED':
|
|
114
|
-
return todos.filter(t => t.completed);
|
|
115
|
-
case 'ACTIVE':
|
|
116
|
-
return todos.filter(t => !t.completed);
|
|
117
|
-
default:
|
|
118
|
-
return [];
|
|
119
|
-
}
|
|
120
|
-
},
|
|
121
|
-
},
|
|
122
|
-
});
|
|
123
|
-
|
|
124
|
-
function Todo(props) {
|
|
125
|
-
// filter 状态通过 props 传入
|
|
126
|
-
const { filter } = props;
|
|
127
|
-
const [state, actions] = useModel(todoModel);
|
|
128
|
-
|
|
129
|
-
// 计算得到最终要显示的 todos
|
|
130
|
-
const todos = state.visibleTodos(filter);
|
|
131
|
-
|
|
132
|
-
return (
|
|
133
|
-
<div>
|
|
134
|
-
<div>
|
|
135
|
-
{todos.map(item => (
|
|
136
|
-
<div key={item.id}>{item.text}</div>
|
|
137
|
-
))}
|
|
138
|
-
</div>
|
|
139
|
-
</div>
|
|
140
|
-
);
|
|
141
|
-
}
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
:::info 更多参考
|
|
145
|
-
[使用 Model](/guides/topic-detail/model/computed-state)
|
|
146
|
-
|
|
147
|
-
:::
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# 创建 Model
|
|
2
|
-
|
|
3
|
-
上一节的计数器应用中,我们简单演示了如何创建一个 Model。本节我们将详细介绍 Model 的创建方法。
|
|
4
|
-
|
|
5
|
-
通过 `model` API 创建 Model,例如,`model('foo')` 表示要创建一个名为 `foo` 的 Model,通过调用 `model('foo')` 返回的 `define` 函数,定义 Model 包含的 State、Actions 等:
|
|
6
|
-
|
|
7
|
-
```js
|
|
8
|
-
import { model, useModel } from '@modern-js/runtime/model';
|
|
9
|
-
|
|
10
|
-
const fooModel = model('foo').define({
|
|
11
|
-
state: {
|
|
12
|
-
value: 'foo',
|
|
13
|
-
},
|
|
14
|
-
actions: {
|
|
15
|
-
setValue: (state, payload){
|
|
16
|
-
state.value = payload
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
:::info
|
|
23
|
-
|
|
24
|
-
- Model 中的 Action 中不能包含有副作用的逻辑,如请求 HTTP 接口,访问 localStorage 等。
|
|
25
|
-
- `setValue` 内部直接修改了入参 State,看起来是违反了纯函数的定义,实际上 Reduck 内部使用 [immer](https://github.com/immerjs/immer) 来修改不可变对象,保证了这种写法不会影响对象的不可变性,所以 `setValue` 仍然是一个纯函数。当然,你也可以直接在 Action 中返回一个新对象,不过这样的写法会更加复杂一些。
|
|
26
|
-
|
|
27
|
-
:::
|
|
28
|
-
|
|
29
|
-
`define` 接收的参数,只是对 Model 原始结构的描述:内部定义的 State、Actions 等。`define` 返回值 `fooModel` 才是真正创建得到的 Model 对象。例如,虽然 `setValue`,有 2 个参数,但是当真正调用 `setValue` 这个 Action 时,我们只需要传入 `payload` 一个参数,因为我们调用的是 `fooModel` 上的 Action 方法,而不是 Model 原始结构上描述的 Action 方法。详细参考[使用 Model](/guides/topic-detail/model/use-model)。
|
|
30
|
-
|
|
31
|
-
`define` 除了接收对象类型的参数,还可以接收函数类型的参数。例如:
|
|
32
|
-
|
|
33
|
-
```js
|
|
34
|
-
import { model, useModel } from '@modern-js/runtime/model';
|
|
35
|
-
|
|
36
|
-
const fooModel = model('foo').define((context, utils) => {
|
|
37
|
-
return {
|
|
38
|
-
state: {
|
|
39
|
-
value: 'foo',
|
|
40
|
-
},
|
|
41
|
-
actions: {
|
|
42
|
-
setValue: (state, payload){
|
|
43
|
-
state.value = payload
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
```
|
|
49
|
-
|
|
50
|
-
通过函数定义 Model 时,函数内部会自动传入 `context`、`utils` 2 个参数,`context` 是 Reduck 的上下文对象,可以获取到 `store` 对象,`utils` 提供了一组工具函数,方便实现 Model 通信等复杂功能需求。
|
|
51
|
-
|
|
52
|
-
Model 支持复制。例如:
|
|
53
|
-
|
|
54
|
-
```ts
|
|
55
|
-
const barModel = fooModel('bar');
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
barModel 是基于 fooModel 创建出一个的新的 Model 对象,类比面向对象编程语言中的概念,barModel 和 fooModel 是基于同一个类(Class)创建出的 2 个实例对象。当两个模块的状态管理逻辑相同,例如一个页面中的两个 tab 模块,使用的数据的结构和逻辑相同,区别只是从不同的接口获取数据,那么可以通过 Model 复制的方式,创建 2 个不同的 Model 对象。
|
|
59
|
-
|
|
60
|
-
:::info 补充信息
|
|
61
|
-
本节涉及的 API 的详细定义,请参考[这里](/apis/app/runtime/model/model_)。
|
|
62
|
-
|
|
63
|
-
:::
|