@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
|
@@ -6,28 +6,54 @@ sidebar_position: 16
|
|
|
6
6
|
|
|
7
7
|
Modern.js 将大部分项目需要的服务端能力都进行了封装,通常项目无需进行服务端开发。但在有些开发场景下,例如用户鉴权、请求预处理、添加页面渲染骨架等,项目仍需要对服务端进行定制。
|
|
8
8
|
|
|
9
|
+
要在 Modern.js 项目中使用自定义 Web Server,请按照以下步骤操作:
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
1. 安装 `@modern-js/server-runtime` 依赖
|
|
11
12
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
如果项目尚未安装 `@modern-js/server-runtime` 依赖,请先安装:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @modern-js/server-runtime
|
|
17
|
+
```
|
|
15
18
|
|
|
16
|
-
|
|
19
|
+
:::tip 版本一致性
|
|
20
|
+
请确保 `@modern-js/server-runtime` 的版本与项目中 `@modern-js/app-tools` 的版本保持一致。Modern.js 的所有官方包使用统一版本号发布,版本不一致可能导致兼容性问题。
|
|
21
|
+
|
|
22
|
+
请先查看 `@modern-js/app-tools` 的版本,然后安装相同版本的 `@modern-js/server-runtime`:
|
|
17
23
|
|
|
18
24
|
```bash
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
# 查看当前 @modern-js/app-tools 的版本
|
|
26
|
+
pnpm list @modern-js/app-tools
|
|
27
|
+
|
|
28
|
+
# 安装相同版本的 @modern-js/server-runtime
|
|
29
|
+
pnpm add @modern-js/server-runtime@<版本号>
|
|
21
30
|
```
|
|
22
31
|
|
|
23
|
-
|
|
32
|
+
:::
|
|
33
|
+
|
|
34
|
+
2. 创建 `server` 目录和配置文件
|
|
35
|
+
|
|
36
|
+
在项目根目录下创建 `server/modern.server.ts` 文件:
|
|
24
37
|
|
|
38
|
+
```ts title="server/modern.server.ts"
|
|
39
|
+
import { defineServerConfig } from '@modern-js/server-runtime';
|
|
40
|
+
|
|
41
|
+
export default defineServerConfig({
|
|
42
|
+
middlewares: [], // 中间件
|
|
43
|
+
renderMiddlewares: [], // 渲染中间件
|
|
44
|
+
plugins: [], // 插件
|
|
45
|
+
onError: () => {}, // 错误处理
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
创建文件后,可以在这个文件中编写自定义逻辑。
|
|
25
50
|
|
|
26
51
|
## 自定义 Web Server 能力
|
|
27
52
|
|
|
28
53
|
Modern.js 的服务器基于 Hono 实现,在最新版本的自定义 Web Server 中,我们向用户暴露了 Hono 的中间件能力,你可以参考 [Hono 文档](https://hono.dev/docs/api/context) 了解更多用法。
|
|
29
54
|
|
|
30
55
|
`server/modern.server.ts` 文件中添加如下配置来扩展 Server:
|
|
56
|
+
|
|
31
57
|
- **中间件(Middleware)**
|
|
32
58
|
- **渲染中间件(RenderMiddleware)**
|
|
33
59
|
- **服务端插件(Plugin)**
|
|
@@ -52,7 +78,6 @@ export default defineServerConfig({
|
|
|
52
78
|
});
|
|
53
79
|
```
|
|
54
80
|
|
|
55
|
-
|
|
56
81
|
### 类型定义
|
|
57
82
|
|
|
58
83
|
`defineServerConfig` 类型定义如下:
|
|
@@ -61,17 +86,17 @@ export default defineServerConfig({
|
|
|
61
86
|
import type { MiddlewareHandler } from 'hono';
|
|
62
87
|
|
|
63
88
|
type MiddlewareObj = {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
89
|
+
name: string;
|
|
90
|
+
path?: string;
|
|
91
|
+
method?: 'options' | 'get' | 'post' | 'put' | 'delete' | 'patch' | 'all';
|
|
92
|
+
handler: MiddlewareHandler | MiddlewareHandler[];
|
|
68
93
|
};
|
|
69
94
|
type ServerConfig = {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
95
|
+
middlewares?: MiddlewareObj[];
|
|
96
|
+
renderMiddlewares?: MiddlewareObj[];
|
|
97
|
+
plugins?: ServerPlugin[];
|
|
98
|
+
onError?: (err: Error, c: Context) => Promise<any> | any;
|
|
99
|
+
};
|
|
75
100
|
```
|
|
76
101
|
|
|
77
102
|
### Middleware
|
|
@@ -86,7 +111,10 @@ Middleware 支持在 Modern.js 服务的**请求处理**与**页面路由**的
|
|
|
86
111
|
使用姿势如下:
|
|
87
112
|
|
|
88
113
|
```ts title="server/modern.server.ts"
|
|
89
|
-
import {
|
|
114
|
+
import {
|
|
115
|
+
defineServerConfig,
|
|
116
|
+
type MiddlewareHandler,
|
|
117
|
+
} from '@modern-js/server-runtime';
|
|
90
118
|
|
|
91
119
|
export const handler: MiddlewareHandler = async (c, next) => {
|
|
92
120
|
const monitors = c.get('monitors');
|
|
@@ -113,13 +141,15 @@ export default defineServerConfig({
|
|
|
113
141
|
必须执行 `next` 函数才会执行后续的 Middleware。
|
|
114
142
|
:::
|
|
115
143
|
|
|
116
|
-
|
|
117
144
|
### RenderMiddleware
|
|
118
145
|
|
|
119
146
|
如果只需要处理页面渲染的前后执行逻辑,modern.js 也提供了渲染中间件,使用姿势如下:
|
|
120
147
|
|
|
121
148
|
```ts title="server/modern.server.ts"
|
|
122
|
-
import {
|
|
149
|
+
import {
|
|
150
|
+
defineServerConfig,
|
|
151
|
+
type MiddlewareHandler,
|
|
152
|
+
} from '@modern-js/server-runtime';
|
|
123
153
|
|
|
124
154
|
// 注入 render 性能指标
|
|
125
155
|
const renderTiming: MiddlewareHandler = async (c, next) => {
|
|
@@ -159,52 +189,46 @@ export default defineServerConfig({
|
|
|
159
189
|
});
|
|
160
190
|
```
|
|
161
191
|
|
|
162
|
-
|
|
163
192
|
### Plugin
|
|
164
193
|
|
|
165
194
|
Modern.js 支持在自定义插件中为 Server 添加上述 Middleware 及 RenderMiddleware,使用姿势如下:
|
|
166
195
|
|
|
167
|
-
|
|
168
196
|
```ts title="server/plugins/server.ts"
|
|
169
|
-
import type {
|
|
197
|
+
import type { ServerPlugin } from '@modern-js/server-runtime';
|
|
170
198
|
|
|
171
|
-
export default ():
|
|
199
|
+
export default (): ServerPlugin => ({
|
|
172
200
|
name: 'serverPlugin',
|
|
173
201
|
setup(api) {
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
return serverConfig;
|
|
201
|
-
},
|
|
202
|
-
};
|
|
202
|
+
api.onPrepare(() => {
|
|
203
|
+
const { middlewares, renderMiddlewares } = api.getServerContext();
|
|
204
|
+
|
|
205
|
+
// 注入服务端数据,供页面 dataLoader 消费
|
|
206
|
+
middlewares?.push({
|
|
207
|
+
name: 'server-plugin-middleware',
|
|
208
|
+
handler: async (c, next) => {
|
|
209
|
+
c.set('message', 'hi modern.js');
|
|
210
|
+
await next();
|
|
211
|
+
// ...
|
|
212
|
+
},
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
// 重定向
|
|
216
|
+
renderMiddlewares?.push({
|
|
217
|
+
name: 'server-plugin-render-middleware',
|
|
218
|
+
handler: async (c, next) => {
|
|
219
|
+
const user = getUser(c.req);
|
|
220
|
+
if (!user) {
|
|
221
|
+
return c.redirect('/login');
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
await next();
|
|
225
|
+
},
|
|
226
|
+
});
|
|
227
|
+
});
|
|
203
228
|
},
|
|
204
229
|
});
|
|
205
230
|
```
|
|
206
231
|
|
|
207
|
-
|
|
208
232
|
```ts title="server/modern.server.ts"
|
|
209
233
|
import { defineServerConfig } from '@modern-js/server-runtime';
|
|
210
234
|
import serverPlugin from './plugins/serverPlugin';
|
|
@@ -214,7 +238,6 @@ export default defineServerConfig({
|
|
|
214
238
|
});
|
|
215
239
|
```
|
|
216
240
|
|
|
217
|
-
|
|
218
241
|
```ts title="src/routes/page.data.ts"
|
|
219
242
|
import { useHonoContext } from '@modern-js/server-runtime';
|
|
220
243
|
import { defer } from '@modern-js/runtime/router';
|
|
@@ -226,10 +249,8 @@ export default () => {
|
|
|
226
249
|
|
|
227
250
|
// ...
|
|
228
251
|
};
|
|
229
|
-
|
|
230
252
|
```
|
|
231
253
|
|
|
232
|
-
|
|
233
254
|
### onError
|
|
234
255
|
|
|
235
256
|
`onError` 是一个全局错误处理函数,用于捕获和处理 Modern.js server 中的所有未捕获错误。通过自定义 `onError` 函数,开发者可以统一处理不同类型的错误,返回自定义的错误响应,实现错误日志记录、错误分类处理等功能。
|
|
@@ -258,245 +279,3 @@ export default defineServerConfig({
|
|
|
258
279
|
},
|
|
259
280
|
});
|
|
260
281
|
```
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
## 旧版 API(废弃)
|
|
264
|
-
|
|
265
|
-
:::warning
|
|
266
|
-
旧版 API 兼容但不再推荐使用,扩展 Server 能力请移步 [自定义 Web Server](/guides/advanced-features/web-server.html),迁移指南参考 [迁移至新版自定义 Web Server](/guides/advanced-features/web-server.html#迁移至新版自定义-web-server)。
|
|
267
|
-
:::
|
|
268
|
-
|
|
269
|
-
### 开启
|
|
270
|
-
开启自定义 Web Server 功能,需要执行以下步骤:
|
|
271
|
-
1. devDependencies 增加 `@modern-js/plugin-server`、`tsconfig-paths` 及 `ts-node`依赖并安装。
|
|
272
|
-
2. `tsconfig` 的 `include` 中添加 `server`。
|
|
273
|
-
3. `modern.config.ts` 中注册 `@modern-js/plugin-server` 插件。
|
|
274
|
-
4. 项目目录下创建 `server/index.ts` 文件,可以在这个文件中编写自定义逻辑。
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
### Unstable Middleware
|
|
278
|
-
|
|
279
|
-
Modern.js 支持为 Web Server 添加渲染中间件,支持在处理页面路由的前后执行自定义逻辑。
|
|
280
|
-
|
|
281
|
-
```ts title="server/index.ts"
|
|
282
|
-
import {
|
|
283
|
-
UnstableMiddleware,
|
|
284
|
-
UnstableMiddlewareContext,
|
|
285
|
-
} from '@modern-js/runtime/server';
|
|
286
|
-
|
|
287
|
-
const time: UnstableMiddleware = async (c: UnstableMiddlewareContext, next) => {
|
|
288
|
-
const start = Date.now();
|
|
289
|
-
|
|
290
|
-
await next();
|
|
291
|
-
|
|
292
|
-
const end = Date.now();
|
|
293
|
-
|
|
294
|
-
console.log(`dur=${end - start}`);
|
|
295
|
-
};
|
|
296
|
-
|
|
297
|
-
export const unstableMiddleware: UnstableMiddleware[] = [time];
|
|
298
|
-
```
|
|
299
|
-
|
|
300
|
-
:::info
|
|
301
|
-
详细 API 和更多用法查看 [UnstableMiddleware](/apis/app/runtime/web-server/unstable_middleware)。
|
|
302
|
-
:::
|
|
303
|
-
|
|
304
|
-
### Hook
|
|
305
|
-
|
|
306
|
-
Modern.js 提供的 Hook 用于控制 Web Server 中的特定逻辑,所有的页面请求都会经过 Hook。
|
|
307
|
-
|
|
308
|
-
目前提供了两种 Hook,分别是 `AfterMatch` 和 `AfterRender`,开发者可以在 `server/index.ts` 中这样写:
|
|
309
|
-
|
|
310
|
-
```ts
|
|
311
|
-
import type {
|
|
312
|
-
AfterMatchHook,
|
|
313
|
-
AfterRenderHook,
|
|
314
|
-
} from '@modern-js/runtime/server';
|
|
315
|
-
|
|
316
|
-
export const afterMatch: AfterMatchHook = (ctx, next) => {
|
|
317
|
-
next();
|
|
318
|
-
};
|
|
319
|
-
|
|
320
|
-
export const afterRender: AfterRenderHook = (ctx, next) => {
|
|
321
|
-
next();
|
|
322
|
-
};
|
|
323
|
-
```
|
|
324
|
-
|
|
325
|
-
项目在使用 Hook 时,应该有以下最佳实践:
|
|
326
|
-
|
|
327
|
-
1. 在 afterMatch 中做权限校验。
|
|
328
|
-
2. 在 afterMatch 做 Rewrite 和 Redirect。
|
|
329
|
-
3. 在 afterRender 中做 HTML 内容注入。
|
|
330
|
-
|
|
331
|
-
:::info
|
|
332
|
-
详细 API 和更多用法可以查看 [Hook](/apis/app/runtime/web-server/hook)。
|
|
333
|
-
:::
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
## 迁移至新版自定义 Web Server
|
|
337
|
-
|
|
338
|
-
### 迁移背景
|
|
339
|
-
|
|
340
|
-
Modern.js Server 在不断演进,为了提供更强大的功能,我们对中间件和 Server 插件的定义和使用方式进行了优化。
|
|
341
|
-
虽然旧版 API 仍被兼容,但我们强烈建议您按照本指南进行迁移,以充分利用新版的优势。
|
|
342
|
-
|
|
343
|
-
### 迁移步骤
|
|
344
|
-
|
|
345
|
-
1. 升级 Modern.js 版本至 x.67.5 及以上。
|
|
346
|
-
2. 按照新版定义方式,在 `server/modern.server.ts` 中配置中间件或插件。
|
|
347
|
-
3. 将 `server/index.ts` 自定义逻辑迁移到中间件或插件中,并参考 `Context` 和 `Next` 差异,更新您的代码。
|
|
348
|
-
|
|
349
|
-
### Context 差异
|
|
350
|
-
|
|
351
|
-
新版中间件 handler 类型为 Hono 的 `MiddlewareHandler`,即 `Context` 类型为 `Hono Context`。对比旧版自定义 Web Server 中 `Context` 差异如下:
|
|
352
|
-
|
|
353
|
-
#### UnstableMiddleware
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
```ts
|
|
357
|
-
type Body = ReadableStream | ArrayBuffer | string | null;
|
|
358
|
-
|
|
359
|
-
type UnstableMiddlewareContext<
|
|
360
|
-
V extends Record<string, unknown> = Record<string, unknown>,
|
|
361
|
-
> = {
|
|
362
|
-
request: Request;
|
|
363
|
-
response: Response;
|
|
364
|
-
get: Get<V>;
|
|
365
|
-
set: Set<V>;
|
|
366
|
-
// 当前匹配到的路由信息
|
|
367
|
-
route: string;
|
|
368
|
-
header: (name: string, value: string, options?: { append?: boolean }) => void;
|
|
369
|
-
status: (code: number) => void;
|
|
370
|
-
redirect: (location: string, status?: number) => Response;
|
|
371
|
-
body: (data: Body, init?: ResponseInit) => Response;
|
|
372
|
-
html: (
|
|
373
|
-
data: string | Promise<string>,
|
|
374
|
-
init?: ResponseInit,
|
|
375
|
-
) => Response | Promise<Response>;
|
|
376
|
-
};
|
|
377
|
-
```
|
|
378
|
-
|
|
379
|
-
UnstableMiddleware `Context` 和 Hono `Context` 的具体差异:
|
|
380
|
-
|
|
381
|
-
| UnstableMiddleware | Hono | 说明 |
|
|
382
|
-
| :----------------------- | :---------------------------- | :------------------------------------------------------------------------ |
|
|
383
|
-
| `c.request` | `c.req.raw` | 参考 [HonoRequest raw](https://hono.dev/docs/api/request#raw) 文档 |
|
|
384
|
-
| `c.response` | `c.res` | 参考 [Hono Context res](https://hono.dev/docs/api/context#res) 文档 |
|
|
385
|
-
| `c.route` | `c.get('route')` | 获取应用上下文信息 |
|
|
386
|
-
| `loaderContext.get` | `honoContext.get` | 通过 `c.set` 注入数据后 dataLoader 中消费:旧版通过 `loaderContext.get` 获取,新版参考 [Plugin](/guides/advanced-features/web-server.html#使用姿势-2) 示例 |
|
|
387
|
-
|
|
388
|
-
#### Middleware
|
|
389
|
-
|
|
390
|
-
```ts
|
|
391
|
-
type MiddlewareContext = {
|
|
392
|
-
response: {
|
|
393
|
-
set: (key: string, value: string) => void;
|
|
394
|
-
status: (code: number) => void;
|
|
395
|
-
getStatus: () => number;
|
|
396
|
-
cookies: {
|
|
397
|
-
set: (key: string, value: string, options?: any) => void;
|
|
398
|
-
clear: () => void;
|
|
399
|
-
};
|
|
400
|
-
raw: (
|
|
401
|
-
body: string,
|
|
402
|
-
{ status, headers }: { status: number; headers: Record<string, any> },
|
|
403
|
-
) => void;
|
|
404
|
-
locals: Record<string, any>;
|
|
405
|
-
};
|
|
406
|
-
request: {
|
|
407
|
-
url: string;
|
|
408
|
-
host: string;
|
|
409
|
-
pathname: string;
|
|
410
|
-
query: Record<string, any>;
|
|
411
|
-
cookie: string;
|
|
412
|
-
cookies: {
|
|
413
|
-
get: (key: string) => string;
|
|
414
|
-
};
|
|
415
|
-
headers: IncomingHttpHeaders;
|
|
416
|
-
};
|
|
417
|
-
source: {
|
|
418
|
-
req: IncomingMessage;
|
|
419
|
-
res: ServerResponse;
|
|
420
|
-
};
|
|
421
|
-
};
|
|
422
|
-
|
|
423
|
-
```
|
|
424
|
-
|
|
425
|
-
Middleware `Context` 和 Hono `Context` 的具体差异:
|
|
426
|
-
|
|
427
|
-
| UnstableMiddleware | Hono | 说明 |
|
|
428
|
-
| :----------------------- | :---------------------------- | :--------------------------------------------------------------------------- |
|
|
429
|
-
| `c.request.cookie` | `c.req.cookie()` | 参考 [Hono Cookie Helper](https://hono.dev/docs/helpers/cookie) 文档 |
|
|
430
|
-
| `c.request.pathname` | `c.req.path` | 参考 [HonoRequest path](https://hono.dev/docs/api/request#path) 文档 |
|
|
431
|
-
| `c.request.url` | - | Hono `c.req.url` 为完整请求路径,自行通过 url 计算 |
|
|
432
|
-
| `c.request.host` | `c.req.header('Host')` | 通过 header 获取 host |
|
|
433
|
-
| `c.request.query` | `c.req.query()` | 参考 [HonoRequest query](https://hono.dev/docs/api/request#query) 文档 |
|
|
434
|
-
| `c.request.headers` | `c.req.header()` | 参考 [HonoRequest header](https://hono.dev/docs/api/request#header) 文档 |
|
|
435
|
-
| `c.response.set` | `c.res.headers.set` | 例:`c.res.headers.set('custom-header', '1')` |
|
|
436
|
-
| `c.response.status` | `c.status` | 例:`c.status(201)` |
|
|
437
|
-
| `c.response.cookies` | `c.header` | 例:`c.header('Set-Cookie', 'user_id=123')` |
|
|
438
|
-
| `c.response.raw` | `c.res` | 参考 [Hono Context res](https://hono.dev/docs/api/context#res) 文档 |
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
#### Hook
|
|
442
|
-
|
|
443
|
-
```ts
|
|
444
|
-
type HookContext = {
|
|
445
|
-
response: {
|
|
446
|
-
set: (key: string, value: string) => void;
|
|
447
|
-
status: (code: number) => void;
|
|
448
|
-
getStatus: () => number;
|
|
449
|
-
cookies: {
|
|
450
|
-
set: (key: string, value: string, options?: any) => void;
|
|
451
|
-
clear: () => void;
|
|
452
|
-
};
|
|
453
|
-
raw: (
|
|
454
|
-
body: string,
|
|
455
|
-
{ status, headers }: { status: number; headers: Record<string, any> },
|
|
456
|
-
) => void;
|
|
457
|
-
};
|
|
458
|
-
request: {
|
|
459
|
-
url: string;
|
|
460
|
-
host: string;
|
|
461
|
-
pathname: string;
|
|
462
|
-
query: Record<string, any>;
|
|
463
|
-
cookie: string;
|
|
464
|
-
cookies: {
|
|
465
|
-
get: (key: string) => string;
|
|
466
|
-
};
|
|
467
|
-
headers: IncomingHttpHeaders;
|
|
468
|
-
};
|
|
469
|
-
};
|
|
470
|
-
|
|
471
|
-
type AfterMatchContext = HookContext & {
|
|
472
|
-
router: {
|
|
473
|
-
redirect: (url: string, status: number) => void;
|
|
474
|
-
rewrite: (entry: string) => void;
|
|
475
|
-
};
|
|
476
|
-
};
|
|
477
|
-
|
|
478
|
-
type AfterRenderContext = {
|
|
479
|
-
template: {
|
|
480
|
-
get: () => string;
|
|
481
|
-
set: (html: string) => void;
|
|
482
|
-
prependHead: (fragment: string) => void;
|
|
483
|
-
appendHead: (fragment: string) => void;
|
|
484
|
-
prependBody: (fragment: string) => void;
|
|
485
|
-
appendBody: (fragment: string) => void;
|
|
486
|
-
};
|
|
487
|
-
};
|
|
488
|
-
```
|
|
489
|
-
|
|
490
|
-
Hook Context 大部分和 Middleware Context 一致,因此我们要额外关注不同 Hook 多余的部分。
|
|
491
|
-
|
|
492
|
-
| UnstableMiddleware | Hono | 说明 |
|
|
493
|
-
| :----------------------- | :---------------------------- | :----------------------------- |
|
|
494
|
-
| `router.redirect` | `c.redirect` | 参考 [Hono Context redirect](https://hono.dev/docs/api/context#redirect) 文档 |
|
|
495
|
-
| `router.rewrite` | - | 暂时没有提供对应的能力 |
|
|
496
|
-
| template API | `c.res` | 参考 [Hono Context res](https://hono.dev/docs/api/context#res) 文档 |
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
### Next API 差异
|
|
500
|
-
|
|
501
|
-
在 Middleware 和 Hook 中,即使不执行 `next`,渲染函数也会执行。
|
|
502
|
-
在新的设计中,必须执行 `next` 函数才会执行后续的 Middleware。
|
|
@@ -2,12 +2,49 @@
|
|
|
2
2
|
|
|
3
3
|
CSS-in-JS 是一种可以将 CSS 样式写在 JS 文件里的技术。
|
|
4
4
|
|
|
5
|
-
Modern.js
|
|
5
|
+
Modern.js 支持社区常用的 CSS-in-JS 实现库 [styled-components](https://styled-components.com/),它使用 JavaScript 的新特性 [Tagged template](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) 编写组件的 CSS 样式。
|
|
6
|
+
|
|
7
|
+
Modern.js 插件 `@modern-js/plugin-styled-components` 提供了对 styled-components 的支持,并为 styled-components 添加了服务器端渲染能力。你可以通过安装 `@modern-js/plugin-styled-components` 插件来使用 styled-components。
|
|
8
|
+
|
|
9
|
+
## 在 Modern.js 中使用 styled-components
|
|
10
|
+
|
|
11
|
+
首先,你需要安装 `styled-components` 插件依赖和 `styled-components` 库:
|
|
12
|
+
|
|
13
|
+
import { PackageManagerTabs } from '@theme';
|
|
14
|
+
|
|
15
|
+
<PackageManagerTabs
|
|
16
|
+
command={{
|
|
17
|
+
npm: 'npm install @modern-js/plugin-styled-components styled-components -D',
|
|
18
|
+
yarn: 'yarn add @modern-js/plugin-styled-components styled-components -D',
|
|
19
|
+
pnpm: 'pnpm install @modern-js/plugin-styled-components styled-components -D',
|
|
20
|
+
}}
|
|
21
|
+
/>
|
|
22
|
+
|
|
23
|
+
然后在 `modern.config.ts` 中配置 `styled-components` 插件:
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
27
|
+
import { styledComponentsPlugin } from '@modern-js/plugin-styled-components';
|
|
28
|
+
|
|
29
|
+
export default defineConfig({
|
|
30
|
+
plugins: [
|
|
31
|
+
styledComponentsPlugin({
|
|
32
|
+
// ...
|
|
33
|
+
displayName: true,
|
|
34
|
+
minify: process.env.NODE_ENV === 'production',
|
|
35
|
+
}),
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
styledComponentsPlugin 插件的配置项与 [@rsbuild/plugin-styled-components](https://www.npmjs.com/package/@rsbuild/plugin-styled-components) 插件的配置项相同,你可以参考 [@rsbuild/plugin-styled-components](https://www.npmjs.com/package/@rsbuild/plugin-styled-components) 插件的文档进行配置。
|
|
41
|
+
|
|
42
|
+
## 使用 styled-components 编写样式
|
|
6
43
|
|
|
7
44
|
当需要编写一个内部字体为红色的 `div` 组件时,可以如下实现:
|
|
8
45
|
|
|
9
46
|
```js
|
|
10
|
-
import styled from '@modern-js/
|
|
47
|
+
import styled from '@modern-js/plugin-styled-components/styled';
|
|
11
48
|
|
|
12
49
|
const RedDiv = styled.div`
|
|
13
50
|
color: red;
|
|
@@ -17,7 +54,7 @@ const RedDiv = styled.div`
|
|
|
17
54
|
当需要根据组件的 `props` 动态设置组件样式时,例如 `props` 的属性 `primary` 为 `true` 时,按钮的颜色为白色,其他情况为红色,实现代码如下:
|
|
18
55
|
|
|
19
56
|
```js
|
|
20
|
-
import styled from '@modern-js/
|
|
57
|
+
import styled from '@modern-js/plugin-styled-components/styled';
|
|
21
58
|
|
|
22
59
|
const Button = styled.button`
|
|
23
60
|
color: ${props => (props.primary ? 'white' : 'red')};
|
|
@@ -27,8 +64,6 @@ const Button = styled.button`
|
|
|
27
64
|
|
|
28
65
|
关于 styled-components 的更多用法,请参考 [styled-components 官网](https://styled-components.com/)。
|
|
29
66
|
|
|
30
|
-
Modern.js 内部集成了 Babel 的 [babel-plugin-styled-components](https://github.com/styled-components/babel-plugin-styled-components) 插件,你可以通过 [tools.styledComponents](/configure/app/tools/styled-components) 对插件进行配置。
|
|
31
|
-
|
|
32
67
|
:::tip 提示
|
|
33
68
|
如果需要使用 [styled-jsx](https://www.npmjs.com/package/styled-jsx)、[Emotion](https://emotion.sh/) 等其他 CSS-in-JS 库,需要先安装对应库的依赖。具体使用方式请参考对应库的官网。
|
|
34
69
|
:::
|
|
@@ -81,18 +81,6 @@ export default {
|
|
|
81
81
|
};
|
|
82
82
|
```
|
|
83
83
|
|
|
84
|
-
## 自定义类名
|
|
85
|
-
|
|
86
|
-
自定义 CSS Modules 生成的类名也是我们比较常用的功能,你可以使用 [output.cssModuleLocalIdentName](/configure/app/output/css-modules.html#cssmodulesexportlocalsconvention) 来进行配置。
|
|
87
|
-
|
|
88
|
-
```ts
|
|
89
|
-
export default {
|
|
90
|
-
output: {
|
|
91
|
-
cssModuleLocalIdentName: '[hash:base64:4]',
|
|
92
|
-
},
|
|
93
|
-
};
|
|
94
|
-
```
|
|
95
|
-
|
|
96
84
|
如果你需要自定义 CSS Modules 的其他配置,可以通过 [tools.cssLoader](/configure/app/tools/css-loader) 进行设置。
|
|
97
85
|
|
|
98
86
|
## 添加类型声明
|
|
@@ -185,14 +173,15 @@ export default {
|
|
|
185
173
|
import styles from './index.module.scss';
|
|
186
174
|
|
|
187
175
|
export default () => {
|
|
188
|
-
|
|
189
|
-
<div
|
|
190
|
-
|
|
176
|
+
return (
|
|
177
|
+
<div>
|
|
178
|
+
<div className={styles.pageHeader}>Page Header</div>
|
|
179
|
+
</div>
|
|
180
|
+
);
|
|
191
181
|
};
|
|
192
182
|
```
|
|
193
183
|
|
|
194
|
-
```scss
|
|
195
|
-
// index.module.scss
|
|
184
|
+
```scss title="src/index.module.scss"
|
|
196
185
|
.page-header {
|
|
197
186
|
color: black;
|
|
198
187
|
}
|
|
@@ -18,13 +18,13 @@ Modern.js 内置了社区流行的 CSS 预处理器,包括 Less 和 Sass。
|
|
|
18
18
|
|
|
19
19
|
Modern.js 内置了 [PostCSS](https://postcss.org/) 来转换 CSS 代码。
|
|
20
20
|
|
|
21
|
-
请阅读 [Rsbuild - 使用 PostCSS](https://rsbuild.rs/zh/guide/
|
|
21
|
+
请阅读 [Rsbuild - 使用 PostCSS](https://rsbuild.rs/zh/guide/styling/css-usage) 了解更多用法。
|
|
22
22
|
|
|
23
23
|
## 使用 Lightning CSS
|
|
24
24
|
|
|
25
25
|
Modern.js 支持使用 [Lightning CSS](https://lightningcss.dev/) 来转换 CSS 代码,可以通过配置 [tools.lightningcssLoader](/configure/app/tools/lightningcss-loader) 来开启此功能。
|
|
26
26
|
|
|
27
|
-
请阅读 [Rsbuild - 使用 Lightning CSS](https://rsbuild.rs/zh/guide/
|
|
27
|
+
请阅读 [Rsbuild - 使用 Lightning CSS](https://rsbuild.rs/zh/guide/styling/css-usage#lightning-css) 了解更多用法。
|
|
28
28
|
|
|
29
29
|
## 使用 Uno CSS
|
|
30
30
|
|