@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
|
@@ -2,88 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
[Tailwind CSS](https://tailwindcss.com/) 是一个以 Utility Class 为基础的 CSS 框架和设计系统,可以快速地为组件添加常用样式,同时支持主题样式的灵活扩展。
|
|
4
4
|
|
|
5
|
-
在 Modern.js 中使用
|
|
5
|
+
## 在 Modern.js 中使用 Tailwind CSS
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
在 Modern.js 中使用 [Tailwind CSS](https://tailwindcss.com/),你只需要按照 Rsbuild 操作步骤进行配置,Rsbuild 支持 Tailwind CSS v3 和 v4 版本:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
? 请选择功能名称 启用 「Tailwind CSS」 支持
|
|
12
|
-
```
|
|
9
|
+
- [Tailwind CSS v3](https://rsbuild.rs/zh/guide/styling/tailwindcss-v3#tailwind-css-v3)
|
|
10
|
+
- [Tailwind CSS v4](https://rsbuild.rs/zh/guide/styling/tailwindcss)
|
|
13
11
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
2. 在 `modern.config.ts` 中注册 Tailwind 插件:
|
|
17
|
-
|
|
18
|
-
```ts title="modern.config.ts"
|
|
19
|
-
import { tailwindcssPlugin } from '@modern-js/plugin-tailwindcss';
|
|
20
|
-
|
|
21
|
-
export default defineConfig({
|
|
22
|
-
plugins: [..., tailwindcssPlugin()],
|
|
23
|
-
});
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
3. 创建 `index.css` 文件,添加以下代码:
|
|
27
|
-
|
|
28
|
-
```css title="index.css"
|
|
29
|
-
@tailwind base;
|
|
30
|
-
@tailwind components;
|
|
31
|
-
@tailwind utilities;
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
:::info
|
|
35
|
-
根据需求不同,你可以选择性地导入 Tailwind CSS 提供的 CSS 样式。请参考 [`@tailwind` 文档](https://tailwindcss.com/docs/functions-and-directives#tailwind) 来了解 `@tailwind` 指令的详细用法。
|
|
36
|
-
:::
|
|
37
|
-
|
|
38
|
-
4. 引用 `index.css` 文件,比如在入口的根组件 `src/App.jsx` 添加如下代码:
|
|
39
|
-
|
|
40
|
-
```js
|
|
41
|
-
import './index.css';
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
5. 然后即可在各个组件中使用 Tailwind CSS 提供的 Utility Class 了:
|
|
45
|
-
|
|
46
|
-
```tsx
|
|
47
|
-
const Hello = () => (
|
|
48
|
-
<div className="h-12 w-48">
|
|
49
|
-
<p className="text-xl font-medium text-black">hello world</p>
|
|
50
|
-
</div>
|
|
51
|
-
);
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
### 配置 Tailwind CSS
|
|
55
|
-
|
|
56
|
-
在 Modern.js 中,你有两种方式来配置 Tailwind CSS:
|
|
57
|
-
|
|
58
|
-
1. 使用 `tailwind.config.{ts,js}` 文件,该用法与 Tailwind CSS 的官方用法一致,请参考 ["Tailwind CSS - Configuration"](https://tailwindcss.com/docs/configuration) 来了解更多用法。
|
|
59
|
-
|
|
60
|
-
```ts title="tailwind.config.ts"
|
|
61
|
-
import type { Config } from 'tailwindcss';
|
|
62
|
-
|
|
63
|
-
export default {
|
|
64
|
-
content: ['./src/**/*.{js,jsx,ts,tsx}'],
|
|
65
|
-
} as Config;
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
:::tip
|
|
69
|
-
请升级 Modern.js 到 >= MAJOR_VERSION.33.0 版本,以支持自动读取 `tailwind.config.{ts,js}` 文件。
|
|
70
|
-
:::
|
|
71
|
-
|
|
72
|
-
2. 使用 [tools.tailwindcss](/configure/app/tools/tailwindcss.html) 配置项,这是旧版本的用法,我们更推荐使用 `tailwind.config.{ts,js}` 文件进行配置。
|
|
73
|
-
|
|
74
|
-
```ts title="modern.config.ts"
|
|
75
|
-
export default {
|
|
76
|
-
tools: {
|
|
77
|
-
tailwindcss: {
|
|
78
|
-
content: ['./src/**/*.{js,jsx,ts,tsx}'],
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
如果你同时使用了 `tailwind.config.{ts,js}` 文件和 `tools.tailwindcss` 选项,那么 `tools.tailwindcss` 定义的配置会优先生效,并覆盖 `tailwind.config.{ts,js}` 中定义的内容。
|
|
85
|
-
|
|
86
|
-
### Tailwind CSS 自动补全
|
|
12
|
+
## Tailwind CSS 自动补全
|
|
87
13
|
|
|
88
14
|
Tailwind CSS 官方提供了 [Tailwind CSS IntelliSense](https://github.com/tailwindlabs/tailwindcss-intellisense) 插件,用于在 VS Code 中自动补全 Tailwind CSS 的 class names、CSS functions 和 directives。
|
|
89
15
|
|
|
@@ -92,20 +18,10 @@ Tailwind CSS 官方提供了 [Tailwind CSS IntelliSense](https://github.com/tail
|
|
|
92
18
|
1. 在 VS Code 中安装 [Tailwind CSS IntelliSense](https://github.com/tailwindlabs/tailwindcss-intellisense) 插件。
|
|
93
19
|
2. 如果项目的根目录没有 `tailwind.config.{ts,js}` 文件,那么你需要创建该文件,并写入当前项目的 Tailwind CSS 配置,否则 IDE 插件将无法正确生效。
|
|
94
20
|
|
|
95
|
-
## Tailwind CSS 版本
|
|
96
|
-
|
|
97
|
-
Modern.js 同时支持 Tailwind CSS v2 和 v3 版本,框架会识别项目 `package.json` 中的 `tailwindcss` 依赖版本,并启用相应的配置。默认情况下,我们会为你安装 Tailwind CSS v3 版本。
|
|
98
|
-
|
|
99
|
-
如果你的项目仍在使用 Tailwind CSS v2,我们推荐你升级到 v3 以支持 JIT 等能力。关于 Tailwind CSS v2 与 v3 版本之间的差异,请参考以下文章:
|
|
100
|
-
|
|
101
|
-
- [Tailwind CSS v3.0](https://tailwindcss.com/blog/tailwindcss-v3)
|
|
102
|
-
- [Upgrade Guide](https://tailwindcss.com/docs/upgrade-guide)
|
|
103
|
-
|
|
104
21
|
## 浏览器兼容性
|
|
105
22
|
|
|
106
|
-
Tailwind CSS
|
|
23
|
+
Tailwind CSS v3 不支持 IE 11 浏览器,相关背景请参考:
|
|
107
24
|
|
|
108
25
|
- [Tailwind CSS v3 - Browser Support](https://tailwindcss.com/docs/browser-support)。
|
|
109
|
-
- [Tailwind CSS v2 - Browser Support](https://v2.tailwindcss.com/docs/browser-support)
|
|
110
26
|
|
|
111
27
|
如果你在 IE 11 浏览器上使用 Tailwind CSS,可能会出现部分样式不可用的现象,请谨慎使用。
|
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
title: 数据缓存
|
|
3
3
|
sidebar_position: 4
|
|
4
4
|
---
|
|
5
|
+
|
|
5
6
|
# 数据缓存
|
|
6
7
|
|
|
7
8
|
`cache` 函数可以让你缓存数据获取或计算的结果,相比整页[渲染缓存](/guides/basic-features/render/ssr-cache),它提供了更精细的数据粒度控制,并且适用于客户端渲染(CSR)、服务端渲染(SSR)、API 服务(BFF)等多种场景。
|
|
8
9
|
|
|
9
|
-
:::info
|
|
10
|
-
需要 x.65.5 及以上版本
|
|
11
|
-
:::
|
|
12
|
-
|
|
13
10
|
## 基本用法
|
|
14
11
|
|
|
15
12
|
:::note
|
|
@@ -27,7 +24,7 @@ import { fetchUserData } from './api';
|
|
|
27
24
|
const getUser = cache(fetchUserData);
|
|
28
25
|
|
|
29
26
|
const loader = async () => {
|
|
30
|
-
const user = await getUser(
|
|
27
|
+
const user = await getUser('123'); // 函数入参发生变化时,函数会重新执行
|
|
31
28
|
return {
|
|
32
29
|
user,
|
|
33
30
|
};
|
|
@@ -67,7 +64,7 @@ interface CacheOptions {
|
|
|
67
64
|
## 使用范围
|
|
68
65
|
|
|
69
66
|
与 react 的 [cache](https://react.dev/reference/react/cache) 函数只能在 server component 组件中使用不同,
|
|
70
|
-
|
|
67
|
+
Modern.js 提供的 `cache` 函数可以在任意的前端或服务端的代码中使用。
|
|
71
68
|
|
|
72
69
|
## 详细用法
|
|
73
70
|
|
|
@@ -79,7 +76,6 @@ EdenX 提供的 `cache` 函数可以在任意的前端或服务端的代码中
|
|
|
79
76
|
无 `options` 参数时,可以看作是 react [`cache`](https://react.dev/reference/react/cache) 函数的替代品,可以在任意服务端代码中使用(比如可以在 SSR 项目的 data loader 中),不局限于 server component。
|
|
80
77
|
:::
|
|
81
78
|
|
|
82
|
-
|
|
83
79
|
```ts
|
|
84
80
|
import { cache } from '@modern-js/runtime/cache';
|
|
85
81
|
import { fetchUserData } from './api';
|
|
@@ -108,8 +104,8 @@ const getDashboardStats = cache(
|
|
|
108
104
|
return await fetchComplexStatistics();
|
|
109
105
|
},
|
|
110
106
|
{
|
|
111
|
-
maxAge: CacheTime.MINUTE * 2,
|
|
112
|
-
}
|
|
107
|
+
maxAge: CacheTime.MINUTE * 2, // 在 2 分钟内调用该函数会返回缓存的数据
|
|
108
|
+
},
|
|
113
109
|
);
|
|
114
110
|
```
|
|
115
111
|
|
|
@@ -117,8 +113,11 @@ const getDashboardStats = cache(
|
|
|
117
113
|
|
|
118
114
|
`revalidate` 参数用于设置缓存过期后,重新验证缓存的时间窗口,可以和 `maxAge` 参数一起使用,类似与 HTTP Cache-Control 的 stale-while-revalidate 模式。
|
|
119
115
|
|
|
116
|
+
如以下示例,缓存的行为会根据时间分为三个阶段:
|
|
120
117
|
|
|
121
|
-
|
|
118
|
+
1. **0 到 2 分钟(`maxAge` 内)**:缓存新鲜,直接返回缓存数据,不会重新请求
|
|
119
|
+
2. **2 到 3 分钟(`maxAge` 到 `maxAge + revalidate` 之间)**:缓存过期但在重新验证窗口内,会立即返回旧数据,同时在后台重新请求数据并更新缓存
|
|
120
|
+
3. **超过 3 分钟(超过 `maxAge + revalidate`)**:缓存完全过期,会重新执行函数获取新数据
|
|
122
121
|
|
|
123
122
|
```ts
|
|
124
123
|
import { cache, CacheTime } from '@modern-js/runtime/cache';
|
|
@@ -130,7 +129,7 @@ const getDashboardStats = cache(
|
|
|
130
129
|
{
|
|
131
130
|
maxAge: CacheTime.MINUTE * 2,
|
|
132
131
|
revalidate: CacheTime.MINUTE * 1,
|
|
133
|
-
}
|
|
132
|
+
},
|
|
134
133
|
);
|
|
135
134
|
```
|
|
136
135
|
|
|
@@ -147,7 +146,7 @@ const getDashboardStats = cache(
|
|
|
147
146
|
},
|
|
148
147
|
{
|
|
149
148
|
tag: 'dashboard',
|
|
150
|
-
}
|
|
149
|
+
},
|
|
151
150
|
);
|
|
152
151
|
|
|
153
152
|
const getComplexStatistics = cache(
|
|
@@ -156,10 +155,10 @@ const getComplexStatistics = cache(
|
|
|
156
155
|
},
|
|
157
156
|
{
|
|
158
157
|
tag: 'dashboard',
|
|
159
|
-
}
|
|
158
|
+
},
|
|
160
159
|
);
|
|
161
160
|
|
|
162
|
-
await revalidateTag('dashboard
|
|
161
|
+
await revalidateTag('dashboard'); // 会使 getDashboardStats 函数和 getComplexStatistics 函数的缓存都失效
|
|
163
162
|
```
|
|
164
163
|
|
|
165
164
|
#### `getKey` 参数
|
|
@@ -181,7 +180,7 @@ const getUser = cache(
|
|
|
181
180
|
maxAge: CacheTime.MINUTE * 5,
|
|
182
181
|
// 只使用第一个参数(userId)作为缓存键
|
|
183
182
|
getKey: (userId, options) => userId,
|
|
184
|
-
}
|
|
183
|
+
},
|
|
185
184
|
);
|
|
186
185
|
|
|
187
186
|
// 下面两次调用会共享缓存,因为 getKey 只使用了 userId
|
|
@@ -211,11 +210,10 @@ const getUser = cache(
|
|
|
211
210
|
{
|
|
212
211
|
maxAge: CacheTime.MINUTE * 5,
|
|
213
212
|
getKey: (userId, options) => generateKey(userId),
|
|
214
|
-
}
|
|
213
|
+
},
|
|
215
214
|
);
|
|
216
215
|
```
|
|
217
216
|
|
|
218
|
-
|
|
219
217
|
#### `customKey` 参数
|
|
220
218
|
|
|
221
219
|
`customKey` 参数用于**完全定制**缓存的键,它是一个函数,接收一个包含以下属性的对象,返回值必须是字符串类型。
|
|
@@ -229,6 +227,7 @@ const getUser = cache(
|
|
|
229
227
|
:::info
|
|
230
228
|
|
|
231
229
|
一般在以下场景,缓存会失效:
|
|
230
|
+
|
|
232
231
|
1. 函数的入参发生变化
|
|
233
232
|
2. 不满足 maxAge 条件
|
|
234
233
|
3. 调用了 `revalidateTag`
|
|
@@ -244,16 +243,13 @@ import { cache } from '@modern-js/runtime/cache';
|
|
|
244
243
|
import { fetchUserData } from './api';
|
|
245
244
|
|
|
246
245
|
// 不同的函数引用,但是通过 customKey 可以使它们共享一个缓存
|
|
247
|
-
const getUserA = cache(
|
|
248
|
-
|
|
249
|
-
{
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
},
|
|
255
|
-
}
|
|
256
|
-
);
|
|
246
|
+
const getUserA = cache(fetchUserData, {
|
|
247
|
+
maxAge: CacheTime.MINUTE * 5,
|
|
248
|
+
customKey: ({ params }) => {
|
|
249
|
+
// 返回一个稳定的字符串作为缓存的键
|
|
250
|
+
return `user-${params[0]}`;
|
|
251
|
+
},
|
|
252
|
+
});
|
|
257
253
|
|
|
258
254
|
// 即使函数引用变了,只要 customKey 返回相同的值,也会命中缓存
|
|
259
255
|
const getUserB = cache(
|
|
@@ -264,7 +260,7 @@ const getUserB = cache(
|
|
|
264
260
|
// 返回与 getUserA 相同的键
|
|
265
261
|
return `user-${params[0]}`;
|
|
266
262
|
},
|
|
267
|
-
}
|
|
263
|
+
},
|
|
268
264
|
);
|
|
269
265
|
|
|
270
266
|
// 现在你可以在不同的函数实现间共享缓存
|
|
@@ -272,12 +268,9 @@ await getUserA(123); // 获取数据并使用键 "user-123" 缓存
|
|
|
272
268
|
await getUserB(123); // 缓存命中,返回缓存的数据
|
|
273
269
|
|
|
274
270
|
// 可以利用 generatedKey 参数在默认键的基础上进行修改
|
|
275
|
-
const getUserC = cache(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
customKey: ({ generatedKey }) => `prefix-${generatedKey}`,
|
|
279
|
-
}
|
|
280
|
-
);
|
|
271
|
+
const getUserC = cache(fetchUserData, {
|
|
272
|
+
customKey: ({ generatedKey }) => `prefix-${generatedKey}`,
|
|
273
|
+
});
|
|
281
274
|
|
|
282
275
|
// 用于可预测的缓存键,便于外部管理
|
|
283
276
|
const getUserD = cache(
|
|
@@ -287,7 +280,7 @@ const getUserD = cache(
|
|
|
287
280
|
{
|
|
288
281
|
maxAge: CacheTime.MINUTE * 5,
|
|
289
282
|
customKey: ({ params }) => `app:user:${params[0]}`,
|
|
290
|
-
}
|
|
283
|
+
},
|
|
291
284
|
);
|
|
292
285
|
```
|
|
293
286
|
|
|
@@ -304,30 +297,31 @@ const stats = {
|
|
|
304
297
|
hits: 0,
|
|
305
298
|
misses: 0,
|
|
306
299
|
stales: 0,
|
|
307
|
-
hitRate: () => stats.hits / stats.total
|
|
300
|
+
hitRate: () => stats.hits / stats.total,
|
|
308
301
|
};
|
|
309
302
|
|
|
310
|
-
const getUser = cache(
|
|
311
|
-
|
|
312
|
-
{
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
} else if (status === 'stale') {
|
|
323
|
-
stats.stales++;
|
|
324
|
-
}
|
|
325
|
-
|
|
326
|
-
console.log(`缓存${status === 'hit' ? '命中' : status === 'miss' ? '未命中' : '陈旧'},键:${String(key)}`);
|
|
327
|
-
console.log(`当前命中率:${stats.hitRate() * 100}%`);
|
|
303
|
+
const getUser = cache(fetchUserData, {
|
|
304
|
+
maxAge: CacheTime.MINUTE * 5,
|
|
305
|
+
onCache({ status, key, params, result }) {
|
|
306
|
+
// status 可以是 'hit'、'miss' 或 'stale'
|
|
307
|
+
stats.total++;
|
|
308
|
+
|
|
309
|
+
if (status === 'hit') {
|
|
310
|
+
stats.hits++;
|
|
311
|
+
} else if (status === 'miss') {
|
|
312
|
+
stats.misses++;
|
|
313
|
+
} else if (status === 'stale') {
|
|
314
|
+
stats.stales++;
|
|
328
315
|
}
|
|
329
|
-
|
|
330
|
-
|
|
316
|
+
|
|
317
|
+
console.log(
|
|
318
|
+
`缓存${
|
|
319
|
+
status === 'hit' ? '命中' : status === 'miss' ? '未命中' : '陈旧'
|
|
320
|
+
},键:${String(key)}`,
|
|
321
|
+
);
|
|
322
|
+
console.log(`当前命中率:${stats.hitRate() * 100}%`);
|
|
323
|
+
},
|
|
324
|
+
});
|
|
331
325
|
|
|
332
326
|
// 使用示例
|
|
333
327
|
await getUser(1); // 缓存未命中
|
|
@@ -348,6 +342,7 @@ await getUser(2); // 缓存未命中
|
|
|
348
342
|
这个回调只在提供 `options` 参数时被调用。当使用无 options 的缓存函数时,不会调用 `onCache` 回调。
|
|
349
343
|
|
|
350
344
|
`onCache` 回调对以下场景非常有用:
|
|
345
|
+
|
|
351
346
|
- 监控缓存性能
|
|
352
347
|
- 计算命中率
|
|
353
348
|
- 记录缓存操作
|
|
@@ -405,11 +400,13 @@ configureCache({
|
|
|
405
400
|
##### 使用 `customKey` 确保缓存键稳定性
|
|
406
401
|
|
|
407
402
|
:::warning 重要建议
|
|
403
|
+
|
|
408
404
|
当使用自定义存储容器(如 Redis)时,**建议配置 `customKey`** 来确保缓存键的稳定性。这样可以确保:
|
|
409
405
|
|
|
410
406
|
1. **跨进程共享**:不同服务器实例能够共享相同的缓存
|
|
411
407
|
2. **应用重启后缓存有效**:重启应用后仍能命中之前的缓存
|
|
412
408
|
3. **代码部署后缓存保持**:代码更新后相同逻辑的缓存仍然有效
|
|
409
|
+
|
|
413
410
|
:::
|
|
414
411
|
|
|
415
412
|
默认的缓存键生成机制基于函数引用,在分布式环境中可能不够稳定。建议使用 `customKey` 提供稳定的缓存键:
|
|
@@ -431,7 +428,7 @@ const getUser = cache(
|
|
|
431
428
|
maxAge: CacheTime.MINUTE * 5,
|
|
432
429
|
// 使用被缓存函数相关的稳定标识符作为缓存键
|
|
433
430
|
customKey: () => `fetchUserData`,
|
|
434
|
-
}
|
|
431
|
+
},
|
|
435
432
|
);
|
|
436
433
|
```
|
|
437
434
|
|
|
@@ -451,7 +448,7 @@ class RedisContainer implements Container {
|
|
|
451
448
|
}
|
|
452
449
|
|
|
453
450
|
async get(key: string): Promise<string | null> {
|
|
454
|
-
const value = await this.
|
|
451
|
+
const value = await this.client.get(key);
|
|
455
452
|
return value ? JSON.parse(value) : null;
|
|
456
453
|
}
|
|
457
454
|
|
|
@@ -499,4 +496,3 @@ configureCache({
|
|
|
499
496
|
1. **序列化**:所有的缓存数据都会被序列化为字符串存储,容器只需要处理字符串的存取操作。
|
|
500
497
|
|
|
501
498
|
2. **TTL 支持**:如果你的存储后端支持 TTL(生存时间),可以在 `set` 方法中使用 `options.ttl` 参数(单位为秒)。
|
|
502
|
-
|
|
@@ -9,11 +9,7 @@ Modern.js 中提供了开箱即用的数据获取能力,开发者可以通过
|
|
|
9
9
|
|
|
10
10
|
## 什么是 Data Loader
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
Modern.js v1 项目通过 `useLoader` 获取数据,这已经不是我们推荐的用法,建议迁移到 Data Loader。
|
|
14
|
-
:::
|
|
15
|
-
|
|
16
|
-
Modern.js 推荐使用[约定式路由](/guides/basic-features/routes)做路由的管理,每个路由组件(`layout.ts`,`page.ts` 或 `$.tsx`)都可以有一个同名的 `.data` 文件。这些文件可以导出一个 `loader` 函数,我们称为 Data Loader,它会在对应的路由组件渲染之前执行,为组件提供数据。如下面示例:
|
|
12
|
+
Modern.js 推荐使用[约定式路由](/guides/basic-features/routes/routes)做路由的管理,每个路由组件(`layout.ts`,`page.ts` 或 `$.tsx`)都可以有一个同名的 `.data` 文件。这些文件可以导出一个 `loader` 函数,我们称为 Data Loader,它会在对应的路由组件渲染之前执行,为组件提供数据。如下面示例:
|
|
17
13
|
|
|
18
14
|
```bash
|
|
19
15
|
.
|
|
@@ -40,17 +36,19 @@ export const loader = async (): Promise<ProfileData> => {
|
|
|
40
36
|
```
|
|
41
37
|
|
|
42
38
|
:::warning 兼容性
|
|
39
|
+
|
|
43
40
|
- 在之前的版本中,Data Loader 是定义在 `.loader` 文件中的。当前版本中,我们推荐定义在 `.data` 文件中,同时我们会保持对 `.loader` 文件的兼容。
|
|
44
41
|
- 在 `.loader` 文件中,Data Loader 可以默认导出。但在 `data` 文件中,Data Loader 需要以 `loader` 具名导出。
|
|
42
|
+
|
|
45
43
|
```ts
|
|
46
|
-
|
|
47
|
-
export default () => {}
|
|
44
|
+
// xxx.loader.ts
|
|
45
|
+
export default () => {};
|
|
48
46
|
|
|
49
47
|
// xxx.data.ts
|
|
50
|
-
export const loader = () => {}
|
|
48
|
+
export const loader = () => {};
|
|
51
49
|
```
|
|
52
|
-
:::
|
|
53
50
|
|
|
51
|
+
:::
|
|
54
52
|
|
|
55
53
|
在路由组件中,你可以通过 `useLoaderData` 函数获取数据:
|
|
56
54
|
|
|
@@ -76,7 +74,7 @@ export default function UserPage() {
|
|
|
76
74
|
在以后的版本中,Modern.js 可能会支持在 CSR 环境下,`loader` 函数也在服务端运行,以提高性能和安全性,所以这里建议尽可能地保证 `loader` 的纯粹,只做数据获取的场景。
|
|
77
75
|
:::
|
|
78
76
|
|
|
79
|
-
当在浏览器端导航时,基于[约定式路由](/guides/basic-features/routes),Modern.js 能够支持所有的 `loader` 函数并行执行(请求)。即当访问 `/user/profile` 时,`/user` 和 `/user/profile` 下的 `loader` 函数都会并行执行(请求),这种方式解决了部分请求、渲染瀑布流的问题,较大的提升了页面性能。
|
|
77
|
+
当在浏览器端导航时,基于[约定式路由](/guides/basic-features/routes/routes),Modern.js 能够支持所有的 `loader` 函数并行执行(请求)。即当访问 `/user/profile` 时,`/user` 和 `/user/profile` 下的 `loader` 函数都会并行执行(请求),这种方式解决了部分请求、渲染瀑布流的问题,较大的提升了页面性能。
|
|
80
78
|
|
|
81
79
|
## `loader` 函数
|
|
82
80
|
|
|
@@ -84,7 +82,7 @@ export default function UserPage() {
|
|
|
84
82
|
|
|
85
83
|
### params
|
|
86
84
|
|
|
87
|
-
`params` 是当路由为[动态路由](/guides/basic-features/routes#动态路由)时的动态路由片段,会作为参数传入 `loader` 函数:
|
|
85
|
+
`params` 是当路由为[动态路由](/guides/basic-features/routes/routes#动态路由)时的动态路由片段,会作为参数传入 `loader` 函数:
|
|
88
86
|
|
|
89
87
|
```tsx title="routes/user/[id]/page.data.ts"
|
|
90
88
|
import { LoaderFunctionArgs } from '@modern-js/runtime/router';
|
|
@@ -160,9 +158,10 @@ SSR 应用的 `loader` 函数只在服务端执行可以带来以下好处:
|
|
|
160
158
|
```tsx
|
|
161
159
|
export async function loader() {
|
|
162
160
|
const res = await fetch('URL_ADDRESS');
|
|
161
|
+
const data = await res.json();
|
|
163
162
|
return {
|
|
164
|
-
message:
|
|
165
|
-
}
|
|
163
|
+
message: data.message,
|
|
164
|
+
};
|
|
166
165
|
}
|
|
167
166
|
```
|
|
168
167
|
|
|
@@ -170,7 +169,7 @@ export async function loader() {
|
|
|
170
169
|
|
|
171
170
|
### 基本用法
|
|
172
171
|
|
|
173
|
-
在 `loader` 函数中,可以通过 `throw error` 或者 `throw response` 的方式处理错误,当 `loader` 函数中有错误被抛出时,Modern.js 会停止执行当前 `loader` 中的代码,并将前端 UI 切换到定义的 [`ErrorBoundary`](/guides/basic-features/routes#错误处理) 组件:
|
|
172
|
+
在 `loader` 函数中,可以通过 `throw error` 或者 `throw response` 的方式处理错误,当 `loader` 函数中有错误被抛出时,Modern.js 会停止执行当前 `loader` 中的代码,并将前端 UI 切换到定义的 [`ErrorBoundary`](/guides/basic-features/routes/routes#错误处理) 组件:
|
|
174
173
|
|
|
175
174
|
```tsx
|
|
176
175
|
// routes/user/profile/page.data.ts
|
|
@@ -207,7 +206,7 @@ export default ErrorBoundary;
|
|
|
207
206
|
// routes/user/profile/page.data.ts
|
|
208
207
|
export async function loader() {
|
|
209
208
|
const user = await fetchUser();
|
|
210
|
-
if(!user){
|
|
209
|
+
if (!user) {
|
|
211
210
|
throw new Response('The user was not found', { status: 404 });
|
|
212
211
|
}
|
|
213
212
|
return user;
|
|
@@ -260,7 +259,6 @@ export function UserLayout() {
|
|
|
260
259
|
|
|
261
260
|
如果想获取 `entry1/routes/layout.tsx` 中 `loader` 返回的数据,`routeId` 的值就是 `entry1_layout`。
|
|
262
261
|
|
|
263
|
-
|
|
264
262
|
## Loading UI (Experimental)
|
|
265
263
|
|
|
266
264
|
:::info Experimental
|
|
@@ -14,7 +14,7 @@ sidebar_position: 4
|
|
|
14
14
|
|
|
15
15
|
## 什么是 Data Action
|
|
16
16
|
|
|
17
|
-
Modern.js 推荐使用[约定式路由](/guides/basic-features/routes)做路由的管理,每个路由组件(`layout.ts`,`page.ts` 或 `$.tsx`)都可以有一个同名的 `.data` 文件。这些文件可以导出一个 `action` 函数,我们称为 Data Action,开发者可以在合适的时机调用它:
|
|
17
|
+
Modern.js 推荐使用[约定式路由](/guides/basic-features/routes/routes)做路由的管理,每个路由组件(`layout.ts`,`page.ts` 或 `$.tsx`)都可以有一个同名的 `.data` 文件。这些文件可以导出一个 `action` 函数,我们称为 Data Action,开发者可以在合适的时机调用它:
|
|
18
18
|
|
|
19
19
|
```bash
|
|
20
20
|
.
|
|
@@ -29,7 +29,7 @@ Modern.js 推荐使用[约定式路由](/guides/basic-features/routes)做路由
|
|
|
29
29
|
```ts title="routes/user/layout.data.ts"
|
|
30
30
|
import type { ActionFunction } from '@modern-js/runtime/router';
|
|
31
31
|
|
|
32
|
-
export const action: ActionFunction = ({ request }) => {
|
|
32
|
+
export const action: ActionFunction = async ({ request }) => {
|
|
33
33
|
const newUser = await request.json();
|
|
34
34
|
const name = newUser.name;
|
|
35
35
|
return updateUserProfile(name);
|
|
@@ -82,7 +82,7 @@ export default () => {
|
|
|
82
82
|
|
|
83
83
|
### params
|
|
84
84
|
|
|
85
|
-
`params` 是当路由为[动态路由](/guides/basic-features/routes#动态路由)时动态路由片段,会作为参数传入 `action` 函数:
|
|
85
|
+
`params` 是当路由为[动态路由](/guides/basic-features/routes/routes#动态路由)时动态路由片段,会作为参数传入 `action` 函数:
|
|
86
86
|
|
|
87
87
|
```tsx title="routes/user/[id]/page.data.ts"
|
|
88
88
|
import { ActionFunctionArgs } from '@modern-js/runtime/router';
|
|
@@ -97,7 +97,7 @@ export const action = async ({ params }: ActionFunctionArgs) => {
|
|
|
97
97
|
|
|
98
98
|
### request
|
|
99
99
|
|
|
100
|
-
`request` 是一个 [Fetch Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) 实例。通过 `request`,可以在 action 函数中获取到浏览器端提交的数据,如 `request.json()`,`request.formData()`,`request.
|
|
100
|
+
`request` 是一个 [Fetch Request](https://developer.mozilla.org/en-US/docs/Web/API/Request) 实例。通过 `request`,可以在 action 函数中获取到浏览器端提交的数据,如 `request.json()`,`request.formData()`,`request.text()` 等。具体使用哪个 API,请参考[数据类型](#数据类型)。
|
|
101
101
|
|
|
102
102
|
```tsx title="routes/user/[id]/page.data.ts"
|
|
103
103
|
import { ActionFunctionArgs } from '@modern-js/runtime/router';
|
|
@@ -70,7 +70,7 @@ module.exports = {
|
|
|
70
70
|
|
|
71
71
|
```js
|
|
72
72
|
module.exports = {
|
|
73
|
-
'api/getInfo': (req, res) => {
|
|
73
|
+
'/api/getInfo': (req, res) => {
|
|
74
74
|
setTimeout(() => {
|
|
75
75
|
res.end('delay 2000ms');
|
|
76
76
|
}, 2000);
|
|
@@ -83,6 +83,9 @@ module.exports = {
|
|
|
83
83
|
`config/mock/index.ts` 下还可以导出 `config` 对象,更精细的控制 Mock 服务。
|
|
84
84
|
|
|
85
85
|
```ts
|
|
86
|
+
import type { IncomingMessage } from 'node:http';
|
|
87
|
+
import type { ServerResponse } from 'node:http';
|
|
88
|
+
|
|
86
89
|
type MockConfig = {
|
|
87
90
|
enable: ((req: IncomingMessage, res: ServerResponse) => boolean) | boolean;
|
|
88
91
|
};
|
|
@@ -4,21 +4,16 @@ sidebar_position: 6
|
|
|
4
4
|
|
|
5
5
|
# 网络代理
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
Modern.js 在 [`tools.devServer`](/configure/app/tools/dev-server) 中提供了配置开发环境代理的方式。例如,将本地开发接口,代理到线上某个地址:
|
|
7
|
+
Modern.js 在 [`dev.server.proxy`](/configure/app/dev/server) 中提供了配置开发环境代理的方式。例如,将本地开发接口,代理到线上某个地址:
|
|
10
8
|
|
|
11
9
|
```ts title="modern.config.ts"
|
|
12
10
|
import { defineConfig } from '@modern-js/app-tools';
|
|
13
11
|
|
|
14
12
|
export default defineConfig({
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
dev: {
|
|
14
|
+
server: {
|
|
17
15
|
proxy: {
|
|
18
|
-
'/go/api':
|
|
19
|
-
target: 'http://www.example.com/',
|
|
20
|
-
changeOrigin: true,
|
|
21
|
-
},
|
|
16
|
+
'/go/api': 'http://www.example.com/',
|
|
22
17
|
},
|
|
23
18
|
},
|
|
24
19
|
},
|
|
@@ -31,9 +26,3 @@ export default defineConfig({
|
|
|
31
26
|
配置格式可参考:[http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware)。
|
|
32
27
|
|
|
33
28
|
:::
|
|
34
|
-
|
|
35
|
-
## 全局代理
|
|
36
|
-
|
|
37
|
-
import GlobalProxy from "@site-docs/components/global-proxy"
|
|
38
|
-
|
|
39
|
-
<GlobalProxy />
|
|
@@ -26,14 +26,14 @@ import { RsdoctorRspackPlugin } from '@rsdoctor/rspack-plugin';
|
|
|
26
26
|
export default {
|
|
27
27
|
// ...
|
|
28
28
|
tools: {
|
|
29
|
-
|
|
29
|
+
bundlerChain(chain) {
|
|
30
30
|
// 仅在 RSDOCTOR 为 true 时注册插件,因为插件会增加构建耗时
|
|
31
31
|
if (process.env.RSDOCTOR) {
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
chain.plugin('rsdoctor').use(RsdoctorRspackPlugin, [
|
|
33
|
+
{
|
|
34
34
|
// 插件选项
|
|
35
|
-
}
|
|
36
|
-
);
|
|
35
|
+
},
|
|
36
|
+
]);
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
39
|
},
|
|
@@ -46,7 +46,7 @@ export default {
|
|
|
46
46
|
|
|
47
47
|
## 执行构建
|
|
48
48
|
|
|
49
|
-
|
|
49
|
+
你可以在项目内执行 build 命令,在完成构建后,Rsdoctor 会自动打开本次构建的分析页面。
|
|
50
50
|
|
|
51
51
|
```bash
|
|
52
52
|
RSDOCTOR=true npm run build
|