@modern-js/main-doc 2.69.5 → 3.0.0-alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/en/{_meta.json → _nav.json} +5 -1
- package/docs/en/apis/app/commands.mdx +2 -3
- package/docs/en/apis/app/hooks/src/entry.mdx +1 -5
- package/docs/en/apis/app/hooks/src/entry.server.mdx +4 -5
- package/docs/en/apis/app/hooks/src/routes.mdx +2 -2
- package/docs/en/apis/app/runtime/_meta.json +0 -18
- package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +2 -2
- package/docs/en/apis/app/runtime/router/router.mdx +1 -1
- package/docs/en/apis/app/runtime/utility/css-in-js.mdx +3 -2
- package/docs/en/community/blog/v2-release-note.mdx +0 -2
- package/docs/en/community/contributing-guide.mdx +10 -12
- package/docs/en/components/bff-upload.mdx +16 -12
- package/docs/en/components/build-output.mdx +45 -0
- package/docs/en/components/debug-app.mdx +1 -1
- package/docs/en/components/enable-bff-caution.mdx +2 -2
- package/docs/en/components/enable-bff.mdx +38 -8
- package/docs/en/components/enable-ssg.mdx +48 -0
- package/docs/en/components/entry-scan-logic.mdx +7 -0
- package/docs/en/components/init-app.mdx +40 -17
- package/docs/en/components/international/install-command.mdx +9 -0
- package/docs/en/components/international/introduce.mdx +2 -0
- package/docs/en/components/module-federation.mdx +4 -4
- package/docs/en/components/new-entry-tooltip.mdx +0 -0
- package/docs/en/components/nodeVersion.mdx +2 -6
- package/docs/en/components/prerequisites.mdx +1 -1
- package/docs/en/components/ua-polyfill.mdx +16 -12
- package/docs/en/components/upgrade-browserslist.mdx +0 -0
- package/docs/en/configure/_meta.json +7 -8
- package/docs/en/configure/app/bff/cross-project.mdx +24 -0
- package/docs/en/configure/app/dev/lazy-compilation.mdx +45 -0
- package/docs/en/configure/app/dev/server.mdx +103 -0
- package/docs/en/configure/app/dev/setup-middlewares.mdx +4 -22
- package/docs/en/configure/app/html/app-icon.mdx +1 -23
- package/docs/en/configure/app/output/inline-scripts.mdx +1 -1
- package/docs/en/configure/app/output/override-browserslist.mdx +6 -4
- package/docs/en/configure/app/output/source-map.mdx +6 -3
- package/docs/en/configure/app/output/ssg.mdx +12 -43
- package/docs/en/configure/app/output/ssgByEntries.mdx +93 -0
- package/docs/en/configure/app/performance/build-cache.mdx +0 -4
- package/docs/en/configure/app/resolve/alias-strategy.mdx +14 -0
- package/docs/en/configure/app/resolve/alias.mdx +13 -0
- package/docs/en/configure/app/resolve/condition-names.mdx +18 -0
- package/docs/en/configure/app/resolve/dedupe.mdx +13 -0
- package/docs/en/configure/app/resolve/extensions.mdx +18 -0
- package/docs/en/configure/app/runtime/0-intro.mdx +2 -51
- package/docs/en/configure/app/security/check-syntax.mdx +1 -1
- package/docs/en/configure/app/server/port.mdx +1 -21
- package/docs/en/configure/app/server/rsc.mdx +30 -0
- package/docs/en/configure/app/server/ssr.mdx +20 -9
- package/docs/en/configure/app/source/decorators.mdx +4 -2
- package/docs/en/configure/app/source/entries.mdx +0 -2
- package/docs/en/configure/app/source/main-entry-name.mdx +4 -4
- package/docs/en/configure/app/source/transform-import.mdx +1 -59
- package/docs/en/configure/app/tools/bundler-chain.mdx +5 -5
- package/docs/en/configure/app/tools/css-extract.mdx +1 -1
- package/docs/en/configure/app/tools/dev-server.mdx +14 -248
- package/docs/en/configure/app/tools/html-plugin.mdx +3 -3
- package/docs/en/configure/app/tools/lightningcss-loader.mdx +0 -1
- package/docs/en/configure/app/tools/swc.mdx +1 -43
- package/docs/en/configure/app/usage.mdx +7 -17
- package/docs/en/guides/_meta.json +1 -2
- package/docs/en/guides/advanced-features/_meta.json +6 -0
- package/docs/en/guides/advanced-features/bff/cross-project.mdx +1 -7
- package/docs/en/guides/advanced-features/bff/extend-server.mdx +18 -3
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +1 -1
- package/docs/en/guides/advanced-features/bff/function.mdx +2 -6
- package/docs/en/guides/advanced-features/bff/sdk.mdx +3 -3
- package/docs/en/guides/advanced-features/build-performance.mdx +23 -26
- package/docs/en/guides/advanced-features/compatibility.mdx +53 -9
- package/docs/en/guides/advanced-features/international/_meta.json +11 -0
- package/docs/en/guides/advanced-features/international/advanced.mdx +193 -0
- package/docs/en/guides/advanced-features/international/api.mdx +400 -0
- package/docs/en/guides/advanced-features/international/basic.mdx +417 -0
- package/docs/en/guides/advanced-features/international/best-practices.mdx +135 -0
- package/docs/en/guides/advanced-features/international/configuration.mdx +437 -0
- package/docs/en/guides/advanced-features/international/locale-detection.mdx +276 -0
- package/docs/en/guides/advanced-features/international/quick-start.mdx +154 -0
- package/docs/en/guides/advanced-features/international/resource-loading.mdx +417 -0
- package/docs/en/guides/advanced-features/international/routing.mdx +212 -0
- package/docs/en/guides/advanced-features/international.mdx +37 -0
- package/docs/en/guides/advanced-features/low-level.mdx +21 -16
- package/docs/en/guides/advanced-features/page-performance/code-split.mdx +4 -4
- package/docs/en/guides/advanced-features/page-performance/inline-assets.mdx +4 -4
- package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +7 -21
- package/docs/en/guides/advanced-features/page-performance/react-compiler.mdx +1 -8
- package/docs/en/guides/advanced-features/rspack-start.mdx +2 -22
- package/docs/en/guides/advanced-features/server-monitor/logger.mdx +0 -4
- package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +62 -34
- package/docs/en/guides/advanced-features/web-server.mdx +82 -299
- package/docs/en/guides/basic-features/_meta.json +6 -1
- package/docs/en/guides/basic-features/css/css-in-js.mdx +46 -11
- package/docs/en/guides/basic-features/css/css-modules.mdx +5 -17
- package/docs/en/guides/basic-features/css/css.mdx +3 -3
- package/docs/en/guides/basic-features/css/tailwindcss.mdx +5 -89
- package/docs/en/guides/basic-features/data/data-cache.mdx +5 -1
- package/docs/en/guides/basic-features/data/data-fetch.mdx +4 -4
- package/docs/en/guides/basic-features/data/data-write.mdx +2 -2
- package/docs/en/guides/basic-features/debug/mock.mdx +4 -1
- package/docs/en/guides/basic-features/debug/proxy.mdx +0 -8
- package/docs/en/guides/basic-features/debug/rsdoctor.mdx +5 -5
- package/docs/en/guides/basic-features/deploy.mdx +25 -18
- package/docs/en/guides/basic-features/env-vars.mdx +1 -1
- package/docs/en/guides/basic-features/html.mdx +1 -1
- package/docs/en/guides/basic-features/output-files.mdx +3 -3
- package/docs/en/guides/basic-features/render/_meta.json +1 -1
- package/docs/en/guides/basic-features/render/before-render.mdx +16 -23
- package/docs/en/guides/basic-features/render/overview.mdx +51 -0
- package/docs/en/guides/basic-features/render/rsc.mdx +394 -0
- package/docs/en/guides/basic-features/render/ssg.mdx +26 -62
- package/docs/en/guides/basic-features/render/ssr-cache.mdx +6 -6
- package/docs/en/guides/basic-features/render/ssr.mdx +31 -31
- package/docs/en/guides/basic-features/render/streaming-ssr.mdx +29 -9
- package/docs/en/guides/basic-features/routes/_meta.json +1 -0
- package/docs/en/guides/basic-features/routes/config-routes.mdx +427 -0
- package/docs/en/guides/basic-features/{routes.mdx → routes/routes.mdx} +7 -110
- package/docs/en/guides/basic-features/static-assets/json-files.mdx +21 -3
- package/docs/en/guides/basic-features/static-assets.mdx +2 -2
- package/docs/en/guides/concept/builder.mdx +24 -9
- package/docs/en/guides/concept/entries.mdx +139 -147
- package/docs/en/guides/get-started/glossary.mdx +0 -18
- package/docs/en/guides/get-started/introduction.mdx +1 -4
- package/docs/en/guides/get-started/quick-start.mdx +8 -73
- package/docs/en/guides/get-started/tech-stack.mdx +7 -25
- package/docs/en/guides/get-started/upgrade.mdx +30 -23
- package/docs/en/guides/topic-detail/_meta.json +0 -12
- package/docs/en/guides/topic-detail/module-federation/_meta.json +1 -1
- package/docs/en/guides/topic-detail/module-federation/application.mdx +16 -15
- package/docs/en/guides/topic-detail/module-federation/i18n.mdx +670 -0
- package/docs/en/guides/topic-detail/module-federation/introduce.mdx +5 -4
- package/docs/en/guides/topic-detail/module-federation/ssr.mdx +50 -2
- package/docs/en/guides/topic-detail/module-federation/usage.mdx +10 -30
- package/docs/en/guides/troubleshooting/builder.mdx +3 -82
- package/docs/en/guides/troubleshooting/cli.mdx +6 -30
- package/docs/en/guides/troubleshooting/dependencies.mdx +22 -22
- package/docs/en/plugin/cli-plugins/api.mdx +4 -5
- package/docs/en/plugin/cli-plugins/migration.mdx +33 -48
- package/docs/en/plugin/introduction.mdx +39 -27
- package/docs/en/plugin/official/_meta.json +0 -5
- package/docs/en/plugin/official/cli-plugins/_meta.json +1 -1
- package/docs/en/plugin/official/cli-plugins/plugin-styled-components.mdx +5 -0
- package/docs/en/plugin/official/cli-plugins.mdx +0 -2
- package/docs/en/plugin/plugin-system.mdx +68 -61
- package/docs/en/plugin/runtime-plugins/api.mdx +62 -59
- package/docs/en/plugin/runtime-plugins/migration.mdx +29 -20
- package/docs/en/tutorials/_meta.json +0 -10
- package/docs/en/tutorials/examples/csr-auth.mdx +1 -1
- package/docs/en/tutorials/foundations/introduction.mdx +9 -25
- package/docs/zh/{_meta.json → _nav.json} +10 -6
- package/docs/zh/apis/app/commands.mdx +2 -3
- package/docs/zh/apis/app/hooks/src/entry.mdx +1 -5
- package/docs/zh/apis/app/hooks/src/entry.server.mdx +4 -5
- package/docs/zh/apis/app/hooks/src/routes.mdx +2 -2
- package/docs/zh/apis/app/runtime/_meta.json +0 -18
- package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +2 -2
- package/docs/zh/apis/app/runtime/utility/css-in-js.mdx +3 -2
- package/docs/zh/community/blog/v2-release-note.mdx +0 -2
- package/docs/zh/community/contributing-guide.mdx +10 -12
- package/docs/zh/components/auto-upgrade.mdx +0 -0
- package/docs/zh/components/bff-upload.mdx +8 -5
- package/docs/zh/components/build-output.mdx +45 -0
- package/docs/zh/components/debug-app.mdx +1 -1
- package/docs/zh/components/enable-bff-caution.mdx +1 -1
- package/docs/zh/components/enable-bff.mdx +37 -8
- package/docs/zh/components/enable-ssg.mdx +47 -0
- package/docs/zh/components/entry-scan-logic.mdx +7 -0
- package/docs/zh/components/init-app.mdx +40 -18
- package/docs/zh/components/international/install-command.mdx +8 -0
- package/docs/zh/components/international/introduce.mdx +2 -0
- package/docs/zh/components/international/platform-support.mdx +0 -0
- package/docs/zh/components/module-federation.mdx +4 -4
- package/docs/zh/components/new-entry-tooltip.mdx +0 -0
- package/docs/zh/components/nodeVersion.mdx +3 -7
- package/docs/zh/components/prerequisites.mdx +1 -1
- package/docs/zh/components/self-route-example.mdx +3 -3
- package/docs/zh/components/ua-polyfill.mdx +11 -6
- package/docs/zh/components/upgrade-browserslist.mdx +0 -0
- package/docs/zh/configure/_meta.json +7 -8
- package/docs/zh/configure/app/bff/cross-project.mdx +24 -0
- package/docs/zh/configure/app/dev/lazy-compilation.mdx +44 -0
- package/docs/zh/configure/app/dev/server.mdx +104 -0
- package/docs/zh/configure/app/dev/setup-middlewares.mdx +4 -23
- package/docs/zh/configure/app/html/app-icon.mdx +1 -23
- package/docs/zh/configure/app/output/inline-scripts.mdx +1 -1
- package/docs/zh/configure/app/output/override-browserslist.mdx +3 -3
- package/docs/zh/configure/app/output/source-map.mdx +10 -3
- package/docs/zh/configure/app/output/ssg.mdx +13 -45
- package/docs/zh/configure/app/output/ssgByEntries.mdx +94 -0
- package/docs/zh/configure/app/performance/build-cache.mdx +0 -4
- package/docs/zh/configure/app/resolve/alias-strategy.mdx +14 -0
- package/docs/zh/configure/app/resolve/alias.mdx +13 -0
- package/docs/zh/configure/app/resolve/condition-names.mdx +18 -0
- package/docs/zh/configure/app/resolve/dedupe.mdx +14 -0
- package/docs/zh/configure/app/resolve/extensions.mdx +18 -0
- package/docs/zh/configure/app/runtime/0-intro.mdx +2 -53
- package/docs/zh/configure/app/security/check-syntax.mdx +1 -1
- package/docs/zh/configure/app/server/port.mdx +2 -21
- package/docs/zh/configure/app/server/rsc.mdx +30 -0
- package/docs/zh/configure/app/server/ssr.mdx +21 -11
- package/docs/zh/configure/app/source/decorators.mdx +4 -4
- package/docs/zh/configure/app/source/entries.mdx +0 -2
- package/docs/zh/configure/app/source/main-entry-name.mdx +4 -4
- package/docs/zh/configure/app/source/transform-import.mdx +1 -59
- package/docs/zh/configure/app/tools/bundler-chain.mdx +6 -6
- package/docs/zh/configure/app/tools/css-extract.mdx +1 -1
- package/docs/zh/configure/app/tools/dev-server.mdx +14 -248
- package/docs/zh/configure/app/tools/html-plugin.mdx +3 -2
- package/docs/zh/configure/app/tools/lightningcss-loader.mdx +0 -1
- package/docs/zh/configure/app/tools/swc.mdx +1 -43
- package/docs/zh/configure/app/usage.mdx +8 -18
- package/docs/zh/guides/_meta.json +5 -1
- package/docs/zh/guides/advanced-features/_meta.json +6 -1
- package/docs/zh/guides/advanced-features/bff/cross-project.mdx +8 -16
- package/docs/zh/guides/advanced-features/bff/extend-server.mdx +25 -8
- package/docs/zh/guides/advanced-features/bff/frameworks.mdx +1 -1
- package/docs/zh/guides/advanced-features/bff/function.mdx +7 -12
- package/docs/zh/guides/advanced-features/bff/sdk.mdx +4 -4
- package/docs/zh/guides/advanced-features/build-performance.mdx +23 -30
- package/docs/zh/guides/advanced-features/compatibility.mdx +44 -0
- package/docs/zh/guides/advanced-features/international/_meta.json +11 -0
- package/docs/zh/guides/advanced-features/international/advanced.mdx +193 -0
- package/docs/zh/guides/advanced-features/international/api.mdx +400 -0
- package/docs/zh/guides/advanced-features/international/basic.mdx +416 -0
- package/docs/zh/guides/advanced-features/international/best-practices.mdx +135 -0
- package/docs/zh/guides/advanced-features/international/configuration.mdx +441 -0
- package/docs/zh/guides/advanced-features/international/locale-detection.mdx +304 -0
- package/docs/zh/guides/advanced-features/international/quick-start.mdx +149 -0
- package/docs/zh/guides/advanced-features/international/resource-loading.mdx +417 -0
- package/docs/zh/guides/advanced-features/international/routing.mdx +212 -0
- package/docs/zh/guides/advanced-features/international.mdx +36 -0
- package/docs/zh/guides/advanced-features/low-level.mdx +21 -16
- package/docs/zh/guides/advanced-features/page-performance/code-split.mdx +3 -3
- package/docs/zh/guides/advanced-features/page-performance/inline-assets.mdx +4 -4
- package/docs/zh/guides/advanced-features/page-performance/optimize-bundle.mdx +7 -21
- package/docs/zh/guides/advanced-features/page-performance/react-compiler.mdx +1 -8
- package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +0 -4
- package/docs/zh/guides/advanced-features/server-monitor/monitors.mdx +63 -35
- package/docs/zh/guides/advanced-features/web-server.mdx +79 -300
- package/docs/zh/guides/basic-features/_meta.json +6 -1
- package/docs/zh/guides/basic-features/css/css-in-js.mdx +40 -5
- package/docs/zh/guides/basic-features/css/css-modules.mdx +6 -17
- package/docs/zh/guides/basic-features/css/css.mdx +2 -2
- package/docs/zh/guides/basic-features/css/tailwindcss.mdx +6 -90
- package/docs/zh/guides/basic-features/data/data-cache.mdx +8 -5
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +6 -5
- package/docs/zh/guides/basic-features/data/data-write.mdx +4 -4
- package/docs/zh/guides/basic-features/debug/mock.mdx +4 -1
- package/docs/zh/guides/basic-features/debug/proxy.mdx +0 -8
- package/docs/zh/guides/basic-features/debug/rsdoctor.mdx +6 -6
- package/docs/zh/guides/basic-features/deploy.mdx +24 -20
- package/docs/zh/guides/basic-features/env-vars.mdx +1 -1
- package/docs/zh/guides/basic-features/html.mdx +2 -2
- package/docs/zh/guides/basic-features/output-files.mdx +3 -3
- package/docs/zh/guides/basic-features/render/_meta.json +1 -1
- package/docs/zh/guides/basic-features/render/before-render.mdx +17 -24
- package/docs/zh/guides/basic-features/render/overview.mdx +52 -0
- package/docs/zh/guides/basic-features/render/rsc.mdx +413 -0
- package/docs/zh/guides/basic-features/render/ssg.mdx +27 -69
- package/docs/zh/guides/basic-features/render/ssr-cache.mdx +5 -5
- package/docs/zh/guides/basic-features/render/ssr.mdx +34 -31
- package/docs/zh/guides/basic-features/render/streaming-ssr.mdx +34 -14
- package/docs/zh/guides/basic-features/routes/_meta.json +1 -0
- package/docs/zh/guides/basic-features/routes/config-routes.mdx +426 -0
- package/docs/zh/guides/basic-features/{routes.mdx → routes/routes.mdx} +8 -114
- package/docs/zh/guides/basic-features/static-assets/json-files.mdx +21 -3
- package/docs/zh/guides/basic-features/static-assets.mdx +2 -2
- package/docs/zh/guides/basic-features/testing/cypress.mdx +5 -5
- package/docs/zh/guides/basic-features/testing/jest.mdx +12 -12
- package/docs/zh/guides/concept/builder.mdx +24 -9
- package/docs/zh/guides/concept/entries.mdx +95 -92
- package/docs/zh/guides/get-started/glossary.mdx +0 -18
- package/docs/zh/guides/get-started/introduction.mdx +1 -5
- package/docs/zh/guides/get-started/quick-start.mdx +5 -72
- package/docs/zh/guides/get-started/tech-stack.mdx +8 -26
- package/docs/zh/guides/get-started/upgrade.mdx +30 -23
- package/docs/zh/guides/topic-detail/_meta.json +0 -12
- package/docs/zh/guides/topic-detail/module-federation/_meta.json +1 -1
- package/docs/zh/guides/topic-detail/module-federation/application.mdx +18 -16
- package/docs/zh/guides/topic-detail/module-federation/i18n.mdx +623 -0
- package/docs/zh/guides/topic-detail/module-federation/introduce.mdx +4 -4
- package/docs/zh/guides/topic-detail/module-federation/ssr.mdx +51 -5
- package/docs/zh/guides/topic-detail/module-federation/usage.mdx +11 -32
- package/docs/zh/guides/troubleshooting/builder.mdx +3 -84
- package/docs/zh/guides/troubleshooting/cli.mdx +6 -30
- package/docs/zh/guides/troubleshooting/dependencies.mdx +23 -23
- package/docs/zh/guides/upgrade/_meta.json +1 -0
- package/docs/zh/guides/upgrade/config.mdx +809 -0
- package/docs/zh/guides/upgrade/entry.mdx +463 -0
- package/docs/zh/guides/upgrade/other.md +90 -0
- package/docs/zh/guides/upgrade/overview.mdx +36 -0
- package/docs/zh/guides/upgrade/tailwindcss.mdx +130 -0
- package/docs/zh/guides/upgrade/web-server.md +93 -0
- package/docs/zh/plugin/cli-plugins/api.mdx +4 -5
- package/docs/zh/plugin/cli-plugins/migration.mdx +30 -45
- package/docs/zh/plugin/introduction.mdx +36 -24
- package/docs/zh/plugin/official/_meta.json +0 -5
- package/docs/zh/plugin/official/cli-plugins/_meta.json +1 -1
- package/docs/zh/plugin/official/cli-plugins/plugin-styled-components.mdx +5 -0
- package/docs/zh/plugin/official/cli-plugins.mdx +0 -2
- package/docs/zh/plugin/plugin-system.mdx +45 -42
- package/docs/zh/plugin/runtime-plugins/api.mdx +58 -56
- package/docs/zh/plugin/runtime-plugins/migration.mdx +26 -17
- package/docs/zh/tutorials/_meta.json +0 -10
- package/docs/zh/tutorials/examples/csr-auth.mdx +1 -1
- package/docs/zh/tutorials/foundations/introduction.mdx +8 -25
- package/i18n.json +0 -16
- package/package.json +12 -12
- package/rspress.config.ts +5 -8
- package/src/components/ContentCard/index.module.scss +11 -7
- package/src/components/ContentCard/index.tsx +1 -1
- package/src/components/FeatureLayout/index.module.css +1 -1
- package/src/components/Footer/index.tsx +2 -14
- package/src/components/Footer/styles.module.scss +5 -5
- package/src/components/ListCard/index.tsx +1 -1
- package/src/components/RandomMemberList/index.tsx +1 -1
- package/src/components/RsbuildLink/index.tsx +1 -1
- package/src/components/Sandpack/index.tsx +1 -1
- package/src/custom.scss +15 -0
- package/src/i18n/enUS.ts +2 -4
- package/src/i18n/index.ts +1 -1
- package/src/i18n/zhCN.ts +2 -4
- package/src/index.ts +2 -1
- package/src/pages/index.module.scss +59 -41
- package/src/pages/index.tsx +9 -24
- package/docs/en/apis/app/hooks/server/index_.mdx +0 -10
- package/docs/en/apis/app/hooks/src/index_.mdx +0 -38
- package/docs/en/apis/app/hooks/src/stories.mdx +0 -16
- package/docs/en/apis/app/runtime/app/define-config.mdx +0 -67
- package/docs/en/apis/app/runtime/core/bootstrap.mdx +0 -74
- package/docs/en/apis/app/runtime/core/create-app.mdx +0 -49
- package/docs/en/apis/app/runtime/core/use-loader.mdx +0 -89
- package/docs/en/apis/app/runtime/core/use-module-apps.mdx +0 -140
- package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +0 -116
- package/docs/en/apis/app/runtime/model/Provider.mdx +0 -36
- package/docs/en/apis/app/runtime/model/auto-actions.mdx +0 -122
- package/docs/en/apis/app/runtime/model/connect.mdx +0 -146
- package/docs/en/apis/app/runtime/model/create-app.mdx +0 -75
- package/docs/en/apis/app/runtime/model/create-store.mdx +0 -61
- package/docs/en/apis/app/runtime/model/handle-effect.mdx +0 -107
- package/docs/en/apis/app/runtime/model/model_.mdx +0 -198
- package/docs/en/apis/app/runtime/model/use-local-model.mdx +0 -29
- package/docs/en/apis/app/runtime/model/use-model.mdx +0 -89
- package/docs/en/apis/app/runtime/model/use-static-model.mdx +0 -51
- package/docs/en/apis/app/runtime/model/use-store.mdx +0 -26
- package/docs/en/apis/app/runtime/ssr/pre-render.mdx +0 -96
- package/docs/en/apis/app/runtime/web-server/hook.mdx +0 -134
- package/docs/en/apis/app/runtime/web-server/middleware.mdx +0 -113
- package/docs/en/apis/app/runtime/web-server/unstable_middleware.mdx +0 -167
- package/docs/en/components/bff-proxy-path-rewrite.mdx +0 -16
- package/docs/en/components/bff-proxy-principle.mdx +0 -1
- package/docs/en/components/builder.mdx +0 -3
- package/docs/en/components/create-bff-api-app.mdx +0 -25
- package/docs/en/components/custom-router-micro-frontend.mdx +0 -40
- package/docs/en/components/enable-micro-frontend.mdx +0 -30
- package/docs/en/components/enableSwc.mdx +0 -17
- package/docs/en/components/global-proxy-config.mdx +0 -85
- package/docs/en/components/global-proxy.mdx +0 -29
- package/docs/en/components/package-manager.mdx +0 -11
- package/docs/en/components/reduck-notify.mdx +0 -27
- package/docs/en/components/reduck-tip.mdx +0 -8
- package/docs/en/configure/app/auto-load-plugin.mdx +0 -66
- package/docs/en/configure/app/deploy/microFrontend.mdx +0 -53
- package/docs/en/configure/app/dev/port.mdx +0 -25
- package/docs/en/configure/app/dev/proxy.mdx +0 -9
- package/docs/en/configure/app/experiments/lazy-compilation.mdx +0 -106
- package/docs/en/configure/app/html/disable-html-folder.mdx +0 -46
- package/docs/en/configure/app/html/favicon-by-entries.mdx +0 -36
- package/docs/en/configure/app/html/inject-by-entries.mdx +0 -36
- package/docs/en/configure/app/html/meta-by-entries.mdx +0 -48
- package/docs/en/configure/app/html/tags-by-entries.mdx +0 -44
- package/docs/en/configure/app/html/template-by-entries.mdx +0 -33
- package/docs/en/configure/app/html/template-parameters-by-entries.mdx +0 -35
- package/docs/en/configure/app/html/title-by-entries.mdx +0 -37
- package/docs/en/configure/app/output/css-module-local-ident-name.mdx +0 -21
- package/docs/en/configure/app/output/disable-css-extract.mdx +0 -16
- package/docs/en/configure/app/output/disable-filename-hash.mdx +0 -16
- package/docs/en/configure/app/output/disable-minimize.mdx +0 -14
- package/docs/en/configure/app/output/disable-node-polyfill.mdx +0 -22
- package/docs/en/configure/app/output/disable-source-map.mdx +0 -31
- package/docs/en/configure/app/output/enable-asset-fallback.mdx +0 -36
- package/docs/en/configure/app/output/enable-inline-scripts.mdx +0 -22
- package/docs/en/configure/app/output/enable-inline-styles.mdx +0 -22
- package/docs/en/configure/app/output/enable-latest-decorators.mdx +0 -14
- package/docs/en/configure/app/performance/transform-lodash.mdx +0 -52
- package/docs/en/configure/app/runtime/master-app.mdx +0 -36
- package/docs/en/configure/app/runtime/state.mdx +0 -52
- package/docs/en/configure/app/source/disable-entry-dirs.mdx +0 -38
- package/docs/en/configure/app/source/enable-custom-entry.mdx +0 -68
- package/docs/en/configure/app/source/module-scopes.mdx +0 -72
- package/docs/en/configure/app/source/resolve-extension-prefix.mdx +0 -55
- package/docs/en/configure/app/source/resolve-main-fields.mdx +0 -46
- package/docs/en/configure/app/tools/esbuild.mdx +0 -44
- package/docs/en/configure/app/tools/pug.mdx +0 -54
- package/docs/en/configure/app/tools/styled-components.mdx +0 -55
- package/docs/en/configure/app/tools/tailwindcss.mdx +0 -98
- package/docs/en/configure/app/tools/terser.mdx +0 -58
- package/docs/en/configure/app/tools/ts-loader.mdx +0 -76
- package/docs/en/configure/app/tools/webpack-chain.mdx +0 -249
- package/docs/en/configure/app/tools/webpack.mdx +0 -305
- package/docs/en/guides/deprecated.md +0 -17
- package/docs/en/guides/topic-detail/micro-frontend/c01-introduction.mdx +0 -27
- package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +0 -290
- package/docs/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +0 -298
- package/docs/en/guides/topic-detail/micro-frontend/c04-communicate.mdx +0 -58
- package/docs/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +0 -26
- package/docs/en/guides/topic-detail/model/_meta.json +0 -14
- package/docs/en/guides/topic-detail/model/auto-actions.mdx +0 -85
- package/docs/en/guides/topic-detail/model/computed-state.mdx +0 -148
- package/docs/en/guides/topic-detail/model/define-model.mdx +0 -62
- package/docs/en/guides/topic-detail/model/faq.mdx +0 -35
- package/docs/en/guides/topic-detail/model/manage-effects.mdx +0 -247
- package/docs/en/guides/topic-detail/model/model-communicate.mdx +0 -217
- package/docs/en/guides/topic-detail/model/performance.mdx +0 -167
- package/docs/en/guides/topic-detail/model/quick-start.mdx +0 -117
- package/docs/en/guides/topic-detail/model/redux-integration.mdx +0 -20
- package/docs/en/guides/topic-detail/model/typescript-best-practice.mdx +0 -68
- package/docs/en/guides/topic-detail/model/use-model.mdx +0 -243
- package/docs/en/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -46
- package/docs/en/plugin/official/cli-plugins/plugin-swc.mdx +0 -363
- package/docs/en/plugin/official/cli-plugins/plugin-tailwind.mdx +0 -5
- package/docs/en/plugin/official/rsbuild-plugins/_meta.json +0 -1
- package/docs/en/plugin/official/rsbuild-plugins/plugin-esbuild.mdx +0 -205
- package/docs/en/plugin/official/rsbuild-plugins.mdx +0 -3
- package/docs/en/tutorials/first-app/c01-start.mdx +0 -99
- package/docs/en/tutorials/first-app/c02-component.mdx +0 -60
- package/docs/en/tutorials/first-app/c03-css.mdx +0 -324
- package/docs/en/tutorials/first-app/c04-routes.mdx +0 -172
- package/docs/en/tutorials/first-app/c05-loader.mdx +0 -87
- package/docs/en/tutorials/first-app/c06-model.mdx +0 -278
- package/docs/en/tutorials/first-app/c07-container.mdx +0 -281
- package/docs/en/tutorials/first-app/c08-entries.mdx +0 -135
- package/docs/zh/apis/app/hooks/server/index_.mdx +0 -10
- package/docs/zh/apis/app/hooks/src/index_.mdx +0 -39
- package/docs/zh/apis/app/hooks/src/stories.mdx +0 -16
- package/docs/zh/apis/app/runtime/app/define-config.mdx +0 -67
- package/docs/zh/apis/app/runtime/core/bootstrap.mdx +0 -74
- package/docs/zh/apis/app/runtime/core/create-app.mdx +0 -35
- package/docs/zh/apis/app/runtime/core/use-loader.mdx +0 -89
- package/docs/zh/apis/app/runtime/core/use-module-apps.mdx +0 -179
- package/docs/zh/apis/app/runtime/core/use-runtime-context.mdx +0 -116
- package/docs/zh/apis/app/runtime/model/Provider.mdx +0 -36
- package/docs/zh/apis/app/runtime/model/auto-actions.mdx +0 -122
- package/docs/zh/apis/app/runtime/model/connect.mdx +0 -143
- package/docs/zh/apis/app/runtime/model/create-app.mdx +0 -75
- package/docs/zh/apis/app/runtime/model/create-store.mdx +0 -61
- package/docs/zh/apis/app/runtime/model/handle-effect.mdx +0 -108
- package/docs/zh/apis/app/runtime/model/model_.mdx +0 -201
- package/docs/zh/apis/app/runtime/model/use-local-model.mdx +0 -29
- package/docs/zh/apis/app/runtime/model/use-model.mdx +0 -89
- package/docs/zh/apis/app/runtime/model/use-static-model.mdx +0 -49
- package/docs/zh/apis/app/runtime/model/use-store.mdx +0 -26
- package/docs/zh/apis/app/runtime/ssr/pre-render.mdx +0 -96
- package/docs/zh/apis/app/runtime/web-server/hook.mdx +0 -136
- package/docs/zh/apis/app/runtime/web-server/middleware.mdx +0 -114
- package/docs/zh/apis/app/runtime/web-server/unstable_middleware.mdx +0 -165
- package/docs/zh/components/bff-proxy-path-rewrite.mdx +0 -16
- package/docs/zh/components/bff-proxy-principle.mdx +0 -1
- package/docs/zh/components/builder.mdx +0 -3
- package/docs/zh/components/create-bff-api-app.mdx +0 -25
- package/docs/zh/components/custom-router-micro-frontend.mdx +0 -40
- package/docs/zh/components/enable-micro-frontend.mdx +0 -30
- package/docs/zh/components/enableSwc.mdx +0 -17
- package/docs/zh/components/global-proxy-config.mdx +0 -85
- package/docs/zh/components/global-proxy.mdx +0 -29
- package/docs/zh/components/package-manager.mdx +0 -11
- package/docs/zh/components/reduck-notify.mdx +0 -27
- package/docs/zh/components/reduck-tip.mdx +0 -8
- package/docs/zh/configure/app/auto-load-plugin.mdx +0 -66
- package/docs/zh/configure/app/deploy/microFrontend.mdx +0 -55
- package/docs/zh/configure/app/dev/port.mdx +0 -25
- package/docs/zh/configure/app/dev/proxy.mdx +0 -9
- package/docs/zh/configure/app/experiments/lazy-compilation.mdx +0 -105
- package/docs/zh/configure/app/html/disable-html-folder.mdx +0 -45
- package/docs/zh/configure/app/html/favicon-by-entries.mdx +0 -37
- package/docs/zh/configure/app/html/inject-by-entries.mdx +0 -37
- package/docs/zh/configure/app/html/meta-by-entries.mdx +0 -48
- package/docs/zh/configure/app/html/tags-by-entries.mdx +0 -44
- package/docs/zh/configure/app/html/template-by-entries.mdx +0 -33
- package/docs/zh/configure/app/html/template-parameters-by-entries.mdx +0 -36
- package/docs/zh/configure/app/html/title-by-entries.mdx +0 -37
- package/docs/zh/configure/app/output/css-module-local-ident-name.mdx +0 -21
- package/docs/zh/configure/app/output/disable-css-extract.mdx +0 -16
- package/docs/zh/configure/app/output/disable-filename-hash.mdx +0 -16
- package/docs/zh/configure/app/output/disable-minimize.mdx +0 -14
- package/docs/zh/configure/app/output/disable-node-polyfill.mdx +0 -22
- package/docs/zh/configure/app/output/disable-source-map.mdx +0 -31
- package/docs/zh/configure/app/output/enable-asset-fallback.mdx +0 -36
- package/docs/zh/configure/app/output/enable-inline-scripts.mdx +0 -22
- package/docs/zh/configure/app/output/enable-inline-styles.mdx +0 -22
- package/docs/zh/configure/app/output/enable-latest-decorators.mdx +0 -14
- package/docs/zh/configure/app/performance/transform-lodash.mdx +0 -52
- package/docs/zh/configure/app/runtime/master-app.mdx +0 -38
- package/docs/zh/configure/app/runtime/state.mdx +0 -52
- package/docs/zh/configure/app/source/disable-entry-dirs.mdx +0 -38
- package/docs/zh/configure/app/source/enable-custom-entry.mdx +0 -67
- package/docs/zh/configure/app/source/module-scopes.mdx +0 -72
- package/docs/zh/configure/app/source/resolve-extension-prefix.mdx +0 -57
- package/docs/zh/configure/app/source/resolve-main-fields.mdx +0 -46
- package/docs/zh/configure/app/tools/esbuild.mdx +0 -44
- package/docs/zh/configure/app/tools/pug.mdx +0 -54
- package/docs/zh/configure/app/tools/styled-components.mdx +0 -54
- package/docs/zh/configure/app/tools/tailwindcss.mdx +0 -98
- package/docs/zh/configure/app/tools/terser.mdx +0 -58
- package/docs/zh/configure/app/tools/ts-loader.mdx +0 -76
- package/docs/zh/configure/app/tools/webpack-chain.mdx +0 -253
- package/docs/zh/configure/app/tools/webpack.mdx +0 -305
- package/docs/zh/guides/advanced-features/rspack-start.mdx +0 -154
- package/docs/zh/guides/deprecated.md +0 -19
- package/docs/zh/guides/topic-detail/micro-frontend/c01-introduction.mdx +0 -26
- package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +0 -332
- package/docs/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +0 -296
- package/docs/zh/guides/topic-detail/micro-frontend/c04-communicate.mdx +0 -58
- package/docs/zh/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +0 -27
- package/docs/zh/guides/topic-detail/model/_meta.json +0 -14
- package/docs/zh/guides/topic-detail/model/auto-actions.mdx +0 -88
- package/docs/zh/guides/topic-detail/model/computed-state.mdx +0 -147
- package/docs/zh/guides/topic-detail/model/define-model.mdx +0 -63
- package/docs/zh/guides/topic-detail/model/faq.mdx +0 -36
- package/docs/zh/guides/topic-detail/model/manage-effects.mdx +0 -256
- package/docs/zh/guides/topic-detail/model/model-communicate.mdx +0 -217
- package/docs/zh/guides/topic-detail/model/performance.mdx +0 -167
- package/docs/zh/guides/topic-detail/model/quick-start.mdx +0 -117
- package/docs/zh/guides/topic-detail/model/redux-integration.mdx +0 -20
- package/docs/zh/guides/topic-detail/model/typescript-best-practice.mdx +0 -67
- package/docs/zh/guides/topic-detail/model/use-model.mdx +0 -248
- package/docs/zh/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -46
- package/docs/zh/plugin/official/cli-plugins/plugin-swc.mdx +0 -351
- package/docs/zh/plugin/official/cli-plugins/plugin-tailwind.mdx +0 -5
- package/docs/zh/plugin/official/rsbuild-plugins/_meta.json +0 -1
- package/docs/zh/plugin/official/rsbuild-plugins/plugin-esbuild.mdx +0 -201
- package/docs/zh/plugin/official/rsbuild-plugins.mdx +0 -3
- package/docs/zh/tutorials/first-app/c01-start.mdx +0 -99
- package/docs/zh/tutorials/first-app/c02-component.mdx +0 -60
- package/docs/zh/tutorials/first-app/c03-css.mdx +0 -323
- package/docs/zh/tutorials/first-app/c04-routes.mdx +0 -172
- package/docs/zh/tutorials/first-app/c05-loader.mdx +0 -89
- package/docs/zh/tutorials/first-app/c06-model.mdx +0 -274
- package/docs/zh/tutorials/first-app/c07-container.mdx +0 -281
- package/docs/zh/tutorials/first-app/c08-entries.mdx +0 -135
- /package/docs/en/components/{reduck-migration.mdx → auto-upgrade.mdx} +0 -0
- /package/docs/{zh/components/reduck-migration.mdx → en/components/international/platform-support.mdx} +0 -0
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: PreRender
|
|
3
|
-
---
|
|
4
|
-
# PreRender
|
|
5
|
-
|
|
6
|
-
无展示内容的高阶组件,通过类似 Helmet 的方式实现 SPA 路由级的缓存,无需额外配置。
|
|
7
|
-
|
|
8
|
-
## 使用姿势
|
|
9
|
-
|
|
10
|
-
```tsx
|
|
11
|
-
import { PreRender } from '@modern-js/runtime/ssr';
|
|
12
|
-
|
|
13
|
-
export default () => (
|
|
14
|
-
<>
|
|
15
|
-
<PreRender interval={5} />
|
|
16
|
-
</>
|
|
17
|
-
);
|
|
18
|
-
```
|
|
19
|
-
|
|
20
|
-
## 函数签名
|
|
21
|
-
|
|
22
|
-
`PreRender` 组件提供了一套常用的配置参数,用于控制缓存的规则、过期时间、缓存算法等。
|
|
23
|
-
|
|
24
|
-
```tsx
|
|
25
|
-
type Props {
|
|
26
|
-
interval: number;
|
|
27
|
-
staleLimit: number;
|
|
28
|
-
level: number;
|
|
29
|
-
include: { header?: string[], query?: string[] };
|
|
30
|
-
matches: { header?: Record<string, any>, query?: Record<string, any> }
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function PreRender(props: Props): React.Component
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
### 参数
|
|
37
|
-
|
|
38
|
-
- `interval`:设置缓存保持新鲜的时间,单位秒。在该时间内,将直接使用缓存,并且不做异步渲染。
|
|
39
|
-
- `staleLimit`:设置缓存完全过期的时间,单位秒。在该时间内,缓存可以被返回,并且会做一步渲染,否则必须使用重新渲染的结果。
|
|
40
|
-
- `level`:设置缓存标识的计算规则等级,通常配合 `includes` 与 `matches` 使用。默认值为 `0`。
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
0:路由路径
|
|
44
|
-
1:路由路径 + 查询字符串
|
|
45
|
-
2:路由路径 + 请求头
|
|
46
|
-
3:路由路径 + 查询字符串 + 请求头
|
|
47
|
-
```
|
|
48
|
-
|
|
49
|
-
- `includes`:设置需要被纳入缓存标识的内容,在 level 非 0 时使用。默认值为 `null`。
|
|
50
|
-
- `matches`:设置 query 或 header 的值在缓存标识计算中的重写规则,通常用在缓存分类时,支持正则表达式。默认值为 `null`。
|
|
51
|
-
|
|
52
|
-
## 示例
|
|
53
|
-
|
|
54
|
-
```tsx
|
|
55
|
-
import { PreRender } from '@modern-js/runtime/ssr';
|
|
56
|
-
|
|
57
|
-
export default function App() {
|
|
58
|
-
return (
|
|
59
|
-
<>
|
|
60
|
-
<PreRender interval={10} />
|
|
61
|
-
<div>Hello Modern</div>
|
|
62
|
-
</>
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
下面例子展示了如何将 query、header 中指定的参数纳入缓存计算中:
|
|
68
|
-
|
|
69
|
-
```tsx
|
|
70
|
-
/* 使用 query 中的 channel 和 header 中的 language 计算缓存标识 */
|
|
71
|
-
<PreRender
|
|
72
|
-
interval={10}
|
|
73
|
-
level={2}
|
|
74
|
-
includes={{
|
|
75
|
-
query: ['channel'],
|
|
76
|
-
header: ['language'],
|
|
77
|
-
}}
|
|
78
|
-
/>
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
下面例子展示了如何不让测试频道影响线上缓存:
|
|
82
|
-
|
|
83
|
-
```tsx
|
|
84
|
-
/* 将 query 中 channel 值为 test_ 开头的重写为 testChannel,否则重写为 otherChannel */
|
|
85
|
-
<PreRender interval={10} level={2} includes={{
|
|
86
|
-
query: ["channel"],
|
|
87
|
-
header: ["language"]
|
|
88
|
-
}} matches={{
|
|
89
|
-
query: {
|
|
90
|
-
channel: {
|
|
91
|
-
"testChannel", "^test_",
|
|
92
|
-
"otherChannel", ".*"
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}} />
|
|
96
|
-
```
|
|
@@ -1,136 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Hook
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Hook
|
|
6
|
-
|
|
7
|
-
:::warning
|
|
8
|
-
|
|
9
|
-
Hook API 已废弃,请使用[新版自定义 Web Server](/guides/advanced-features/web-server) 来处理页面请求。
|
|
10
|
-
|
|
11
|
-
:::
|
|
12
|
-
|
|
13
|
-
用于拓展 Modern.js 内置的 Web Server,所有的页面请求都会经过 Hook。
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
## 使用姿势
|
|
17
|
-
|
|
18
|
-
```ts
|
|
19
|
-
import { AfterMatchHook, AfterRenderHook } from '@modern-js/runtime/server';
|
|
20
|
-
|
|
21
|
-
export const afterMatch: AfterMatchHook = (context, next) => {};
|
|
22
|
-
export const afterRender: AfterRenderHook = (context, next) => {};
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
:::info 自定义 Web Server
|
|
26
|
-
使用该 API 前,请先执行 `pnpm run new` 新建「自定义 Web Serve」源码目录。
|
|
27
|
-
|
|
28
|
-
```bash
|
|
29
|
-
pnpm run new
|
|
30
|
-
? 请选择你想要的操作 创建工程元素
|
|
31
|
-
? 新建「自定义 Web Server」源码目录
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
:::
|
|
35
|
-
|
|
36
|
-
## 函数签名
|
|
37
|
-
|
|
38
|
-
```ts
|
|
39
|
-
type HookContext = {
|
|
40
|
-
response: {
|
|
41
|
-
set: (key: string, value: string) => void;
|
|
42
|
-
status: (code: number) => void;
|
|
43
|
-
getStatus: () => number;
|
|
44
|
-
cookies: {
|
|
45
|
-
set: (key: string, value: string, options?: any) => void;
|
|
46
|
-
clear: () => void;
|
|
47
|
-
};
|
|
48
|
-
raw: (
|
|
49
|
-
body: string,
|
|
50
|
-
{ status, headers }: { status: number; headers: Record<string, any> },
|
|
51
|
-
) => void;
|
|
52
|
-
};
|
|
53
|
-
request: {
|
|
54
|
-
url: string;
|
|
55
|
-
host: string;
|
|
56
|
-
pathname: string;
|
|
57
|
-
query: Record<string, any>;
|
|
58
|
-
cookie: string;
|
|
59
|
-
cookies: {
|
|
60
|
-
get: (key: string) => string;
|
|
61
|
-
};
|
|
62
|
-
headers: IncomingHttpHeaders;
|
|
63
|
-
};
|
|
64
|
-
};
|
|
65
|
-
|
|
66
|
-
function Hook(context: HookContext, next: NextFunction): Promsie<void> | void;
|
|
67
|
-
```
|
|
68
|
-
|
|
69
|
-
另外,不同 Hook 额外提供了不同的上下文。目前 Modern.js 支持 `AfterMatch` 和 `AfterRender` 两个 Hook。
|
|
70
|
-
|
|
71
|
-
```ts
|
|
72
|
-
type AfterMatchContext = HookContext & {
|
|
73
|
-
router: {
|
|
74
|
-
redirect: (url: string, status: number) => void;
|
|
75
|
-
rewrite: (entry: string) => void;
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
type AfterRenderContext = {
|
|
80
|
-
template: {
|
|
81
|
-
get: () => string;
|
|
82
|
-
set: (html: string) => void;
|
|
83
|
-
prependHead: (fragment: string) => void;
|
|
84
|
-
appendHead: (fragment: string) => void;
|
|
85
|
-
prependBody: (fragment: string) => void;
|
|
86
|
-
appendBody: (fragment: string) => void;
|
|
87
|
-
};
|
|
88
|
-
};
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### 参数
|
|
92
|
-
|
|
93
|
-
- `context`:提供当前 Hook 上下文。
|
|
94
|
-
- `response`:提供一系列处理响应的操作
|
|
95
|
-
- `request`:提供一系列获取请求信息的操作
|
|
96
|
-
- `router`:提供对响应路由的快捷操作
|
|
97
|
-
- `template`:提供对响应内容的快捷操作
|
|
98
|
-
- `next`:执行当前 Hook 的下一个监听函数(不影响整体服务端流程)。
|
|
99
|
-
|
|
100
|
-
## 示例
|
|
101
|
-
|
|
102
|
-
### Redirect
|
|
103
|
-
|
|
104
|
-
将页面重定向到站点外的页面,例如跳转到统一登录页:
|
|
105
|
-
|
|
106
|
-
```ts
|
|
107
|
-
import type { AfterMatch } from '@modern-js/runtime/server';
|
|
108
|
-
|
|
109
|
-
export const afterMatch: AfterMatch = async (ctx, next) => {
|
|
110
|
-
ctx.router.redirect('https://website.com/login', 302);
|
|
111
|
-
};
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
### Rewrite
|
|
115
|
-
|
|
116
|
-
将页面重写到当前站点的其他页面,例如同一个路由根据 UA 返回适配不同端的页面:
|
|
117
|
-
|
|
118
|
-
```ts
|
|
119
|
-
import type { AfterMatch } from '@modern-js/runtime/server';
|
|
120
|
-
|
|
121
|
-
export const afterMatch: AfterMatch = async (ctx, next) => {
|
|
122
|
-
ctx.router.rewrite('mobile');
|
|
123
|
-
};
|
|
124
|
-
```
|
|
125
|
-
|
|
126
|
-
### HTML 内容注入
|
|
127
|
-
|
|
128
|
-
为页面注入某些与渲染主体无关的 HTML 内容,如脚本、页面骨架等:
|
|
129
|
-
|
|
130
|
-
```ts
|
|
131
|
-
import type { AfterRender } from '@modern-js/runtime/server';
|
|
132
|
-
|
|
133
|
-
export const afterRender: AfterRenderHook = (context, next) => {
|
|
134
|
-
ctx.template.prependBody('<div>Footer</div>');
|
|
135
|
-
};
|
|
136
|
-
```
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Middleware
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Middleware
|
|
6
|
-
|
|
7
|
-
:::warning
|
|
8
|
-
|
|
9
|
-
Middleware 已废弃,请使用[新版自定义 Web Server](/guides/advanced-features/web-server) 来处理页面请求。
|
|
10
|
-
|
|
11
|
-
:::
|
|
12
|
-
|
|
13
|
-
用于拓展 Modern.js 内置的 Web Server,与 [Hook](/apis/app/runtime/web-server/hook) 不同的是,Middleware 可以直接操作 Node 原生的请求、响应对象,并且可以使用框架拓展。
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
## 使用姿势
|
|
17
|
-
|
|
18
|
-
```ts
|
|
19
|
-
import { Middleware } from '@modern-js/runtime/server';
|
|
20
|
-
|
|
21
|
-
export const middleware: Middleware = async (context, next) => {};
|
|
22
|
-
export const middleware: Middleware[] = [
|
|
23
|
-
async (context, next) => {},
|
|
24
|
-
async (context, next) => {},
|
|
25
|
-
];
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
:::info 自定义 Web Server
|
|
29
|
-
使用该 API 前,请先执行 `pnpm run new` 新建「自定义 Web Server」源码目录。
|
|
30
|
-
|
|
31
|
-
```bash
|
|
32
|
-
pnpm run new
|
|
33
|
-
? 请选择你想要的操作 创建工程元素
|
|
34
|
-
? 新建「自定义 Web Server」源码目录
|
|
35
|
-
```
|
|
36
|
-
|
|
37
|
-
:::
|
|
38
|
-
|
|
39
|
-
## 函数签名
|
|
40
|
-
|
|
41
|
-
```ts
|
|
42
|
-
type Middleware = (
|
|
43
|
-
context: MiddlewareContext,
|
|
44
|
-
next: NextFunction,
|
|
45
|
-
) => Promise<void> | void;
|
|
46
|
-
|
|
47
|
-
type MiddlewareContext = {
|
|
48
|
-
response: {
|
|
49
|
-
set: (key: string, value: string) => void;
|
|
50
|
-
status: (code: number) => void;
|
|
51
|
-
getStatus: () => number;
|
|
52
|
-
cookies: {
|
|
53
|
-
set: (key: string, value: string, options?: any) => void;
|
|
54
|
-
clear: () => void;
|
|
55
|
-
};
|
|
56
|
-
raw: (
|
|
57
|
-
body: string,
|
|
58
|
-
{ status, headers }: { status: number; headers: Record<string, any> },
|
|
59
|
-
) => void;
|
|
60
|
-
locals: Record<string, any>;
|
|
61
|
-
};
|
|
62
|
-
request: {
|
|
63
|
-
url: string;
|
|
64
|
-
host: string;
|
|
65
|
-
pathname: string;
|
|
66
|
-
query: Record<string, any>;
|
|
67
|
-
cookie: string;
|
|
68
|
-
cookies: {
|
|
69
|
-
get: (key: string) => string;
|
|
70
|
-
};
|
|
71
|
-
headers: IncomingHttpHeaders;
|
|
72
|
-
};
|
|
73
|
-
source: {
|
|
74
|
-
req: IncomingMessage;
|
|
75
|
-
res: ServerResponse;
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
|
-
```
|
|
79
|
-
|
|
80
|
-
### 参数
|
|
81
|
-
|
|
82
|
-
- `context`:提供当前 Hook 上下文。
|
|
83
|
-
- `response`:提供一系列处理响应的操作
|
|
84
|
-
- `request`:提供一系列获取请求信息的操作
|
|
85
|
-
- `source`:提供 Node.js 原生的 `req` 与 `res` 对象。
|
|
86
|
-
- `next`:执行当前 Hook 的下一个监听函数(不影响整体服务端流程)。
|
|
87
|
-
|
|
88
|
-
:::warning
|
|
89
|
-
`next` 函数的执行不影响后续内置流程,只控制下一个中间件是否执行。只有当响应被写入时,后续渲染流程才会中断。
|
|
90
|
-
:::
|
|
91
|
-
|
|
92
|
-
## 示例
|
|
93
|
-
|
|
94
|
-
### 服务端耗时打点
|
|
95
|
-
|
|
96
|
-
```ts
|
|
97
|
-
export const Middleware = () => async (ctx, next) => {
|
|
98
|
-
const start = Date.now();
|
|
99
|
-
ctx.source.res.once('finish', () => {
|
|
100
|
-
console.log(Date.now() - start);
|
|
101
|
-
});
|
|
102
|
-
};
|
|
103
|
-
```
|
|
104
|
-
|
|
105
|
-
### 注入服务端工具 & 数据
|
|
106
|
-
|
|
107
|
-
Modern.js 提供了 `response.locals` 属性用来存放当前请求的局部变量。
|
|
108
|
-
|
|
109
|
-
```ts
|
|
110
|
-
export const Middleware = () => async (ctx, next) => {
|
|
111
|
-
ctx.response.locals.id = 'Modern.js';
|
|
112
|
-
ctx.response.locals.rpc = createRpcInstance();
|
|
113
|
-
};
|
|
114
|
-
```
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
---
|
|
2
|
-
title: Unstable Middleware
|
|
3
|
-
---
|
|
4
|
-
|
|
5
|
-
# Unstable Middleware
|
|
6
|
-
|
|
7
|
-
:::warning
|
|
8
|
-
|
|
9
|
-
Unstable Middleware 已废弃,请使用[新版自定义 Web Server](/guides/advanced-features/web-server) 来处理页面请求。
|
|
10
|
-
|
|
11
|
-
:::
|
|
12
|
-
|
|
13
|
-
用于拓展 Modern.js 内置的 Web Server。 未来 UnstableMiddleware 将替代 [Middleware](/apis/app/runtime/web-server/middleware)
|
|
14
|
-
|
|
15
|
-
## 使用
|
|
16
|
-
|
|
17
|
-
```ts title="server/index.ts"
|
|
18
|
-
import { UnstableMiddleware } from '@modern-js/runtime/server';
|
|
19
|
-
|
|
20
|
-
export const unstableMiddleware: UnstableMiddleware[] = [];
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
## 类型
|
|
24
|
-
|
|
25
|
-
**UnstableMiddleware**
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
type UnstableMiddleware<
|
|
29
|
-
V extends Record<string, unknown> = Record<string, unknown>,
|
|
30
|
-
> = (
|
|
31
|
-
c: UnstableMiddlewareContext<V>,
|
|
32
|
-
next: UnstableNext,
|
|
33
|
-
) => Promise<void | Response>;
|
|
34
|
-
```
|
|
35
|
-
|
|
36
|
-
**UnstableMiddlewareContext**
|
|
37
|
-
|
|
38
|
-
```ts
|
|
39
|
-
type Body = ReadableStream | ArrayBuffer | string | null;
|
|
40
|
-
|
|
41
|
-
type UnstableMiddlewareContext<
|
|
42
|
-
V extends Record<string, unknown> = Record<string, unknown>,
|
|
43
|
-
> = {
|
|
44
|
-
request: Request;
|
|
45
|
-
response: Response;
|
|
46
|
-
get: Get<V>;
|
|
47
|
-
set: Set<V>;
|
|
48
|
-
header: (name: string, value: string, options?: { append?: boolean }) => void;
|
|
49
|
-
status: (code: number) => void;
|
|
50
|
-
redirect: (location: string, status?: number) => Response;
|
|
51
|
-
body: (data: Body, init?: ResponseInit) => Response;
|
|
52
|
-
html: (
|
|
53
|
-
data: string | Promise<string>,
|
|
54
|
-
init?: ResponseInit,
|
|
55
|
-
) => Response | Promise<Response>;
|
|
56
|
-
};
|
|
57
|
-
```
|
|
58
|
-
|
|
59
|
-
**UnstableNext**
|
|
60
|
-
|
|
61
|
-
```ts
|
|
62
|
-
type UnstableNext = () => Promise<void>;
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
## 用例
|
|
66
|
-
|
|
67
|
-
### web server 耗时打点
|
|
68
|
-
|
|
69
|
-
```ts
|
|
70
|
-
import { UnstableMiddleware } from '@modern-js/runtime/server';
|
|
71
|
-
|
|
72
|
-
const time: UnstableMiddleware = async (c, next) => {
|
|
73
|
-
const start = Date.now();
|
|
74
|
-
|
|
75
|
-
await next();
|
|
76
|
-
|
|
77
|
-
const end = Date.now();
|
|
78
|
-
|
|
79
|
-
console.log(`${end - start}`);
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
export const unstableMiddleware: UnstableMiddleware[] = [time];
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
### 注入服务端数据,供页面 dataLoader 消费
|
|
86
|
-
|
|
87
|
-
```ts title="shared/index.ts"
|
|
88
|
-
export type Vars = {
|
|
89
|
-
message: string;
|
|
90
|
-
};
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
```ts title="server/index.ts"
|
|
94
|
-
import {
|
|
95
|
-
UnstableMiddleware,
|
|
96
|
-
UnstableMiddlewareContext,
|
|
97
|
-
} from '@modern-js/runtime/server';
|
|
98
|
-
import type { Vars } from '../shared/index';
|
|
99
|
-
|
|
100
|
-
const setPayload: UnstableMiddleware<Vars> = async (
|
|
101
|
-
c: UnstableMiddlewareContext<Vars>,
|
|
102
|
-
next,
|
|
103
|
-
) => {
|
|
104
|
-
c.set('message', 'facker');
|
|
105
|
-
|
|
106
|
-
await next();
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
export const unstableMiddleware: UnstableMiddleware<Vars>[] = [setPayload];
|
|
110
|
-
```
|
|
111
|
-
|
|
112
|
-
```ts title="src/routes/page.data.ts"
|
|
113
|
-
import type { Payload } from '../../shared/index';
|
|
114
|
-
import { LoaderFunctionArgs } from '@modern-js/runtime/router';
|
|
115
|
-
|
|
116
|
-
export const loader = async ({ context }: LoaderFunctionArgs<Vars>) => {
|
|
117
|
-
const message = context?.get('message');
|
|
118
|
-
|
|
119
|
-
// ...
|
|
120
|
-
};
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
### 重定向
|
|
124
|
-
|
|
125
|
-
```ts
|
|
126
|
-
import { UnstableMiddleware } from '@modern-js/runtime/server';
|
|
127
|
-
|
|
128
|
-
const auth: UnstableMiddleware = async (c, next) => {
|
|
129
|
-
const user = getUser(c.request);
|
|
130
|
-
|
|
131
|
-
if (!user) {
|
|
132
|
-
return c.redirect('/login');
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
await next();
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
export const unstableMiddleware: UnstableMiddleware[] = [auth];
|
|
139
|
-
```
|
|
140
|
-
|
|
141
|
-
### 修改响应体
|
|
142
|
-
|
|
143
|
-
```ts
|
|
144
|
-
import { UnstableMiddleware } from '@modern-js/runtime/server';
|
|
145
|
-
|
|
146
|
-
const modifier: UnstableMiddleware = async (c, next) => {
|
|
147
|
-
await next();
|
|
148
|
-
|
|
149
|
-
const { response } = c;
|
|
150
|
-
|
|
151
|
-
const text = await response.text();
|
|
152
|
-
|
|
153
|
-
const newText = text.replace('<html>', `<html lang="${language}">`);
|
|
154
|
-
|
|
155
|
-
const newheaders = response.headers;
|
|
156
|
-
newheaders.set('x-custom-value', 'modern');
|
|
157
|
-
|
|
158
|
-
c.response = c.body(newText, {
|
|
159
|
-
status: response.status,
|
|
160
|
-
headers: newheaders,
|
|
161
|
-
});
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
export const unstableMiddleware: UnstableMiddleware[] = [modifier];
|
|
165
|
-
```
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
这里还可以进行路径重写,如将发送到 `localhost:8080/api/topics` 的请求代理到 `https://cnodejs.org/api/v1/topics`。
|
|
2
|
-
|
|
3
|
-
```ts title="modern.server-runtime.config.ts"
|
|
4
|
-
import { defineConfig } from '@modern-js/app-tools/server';
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
bff: {
|
|
7
|
-
proxy: {
|
|
8
|
-
'/api': {
|
|
9
|
-
target: 'https://cnodejs.org',
|
|
10
|
-
pathRewrite: { '/api/topics': '/api/v1/topics' },
|
|
11
|
-
changeOrigin: true,
|
|
12
|
-
},
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
});
|
|
16
|
-
```
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
BFF Proxy 使用了强大的 [http-proxy-middleware](https://github.com/chimurai/http-proxy-middleware),如果需要更多高级的用法, 可以查看它的[文档](https://github.com/chimurai/http-proxy-middleware#options)。
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
1. 执行 `@modern-js/create` 命令:
|
|
3
|
-
|
|
4
|
-
```bash
|
|
5
|
-
npx @modern-js/create@latest myapi
|
|
6
|
-
```
|
|
7
|
-
|
|
8
|
-
2. 可交互的问答界面中,按照默认的选择进行初始化:
|
|
9
|
-
|
|
10
|
-
```bash
|
|
11
|
-
? 请选择开发语言 TS
|
|
12
|
-
? 请选择包管理工具 pnpm
|
|
13
|
-
```
|
|
14
|
-
|
|
15
|
-
3. 执行 `new` 命令,启用 BFF:
|
|
16
|
-
|
|
17
|
-
```bash
|
|
18
|
-
? 请选择你想要的操作 启用可选功能
|
|
19
|
-
? 请选择功能名称 启用「BFF」功能
|
|
20
|
-
? 请选择 BFF 类型 框架模式
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
4. 执行【[已启用 BFF 的项目](/guides/advanced-features/bff/cross-project.html#已启用-bff-的项目)】步骤,即可打开跨项目调用开关。
|
|
25
|
-
需要注意的是,当项目仅作为 BFF 生产端,其运行时不依赖 `/src` 源码目录。因此,移除 `/src` 目录可在一定程度上优化工程的编译效率。
|
|
@@ -1,40 +0,0 @@
|
|
|
1
|
-
```js title="src/App.tsx"
|
|
2
|
-
import { useModuleApps } from '@modern-js/plugin-garfish/runtime';
|
|
3
|
-
|
|
4
|
-
import { RouterProvider, Route, createBrowserRouter, createRoutesFromElements, BrowserRouter, Link, Outlet } from '@modern-js/runtime/router';
|
|
5
|
-
|
|
6
|
-
const AppLayout = () => (
|
|
7
|
-
<>
|
|
8
|
-
<div><Link to={'/table'}>加载约定式路由子应用</Link></div>
|
|
9
|
-
<div><Link to={'/dashboard'}>加载自控式路由子应用</Link></div>
|
|
10
|
-
<div><Link to={'/'}>卸载子应用</Link></div>
|
|
11
|
-
<Outlet />
|
|
12
|
-
</>
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
export default () => {
|
|
16
|
-
const { apps, MApp, Table, Dashboard } = useModuleApps();
|
|
17
|
-
|
|
18
|
-
// 使用的不是 MApp 组件,需要使用 createBrowserRouter 来创建路由
|
|
19
|
-
const router = createBrowserRouter(
|
|
20
|
-
createRoutesFromElements(
|
|
21
|
-
<Route path="/" element={<AppLayout />}>
|
|
22
|
-
<Route key={'table'} path={'table/*'} element={<Table />} />
|
|
23
|
-
<Route key={'dashboard'} path={'dashboard/*'} element={<Dashboard />} />
|
|
24
|
-
</Route>
|
|
25
|
-
)
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
// 方法一:使用 MApp 自动根据配置的 activeWhen 参数加载子应用(本项目配置在 modern.config.ts 中)
|
|
30
|
-
// <BrowserRouter>
|
|
31
|
-
// <MApp />
|
|
32
|
-
// </BrowserRouter>
|
|
33
|
-
|
|
34
|
-
// 方法二:手动写 Route 组件方式加载子应用,方便于需要鉴权等需要前置操作的场景
|
|
35
|
-
<>
|
|
36
|
-
<RouterProvider router={router} />
|
|
37
|
-
</>
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
```
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
```ts title="modern.config.ts"
|
|
2
|
-
import { appTools, defineConfig } from '@modern-js/app-tools';
|
|
3
|
-
import { garfishPlugin } from '@modern-js/plugin-garfish';
|
|
4
|
-
|
|
5
|
-
export default defineConfig({
|
|
6
|
-
runtime: {
|
|
7
|
-
router: true,
|
|
8
|
-
},
|
|
9
|
-
plugins: [appTools(), garfishPlugin()],
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
```ts title="src/modern.runtime.ts"
|
|
15
|
-
import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
16
|
-
|
|
17
|
-
export default defineRuntimeConfig({
|
|
18
|
-
masterApp: {
|
|
19
|
-
apps: [{
|
|
20
|
-
name: 'Table',
|
|
21
|
-
entry: 'http://localhost:8081',
|
|
22
|
-
// activeWhen: '/table'
|
|
23
|
-
}, {
|
|
24
|
-
name: 'Dashboard',
|
|
25
|
-
entry: 'http://localhost:8082'
|
|
26
|
-
// activeWhen: '/dashboard'
|
|
27
|
-
}]
|
|
28
|
-
},
|
|
29
|
-
});
|
|
30
|
-
```
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
首先,你需要执行 `pnpm run new` 启用 SWC 编译:
|
|
2
|
-
|
|
3
|
-
```bash
|
|
4
|
-
? 请选择你想要的操作 启用可选功能
|
|
5
|
-
? 请选择功能名称 启用「SWC 编译」
|
|
6
|
-
```
|
|
7
|
-
|
|
8
|
-
执行完成后,你只需在 `modern.config.ts` 文件中注册 Modern.js 的 SWC 插件,即可启用 SWC 编译和压缩能力。
|
|
9
|
-
|
|
10
|
-
```ts title="modern.config.ts"
|
|
11
|
-
import { appTools, defineConfig } from '@modern-js/app-tools';
|
|
12
|
-
import { swcPlugin } from '@modern-js/plugin-swc';
|
|
13
|
-
|
|
14
|
-
export default defineConfig({
|
|
15
|
-
plugins: [appTools(), swcPlugin()],
|
|
16
|
-
});
|
|
17
|
-
```
|