@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,117 +0,0 @@
|
|
|
1
|
-
# 快速上手
|
|
2
|
-
|
|
3
|
-
:::caution
|
|
4
|
-
新项目不再推荐使用 Reduck,可以使用社区中的状态管理工具,例如 [Jotai](https://jotai.org/)、[zustand](https://zustand.docs.pmnd.rs/getting-started/introduction)、[valtio](https://valtio.dev/docs/introduction/getting-started) 等。
|
|
5
|
-
:::
|
|
6
|
-
|
|
7
|
-
import ReduckNotify from '@site-docs/components/reduck-notify';
|
|
8
|
-
|
|
9
|
-
<ReduckNotify />
|
|
10
|
-
|
|
11
|
-
import ReduckMigration from '@site-docs/components/reduck-migration';
|
|
12
|
-
|
|
13
|
-
<ReduckMigration />
|
|
14
|
-
|
|
15
|
-
[Reduck](https://github.com/web-infra-dev/reduck) 是 Modern.js 团队开发的遵循 MVC 模式的状态管理库,底层状态存储基于 [Redux](https://redux.js.org/) 实现,同时提供更高层级的抽象,并完全兼容 Redux 生态。
|
|
16
|
-
|
|
17
|
-
Reduck 的目标是以 MVC 模式组织 React 应用开发结构,将业务逻辑维护在 Model 层,业务逻辑与 UI 解耦,让开发业务逻辑更集中、更简单,同时通过更高层级的抽象,减少重复工作(样板代码)。
|
|
18
|
-
|
|
19
|
-
Reduck 在 MVC 模式中,扮演 M(Model) 的角色,React UI Component 对应 V(View),从 Reduck 中获取 Model 并修改 Model 的 React Container Component 对应 C(View Controller/Container)。
|
|
20
|
-
|
|
21
|
-
Modern.js 的状态管理解决方案,是通过内置 Reduck 实现的。在 Modern.js 中使用 Reduck,不仅免去了手动集成的环节,而且所有 Reduck API 都可以从 Modern.js 的 Runtime 包中直接导入使用,具有更好的一致性体验。
|
|
22
|
-
|
|
23
|
-
:::info
|
|
24
|
-
|
|
25
|
-
Reduck 也可以脱离 Modern.js 作为状态管理库[单独使用](/guides/topic-detail/model/use-out-of-modernjs)。
|
|
26
|
-
|
|
27
|
-
:::
|
|
28
|
-
|
|
29
|
-
## 核心概念
|
|
30
|
-
|
|
31
|
-
Reduck 中的核心概念只有 4 个: Model、State、Actions、Effects。
|
|
32
|
-
|
|
33
|
-
Model: 对独立模块的逻辑和所需状态的封装,由 State、Actions、Effects 组成。
|
|
34
|
-
|
|
35
|
-
State: Model 中保存的状态。
|
|
36
|
-
|
|
37
|
-
Actions: 用于修改 State 的纯函数,函数必须是**同步**的。
|
|
38
|
-
|
|
39
|
-
Effects: 用于修改 State 的带有副作用的函数,函数可以是**异步**的。Effects 中可以调用自身或其他 Model 的 Actions 和 Effects。
|
|
40
|
-
|
|
41
|
-
Reduck 数据流如下图所示:
|
|
42
|
-
|
|
43
|
-

|
|
44
|
-
|
|
45
|
-
## 基本用法
|
|
46
|
-
|
|
47
|
-
下来我们以一个简单的 **计数器** 应用为例,演示 Reduck 的基本用法。
|
|
48
|
-
|
|
49
|
-
首先,我们定义一个名为 `count` 的 Model:
|
|
50
|
-
|
|
51
|
-
```js
|
|
52
|
-
import { model } from '@modern-js/runtime/model';
|
|
53
|
-
|
|
54
|
-
const countModel = model('count').define({
|
|
55
|
-
state: {
|
|
56
|
-
value: 1,
|
|
57
|
-
},
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
export default countModel;
|
|
61
|
-
```
|
|
62
|
-
|
|
63
|
-
我们使用 API `model` 创建 `countModel`,`countModel` 当前只包含存储计数器值的状态,即代码中的 `value`。
|
|
64
|
-
|
|
65
|
-
我们定义一个 action,用于计算器自增加 1:
|
|
66
|
-
|
|
67
|
-
```js
|
|
68
|
-
import { model } from '@modern-js/runtime/model';
|
|
69
|
-
|
|
70
|
-
const countModel = model('count').define({
|
|
71
|
-
state: {
|
|
72
|
-
value: 1,
|
|
73
|
-
},
|
|
74
|
-
actions: {
|
|
75
|
-
add(state) {
|
|
76
|
-
state.value += 1;
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
export default countModel;
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
在 `add` action 中,我们可以直接修改 state 的值,进行加 1 操作,而不需要把 state 作为不可变对象进行操作,这是因为 Reduck 集成了 [immer](https://github.com/immerjs/immer),可以直接修改原 state 对象。
|
|
85
|
-
|
|
86
|
-
接下来,我们演示如何在组件中使用 Model。
|
|
87
|
-
|
|
88
|
-
新建一个组件 Counter,在组件内通过 `useModel` API 使用 `countModel`:
|
|
89
|
-
|
|
90
|
-
```js
|
|
91
|
-
import { useModel } from '@modern-js/runtime/model';
|
|
92
|
-
import countModel from './models/count';
|
|
93
|
-
|
|
94
|
-
function Counter() {
|
|
95
|
-
const [state, actions] = useModel(countModel);
|
|
96
|
-
|
|
97
|
-
return (
|
|
98
|
-
<div>
|
|
99
|
-
<div>counter: {state.value}</div>
|
|
100
|
-
<button onClick={() => actions.add()}>add</button>
|
|
101
|
-
</div>
|
|
102
|
-
);
|
|
103
|
-
}
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
`useModel` 获取 `countModel` 的 `state` 和 `actions`,组件展示当前计算器的值,点击 `add` 按钮,计数器自增 1。
|
|
107
|
-
|
|
108
|
-
:::info
|
|
109
|
-
由于使用的案例比较简单,这里并没有严格按照 MVC 模式进行分层,组件 `Counter` 同时起到了 V 和 C 两层的作用。
|
|
110
|
-
|
|
111
|
-
:::
|
|
112
|
-
|
|
113
|
-
最终演示效果如下:
|
|
114
|
-
|
|
115
|
-

|
|
116
|
-
|
|
117
|
-
这样,我们就完了一个简单的计数器应用。本节完整的示例代码可以在[这里](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/runtime-api/counter-model)查看。
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
# Redux 生态集成
|
|
2
|
-
|
|
3
|
-
Reduck 基于 Redux 实现,因此可以使用 Redux [生态的库](https://redux.js.org/introduction/ecosystem),实现功能增强。通过 [`Provider`](/apis/app/runtime/model/Provider) 、[`createApp`](/apis/app/runtime/model/create-app) 和 [`createStore`](/apis/app/runtime/model/create-store) 等 API ,可以设置使用 Redux 的 [中间件](https://redux.js.org/understanding/thinking-in-redux/glossary#middleware) 和 [Store Enhancer](https://redux.js.org/understanding/thinking-in-redux/glossary#store-enhancer);使用 [`createStore`](/apis/app/runtime/model/create-store) 还可以完全掌控 Store 的创建过程。
|
|
4
|
-
|
|
5
|
-
例如,我们希望使用中间件 [`redux-logger`](https://github.com/LogRocket/redux-logger),示例代码如下:
|
|
6
|
-
|
|
7
|
-
```ts
|
|
8
|
-
ReactDOM.render(
|
|
9
|
-
<Provider config={{ middlewares: [logger] }}>
|
|
10
|
-
// 通过 Provider 的 config 参数设置 中间件
|
|
11
|
-
<App />
|
|
12
|
-
</Provider>,
|
|
13
|
-
document.getElementById('root'),
|
|
14
|
-
);
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
:::caution
|
|
18
|
-
Reduck 基于 Redux 底层 API 做了上层封装,屏蔽了 Redux 的一些底层概念,如 Reducer 等。Reduck 对于 Model 是动态挂载的,而 Redux 是在 Store 创建时就会挂载应用所需的全部状态。基于这些实现上的差异,有些 Redux 生态的库是无法直接在 Reduck 中使用的。
|
|
19
|
-
|
|
20
|
-
:::
|
|
@@ -1,67 +0,0 @@
|
|
|
1
|
-
# TS 最佳实践
|
|
2
|
-
|
|
3
|
-
Reduck 对 TS 提供了良好的支持,大部分使用场景下,无需任何额外工作,就可以直接获得 API 的 TS 类型提示。本节,将对其他的一些使用场景,做补充介绍。
|
|
4
|
-
|
|
5
|
-
## 定义 Model 的 State 类型
|
|
6
|
-
|
|
7
|
-
为 Model 的 State 声明类型信息,是在 TS 中使用 Reduck 的最佳实践。
|
|
8
|
-
|
|
9
|
-
```ts title="示例"
|
|
10
|
-
interface State {
|
|
11
|
-
data: string;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export const foo = model<State>('foo').define({
|
|
15
|
-
state: {
|
|
16
|
-
data: '',
|
|
17
|
-
},
|
|
18
|
-
computed: {
|
|
19
|
-
withSuffix: state => state.data + 'suffix',
|
|
20
|
-
},
|
|
21
|
-
actions: {
|
|
22
|
-
setData: (state, payload: string) => {
|
|
23
|
-
state.data = payload;
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
```
|
|
28
|
-
|
|
29
|
-
当为 Model 的 State 声明类型信息后,Model 的 `computed`、`actions` 都能获取正确的类型信息。事实上,上面的示例代码中,即使我们不定义 State 类型信息,也会根据 `state` 的初始值信息自动推导出 State 的类型信息。不过,仍然建议你在定义 Model 时,声明 State 的类型信息,因为根据 `state` 的初始值信息推导出的 State 类型信息可能不完整(缺少字段或字段的类型信息缺少),而且当使用[函数类型](/apis/app/runtime/model/model_#函数类型)定义 Model 时,State 的类型信息也是无法根据 `state` 的初始值信息自动推导的。
|
|
30
|
-
|
|
31
|
-
## 衍生状态的依赖类型
|
|
32
|
-
|
|
33
|
-
当 Model 的衍生状态依赖其他 Model 时,需要手动指定其他 Model 的 State。
|
|
34
|
-
|
|
35
|
-
```ts title="示例"
|
|
36
|
-
interface State {
|
|
37
|
-
data: string;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const bar = model<State>('bar').define({
|
|
41
|
-
state: {
|
|
42
|
-
data: '',
|
|
43
|
-
},
|
|
44
|
-
computed: {
|
|
45
|
-
// 为 fooState 指定类型
|
|
46
|
-
withFoo: [foo, (state, fooState: FooState) => state.data + fooState.data],
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
```
|
|
50
|
-
|
|
51
|
-
## 获取 Model 类型信息的 Hooks
|
|
52
|
-
|
|
53
|
-
Reduck 提供了一组用于获取 Model 类型信息的工具类型:
|
|
54
|
-
|
|
55
|
-
- `GetModelState`: 获取 Model 的 State(包含衍生状态)类型信息。
|
|
56
|
-
- `GetModelActions`:获取 Model 的 Actions(包含 Effects 函数)类型信息。
|
|
57
|
-
|
|
58
|
-
```ts title="示例"
|
|
59
|
-
export const foo = model<State2>('foo').define({
|
|
60
|
-
// 省略
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
// 获取 foo 的 State 类型
|
|
64
|
-
let fooActions: GetModelActions<typeof foo>;
|
|
65
|
-
// 获取 foo 的 Actions 类型
|
|
66
|
-
let fooState: GetModelState<typeof foo>;
|
|
67
|
-
```
|
|
@@ -1,248 +0,0 @@
|
|
|
1
|
-
# 使用 Model
|
|
2
|
-
|
|
3
|
-
## 在组件内使用
|
|
4
|
-
|
|
5
|
-
### 作为全局状态使用
|
|
6
|
-
|
|
7
|
-
通过 `useModel` 可以获取 Model 的 State、Actions 等。当 Model 的 State 通过 Actions 进行修改后,任何其他使用了该 Model 的组件,都会自动重新渲染。
|
|
8
|
-
|
|
9
|
-
在 [快速上手](/guides/topic-detail/model/quick-start) 的计数器案例中,我们已经演示了 `useModel` 的使用,不再重复。
|
|
10
|
-
|
|
11
|
-
`useModel` 支持传入多个 Model,多个 Model 的 State 和 Actions 会进行合并后作为返回结果。例如:
|
|
12
|
-
|
|
13
|
-
```ts
|
|
14
|
-
const fooModel = model('foo').define({
|
|
15
|
-
state: {
|
|
16
|
-
value: 1,
|
|
17
|
-
},
|
|
18
|
-
actions: {
|
|
19
|
-
add(state) {
|
|
20
|
-
state += 1;
|
|
21
|
-
},
|
|
22
|
-
},
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
const barModel = model('bar').define({
|
|
26
|
-
state: {
|
|
27
|
-
title: 'bar',
|
|
28
|
-
},
|
|
29
|
-
actions: {
|
|
30
|
-
set(state, payload) {
|
|
31
|
-
state.title = payload;
|
|
32
|
-
},
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const [state, actions] = useModel([fooModel, barModel]);
|
|
37
|
-
// 或
|
|
38
|
-
const [state, actions] = useModel(fooModel, barModel);
|
|
39
|
-
```
|
|
40
|
-
|
|
41
|
-
`state` 和 `actions` 的值分别为:
|
|
42
|
-
|
|
43
|
-
```ts
|
|
44
|
-
state = {
|
|
45
|
-
value: 1,
|
|
46
|
-
title: 'bar',
|
|
47
|
-
};
|
|
48
|
-
|
|
49
|
-
actions = {
|
|
50
|
-
add(state) {
|
|
51
|
-
state += 1;
|
|
52
|
-
},
|
|
53
|
-
set(state, payload) {
|
|
54
|
-
state.title = payload;
|
|
55
|
-
},
|
|
56
|
-
};
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
`useModel` 还支持对 State 和 Actions 做 selector 操作,实现对 State 和 Actions 的筛选或重命名,例如:
|
|
60
|
-
|
|
61
|
-
```ts
|
|
62
|
-
const fooModel = model('foo').define({
|
|
63
|
-
state: {
|
|
64
|
-
value: 1,
|
|
65
|
-
},
|
|
66
|
-
actions: {
|
|
67
|
-
add(state) {
|
|
68
|
-
state += 1;
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
const barModel = model('bar').define({
|
|
74
|
-
state: {
|
|
75
|
-
value: 'bar',
|
|
76
|
-
},
|
|
77
|
-
actions: {
|
|
78
|
-
set(state, payload) {
|
|
79
|
-
state.value = payload;
|
|
80
|
-
},
|
|
81
|
-
},
|
|
82
|
-
});
|
|
83
|
-
|
|
84
|
-
const [state, actions] = useModel(
|
|
85
|
-
[fooModel, barModel],
|
|
86
|
-
(fooState, barState) => ({
|
|
87
|
-
fooValue: fooState.value,
|
|
88
|
-
barValue: barState.value,
|
|
89
|
-
}), // stateSelector
|
|
90
|
-
(fooActions, barActions) => ({ add: fooActions.add }), // actionsSelector
|
|
91
|
-
);
|
|
92
|
-
```
|
|
93
|
-
|
|
94
|
-
我们通过 `stateSelector` ,把 `fooModel` 和 `barModel` 中重名的状态做了命名修改,通过 `actionsSelector` ,过滤掉了 `barModel` 的 Actions。
|
|
95
|
-
|
|
96
|
-
如果只需要设置 `actionsSelector`,可以把 `stateSelector` 设置为 `undefined`,作为参数占位。例如:
|
|
97
|
-
|
|
98
|
-
```ts
|
|
99
|
-
const [state, actions] = useModel(
|
|
100
|
-
[fooModel, barModel],
|
|
101
|
-
undefined,
|
|
102
|
-
(fooActions, barActions) => ({ add: fooActions.add }), // actionsSelector
|
|
103
|
-
);
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
### 作为静态状态使用
|
|
107
|
-
|
|
108
|
-
通过 `useStaticModel` 获取 Model ,将 Model 中的状态作为静态状态使用。可以保证组件每次访问到的 Model 的 State 都是最新值,但是 Model 的 State 的变化,并不会引起当前组件的重新渲染。
|
|
109
|
-
|
|
110
|
-
:::info
|
|
111
|
-
`useStaticModel` 的使用方式和 `useModel` 完全一致。
|
|
112
|
-
|
|
113
|
-
:::
|
|
114
|
-
|
|
115
|
-
考虑下面一种场景,有一个组件 Input 负责用户输入,另外一个组件 Search 负责根据用户的输入信息,在点击查询按钮后执行查询操作,我们不希望用户输入过程中的状态变化引起 Search 重新渲染,这时候就可以使用 `useStaticModel`:
|
|
116
|
-
|
|
117
|
-
```ts
|
|
118
|
-
import { useStaticModel } from '@modern-js/runtime/model';
|
|
119
|
-
|
|
120
|
-
function Search() {
|
|
121
|
-
// 这里注意不要解构 state
|
|
122
|
-
const [state] = useStaticModel(searchModel);
|
|
123
|
-
|
|
124
|
-
return (
|
|
125
|
-
<div>
|
|
126
|
-
<button
|
|
127
|
-
onClick={async () => {
|
|
128
|
-
const result = await mockSearch(state.input);
|
|
129
|
-
console.log(result);
|
|
130
|
-
}}
|
|
131
|
-
>
|
|
132
|
-
Search
|
|
133
|
-
</button>
|
|
134
|
-
</div>
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
```
|
|
138
|
-
|
|
139
|
-
:::warning 注意
|
|
140
|
-
不要解构 `useStaticModel` 返回的 `state`,例如改成如下写法:
|
|
141
|
-
`const [{input}] = useStaticModel(searchModel);`
|
|
142
|
-
将始终获取到 Input 的初始值。
|
|
143
|
-
|
|
144
|
-
:::
|
|
145
|
-
|
|
146
|
-
`useStaticModel` 还适合和 [react-three-fiber](https://github.com/pmndrs/react-three-fiber) 等动画库一起使用,因为在动画组件 UI 里绑定会快速变化的状态,容易引起[性能问题](https://docs.pmnd.rs/react-three-fiber/advanced/pitfalls#never-bind-fast-state-reactive)。这种情况就可以选择使用 `useStaticModel`,它只会订阅状态,但不会引起视图组件的重新渲染。下面是一个简化示例:
|
|
147
|
-
|
|
148
|
-
```ts
|
|
149
|
-
function ThreeComponent() {
|
|
150
|
-
const [state, actions] = useStaticModel(modelA);
|
|
151
|
-
|
|
152
|
-
useFrame(() => {
|
|
153
|
-
state.value; // 假设初始化为 0
|
|
154
|
-
actions.setValue(1);
|
|
155
|
-
state.value; // 这里会得到1
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
```
|
|
159
|
-
|
|
160
|
-
使用 React 的 refs 也可以实现类似效果,其实 `useStaticModel` 内部也使用到了 refs。不过直接 `useStaticModel` 有助于将状态的管理逻辑从组件中解耦,统一收敛到 Model 层。
|
|
161
|
-
|
|
162
|
-
完整的示例代码可以在[这里](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/runtime-api/static-model)查看。
|
|
163
|
-
|
|
164
|
-
### 作为局部状态使用
|
|
165
|
-
|
|
166
|
-
通过 `useLocalModel` 获取 Model ,将 Model 中的状态作为局部状态使用。此时 Model State 的变化,只会引起当前组件的重新渲染,但是不会引起其他使用了该 Model 的组件重新渲染。效果和通过 React 的 `useState` 管理状态类似,但是可以将状态的管理逻辑从组件中解耦,统一收敛到 Model 层。
|
|
167
|
-
|
|
168
|
-
:::info
|
|
169
|
-
`useLocalModel` 的使用方式和 `useModel` 完全一致。
|
|
170
|
-
|
|
171
|
-
:::
|
|
172
|
-
|
|
173
|
-
例如,我们修改计数器应用的代码,添加一个有局部状态的计数器组件 `LocalCounter`:
|
|
174
|
-
|
|
175
|
-
```ts
|
|
176
|
-
import { useLocalModel } from '@modern-js/runtime/model';
|
|
177
|
-
|
|
178
|
-
function LocalCounter() {
|
|
179
|
-
const [state, actions] = useLocalModel(countModel);
|
|
180
|
-
|
|
181
|
-
return (
|
|
182
|
-
<div>
|
|
183
|
-
<div>local counter: {state.value}</div>
|
|
184
|
-
<button onClick={() => actions.add()}>add</button>
|
|
185
|
-
</div>
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
```
|
|
189
|
-
|
|
190
|
-
分别点击 `Counter` 和 `LocalCounter` 的 `add` 按钮,两者的状态互不影响:
|
|
191
|
-
|
|
192
|
-

|
|
193
|
-
|
|
194
|
-
完整的示例代码可以在[这里](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/runtime-api/local-model)查看。
|
|
195
|
-
|
|
196
|
-
## 在组件外使用
|
|
197
|
-
|
|
198
|
-
在实际业务场景中,有时候我们需要在 React 组件外使用 Model,例如在工具函数中访问 State、执行 Actions 等。这个时候,我们就需要使用 Store。 Store 是一个底层概念,一般情况下用户接触不到,它负责存储和管理整个应用的状态。Reduck 的 Store 基于 [Redux 的 Store](https://redux.js.org/api/store) 实现,增加了 Reduck 特有的 API,如 `use` 。
|
|
199
|
-
|
|
200
|
-
首先,在组件内调用 `useStore` 获取当前应用使用的 `store` 对象,并挂载到组件外的变量上:
|
|
201
|
-
|
|
202
|
-
```ts
|
|
203
|
-
let store; // 组件外部 `store` 对象的引用
|
|
204
|
-
function setStore(s) {
|
|
205
|
-
store = s;
|
|
206
|
-
}
|
|
207
|
-
function getStore() {
|
|
208
|
-
return store;
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function Counter() {
|
|
212
|
-
const [state] = useModel(countModel);
|
|
213
|
-
const store = useStore();
|
|
214
|
-
// 通过 useMemo 避免不必要的重复设置
|
|
215
|
-
useMemo(() => {
|
|
216
|
-
setStore(store);
|
|
217
|
-
}, [store]);
|
|
218
|
-
|
|
219
|
-
return (
|
|
220
|
-
<div>
|
|
221
|
-
<div>counter: {state.value}</div>
|
|
222
|
-
</div>
|
|
223
|
-
);
|
|
224
|
-
}
|
|
225
|
-
```
|
|
226
|
-
|
|
227
|
-
通过 `store.use` 可以获取 Model 对象,`store.use` 的用法同 `useModel` 相同。以计数器应用为例,我们在组件树外,每 1s 对计数器值
|
|
228
|
-
执行自增操作:
|
|
229
|
-
|
|
230
|
-
```ts
|
|
231
|
-
setInterval(() => {
|
|
232
|
-
const store = getStore();
|
|
233
|
-
const [, actions] = store.use(countModel);
|
|
234
|
-
actions.add();
|
|
235
|
-
}, 1000);
|
|
236
|
-
```
|
|
237
|
-
|
|
238
|
-
完整的示例代码可以在[这里](https://github.com/web-infra-dev/modern-js-examples/tree/main/examples/runtime-api/counter-model-outof-react)查看。
|
|
239
|
-
|
|
240
|
-
:::info
|
|
241
|
-
如果是通过 [`createStore`](/apis/app/runtime/model/create-store) 手动创建的 Store 对象,无需通过 `useStore` 在组件内获取,即可直接使用。
|
|
242
|
-
|
|
243
|
-
:::
|
|
244
|
-
|
|
245
|
-
:::info 补充信息
|
|
246
|
-
本节涉及的 API 的详细定义,请参考[这里](/apis/app/runtime/model/model_)。
|
|
247
|
-
|
|
248
|
-
:::
|
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
# 单独使用 Reduck
|
|
2
|
-
|
|
3
|
-
在 Modern.js 以外,单独集成 Reduck 使用时,主要需要做以下修改:
|
|
4
|
-
|
|
5
|
-
1. 安装 Reduck 相关包
|
|
6
|
-
|
|
7
|
-
在项目中安装 Reduck 包:`@modern-js-reduck/react`。
|
|
8
|
-
|
|
9
|
-
2. API 导入包名
|
|
10
|
-
|
|
11
|
-
在 Modern.js 中使用时,Reduck 导出 API 的包名为:`@modern-js/runtime/model`。单独使用 Reduck 时,导出包名为:`@modern-js-reduck/react`。
|
|
12
|
-
|
|
13
|
-
3. 包裹 `Provider` 组件
|
|
14
|
-
|
|
15
|
-
Modern.js 自动在应用的入口组件上,包裹了用于注入 Reduck 全局 Store 的 [`Provider`](/apis/app/runtime/model/Provider) 组件。单独使用 Reduck 时,需要手动完成。
|
|
16
|
-
|
|
17
|
-
示例:
|
|
18
|
-
|
|
19
|
-
```tsx
|
|
20
|
-
// 根组件
|
|
21
|
-
const Root = () => {
|
|
22
|
-
return (
|
|
23
|
-
<Provider>
|
|
24
|
-
{/* 应用入口组件 */}
|
|
25
|
-
<App />
|
|
26
|
-
</Provider>
|
|
27
|
-
);
|
|
28
|
-
};
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
4. 功能配置
|
|
32
|
-
|
|
33
|
-
在 Modern.js 中使用时,可以通过 [`runtime.state`](/configure/app/runtime/state) 对 Reduck 功能进行配置。单独使用时,需要通过 [`Provider`](/apis/app/runtime/model/Provider) 的 `config` 或 `store` 参数配置。
|
|
34
|
-
|
|
35
|
-
示例:
|
|
36
|
-
|
|
37
|
-
```tsx
|
|
38
|
-
const Root = () => {
|
|
39
|
-
return (
|
|
40
|
-
{/* 关闭 Redux DevTools */}
|
|
41
|
-
<Provider config={{ devTools: false }}>
|
|
42
|
-
<App />
|
|
43
|
-
</Provider>
|
|
44
|
-
)
|
|
45
|
-
}
|
|
46
|
-
```
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
# 插件迁移
|
|
2
|
-
|
|
3
|
-
### 迁移背景
|
|
4
|
-
|
|
5
|
-
Modern.js 插件系统在不断演进,为了提供更清晰的 API 和更强大的功能,我们对 CLI 插件的定义和使用方式进行了优化。虽然旧版插件写法仍被兼容,但我们强烈建议您按照本指南进行迁移,以充分利用新版插件系统的优势。
|
|
6
|
-
|
|
7
|
-
### 迁移步骤总览
|
|
8
|
-
|
|
9
|
-
1. **更新插件类型定义**:将 `CliPlugin` 类型替换为 `CliPluginFuture`。
|
|
10
|
-
2. **调整 Hooks 调用方式**:从 `return hooks` 模式迁移到 `api.xxx` 直接调用。
|
|
11
|
-
3. **替换已变更的 API**:参照详细的 API 映射表,更新您的代码。
|
|
12
|
-
|
|
13
|
-
### 详细迁移步骤
|
|
14
|
-
|
|
15
|
-
#### 更新插件类型定义
|
|
16
|
-
|
|
17
|
-
这是迁移的第一步,也是最关键的一步。它确保您的插件能够与新版插件系统正确交互。
|
|
18
|
-
|
|
19
|
-
```typescript
|
|
20
|
-
// 旧版写法
|
|
21
|
-
import type { CliPlugin, AppTools } from '@modern-js/app-tools';
|
|
22
|
-
|
|
23
|
-
const plugin: CliPlugin<AppTools<'shared'>> = { ... };
|
|
24
|
-
|
|
25
|
-
// 新版写法
|
|
26
|
-
import type { CliPluginFuture, AppTools } from '@modern-js/app-tools';
|
|
27
|
-
|
|
28
|
-
const plugin: CliPluginFuture<AppTools<'shared'>> = { ... };
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
**说明:** `CliPluginFuture` 类型是新版插件的标准定义,它带来了更好的类型推断和更清晰的 API 结构。
|
|
32
|
-
|
|
33
|
-
#### 调整 Hooks 调用方式
|
|
34
|
-
|
|
35
|
-
新版插件系统推荐使用 `api` 对象直接调用 Hooks,这种方式更直观、更易于维护。
|
|
36
|
-
|
|
37
|
-
```typescript
|
|
38
|
-
// 旧版写法 (return hooks)
|
|
39
|
-
{
|
|
40
|
-
setup: () => ({
|
|
41
|
-
commands({ program }) { /*...*/ }
|
|
42
|
-
})
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
// 新版写法 (api.xxx)
|
|
46
|
-
{
|
|
47
|
-
setup: api => {
|
|
48
|
-
api.addCommand(({ program }) => { /*...*/ })
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
```
|
|
52
|
-
|
|
53
|
-
**说明:** `api` 对象提供了所有可用的 Hooks 和工具方法。
|
|
54
|
-
|
|
55
|
-
#### 替换已变更的 API
|
|
56
|
-
|
|
57
|
-
为了保持 API 的一致性和清晰性,我们对部分 API 的名称进行了调整。下表列出了所有变更的 API 及其新旧对应关系:
|
|
58
|
-
|
|
59
|
-
| 旧版 API | 新版 API | 说明 |
|
|
60
|
-
| :----------------------- | :---------------------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
61
|
-
| `useAppContext` | `getAppContext` | 获取应用上下文信息。 |
|
|
62
|
-
| `useConfigContext` | `getConfig` | 获取用户配置文件中的配置。 |
|
|
63
|
-
| `useResolvedConfigContext` | `getNormalizedConfig` | 获取经过插件处理后的最终配置。 |
|
|
64
|
-
| `beforeConfig` | (直接在 `setup` 中定义) | 不再需要单独的 `beforeConfig` Hook,直接在 `setup` 函数中编写相关逻辑即可。 |
|
|
65
|
-
| `prepare` | `onPrepare` | 运行主流程的前置准备阶段。 |
|
|
66
|
-
| `afterPrepare` | `onAfterPrepare` (不推荐) | 在 `onPrepare` 之后执行,但可能在未来版本中废弃。建议将逻辑合并到 `onPrepare` 中。 |
|
|
67
|
-
| `beforePrintInstructions`| `onBeforePrintInstructions` | 在打印日志信息前执行。 |
|
|
68
|
-
| `commands` | `addCommand` | 添加新的 CLI 命令。 |
|
|
69
|
-
| `watchFiles` | `addWatchFiles` | 添加需要监听的文件。 |
|
|
70
|
-
| `fileChange` | `onFileChanged` | 监听文件变化事件。 |
|
|
71
|
-
| `beforeCreateCompiler` | `onBeforeCreateCompiler` | 创建编译器前执行。 |
|
|
72
|
-
| `afterCreateCompiler` | `onAfterCreateCompiler` | 创建编译器后执行。 |
|
|
73
|
-
| `beforeBuild` | `onBeforeBuild` | 构建前执行。 |
|
|
74
|
-
| `afterBuild` | `onAfterBuild` | 构建后执行。 |
|
|
75
|
-
| `beforeDev` | `onBeforeDev` | 运行 `dev` 命令前执行。 |
|
|
76
|
-
| `afterDev` | `onDevCompileDone` | `dev` 命令编译完成后执行。 |
|
|
77
|
-
| `beforeExit` | `onBeforeExit` | 进程退出前执行。 |
|
|
78
|
-
| `htmlPartials` | `modifyHtmlPartials` | 修改 HTML 模板片段。 |
|
|
79
|
-
|
|
80
|
-
**说明:** 请务必仔细检查您的代码,确保所有旧版 API 都已替换为新版 API。
|
|
81
|
-
|
|
82
|
-
### 常见问题解答
|
|
83
|
-
|
|
84
|
-
**Q: 迁移后,我的插件还能正常工作吗?**
|
|
85
|
-
|
|
86
|
-
A: 只要您按照本指南正确完成了所有步骤,您的插件应该能够正常工作。如果您遇到任何问题,请查阅 Modern.js 的官方文档或寻求社区支持。
|
|
87
|
-
|
|
88
|
-
**Q: 我必须立即迁移我的插件吗?**
|
|
89
|
-
|
|
90
|
-
A: 虽然旧版插件写法仍然兼容,但我们强烈建议您尽快迁移。新版插件系统提供了更好的性能和更丰富的功能,长期来看,迁移是值得的。
|
|
91
|
-
|
|
92
|
-
**Q: 我可以在哪里找到更多关于新版插件系统的信息?**
|
|
93
|
-
|
|
94
|
-
A: 请查阅 Modern.js 的官方文档,特别是关于插件系统的部分。您也可以参考其他已迁移的插件示例,了解最佳实践。
|
|
95
|
-
|
|
96
|
-
### 总结
|
|
97
|
-
|
|
98
|
-
通过这份详细的迁移指南,我们希望能够帮助您顺利地将您的 CLI 插件迁移到 Modern.js 的新版插件系统。如果您在迁移过程中遇到任何问题,请随时向我们寻求帮助。
|