@modern-js/main-doc 2.69.7 → 3.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/en/{_meta.json → _nav.json} +5 -1
- package/docs/en/apis/app/commands.mdx +8 -33
- package/docs/en/apis/app/hooks/src/entry.mdx +1 -5
- package/docs/en/apis/app/hooks/src/entry.server.mdx +4 -5
- package/docs/en/apis/app/hooks/src/routes.mdx +2 -2
- package/docs/en/apis/app/runtime/_meta.json +0 -18
- package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +2 -2
- package/docs/en/apis/app/runtime/router/router.mdx +1 -1
- package/docs/en/apis/app/runtime/utility/css-in-js.mdx +3 -2
- package/docs/en/community/blog/v2-release-note.mdx +0 -2
- package/docs/en/community/contributing-guide.mdx +10 -12
- package/docs/en/components/bff-upload.mdx +19 -17
- package/docs/en/components/build-output.mdx +45 -0
- package/docs/en/components/bundler.mdx +1 -1
- package/docs/en/components/debug-app.mdx +1 -1
- package/docs/en/components/enable-bff-caution.mdx +2 -2
- package/docs/en/components/enable-bff.mdx +42 -8
- package/docs/en/components/enable-ssg.mdx +49 -0
- package/docs/en/components/entry-scan-logic.mdx +7 -0
- package/docs/en/components/esbuild.mdx +2 -2
- package/docs/en/components/extend-bff-function.mdx +2 -4
- package/docs/en/components/hono.mdx +119 -0
- package/docs/en/components/init-app.mdx +40 -17
- package/docs/en/components/international/custom-instance-code.mdx +16 -0
- package/docs/en/components/international/init-options-desc.mdx +1 -0
- package/docs/en/components/international/install-command.mdx +23 -0
- package/docs/en/components/international/instance-code.mdx +26 -0
- package/docs/en/components/international/introduce.mdx +2 -0
- package/docs/en/components/module-federation.mdx +4 -4
- package/docs/en/components/nodeVersion.mdx +2 -6
- package/docs/en/components/prerequisites.mdx +1 -1
- package/docs/en/components/ua-polyfill.mdx +16 -12
- package/docs/en/components/upgrade-config-deploy.mdx +0 -0
- package/docs/en/configure/_meta.json +7 -8
- package/docs/en/configure/app/bff/cross-project.mdx +24 -0
- package/docs/en/configure/app/builder-plugins.mdx +1 -2
- package/docs/en/configure/app/dev/lazy-compilation.mdx +45 -0
- package/docs/en/configure/app/dev/server.mdx +211 -0
- package/docs/en/configure/app/dev/setup-middlewares.mdx +4 -22
- package/docs/en/configure/app/experiments/source-build.mdx +0 -1
- package/docs/en/configure/app/html/app-icon.mdx +1 -23
- package/docs/en/configure/app/output/assets-retry.mdx +1 -1
- package/docs/en/configure/app/output/disable-inline-runtime-chunk.mdx +2 -2
- package/docs/en/configure/app/output/filename.mdx +2 -4
- package/docs/en/configure/app/output/inline-scripts.mdx +1 -1
- package/docs/en/configure/app/output/override-browserslist.mdx +6 -4
- package/docs/en/configure/app/output/source-map.mdx +6 -3
- package/docs/en/configure/app/output/ssg.mdx +12 -43
- package/docs/en/configure/app/output/ssgByEntries.mdx +93 -0
- package/docs/en/configure/app/output/temp-dir.mdx +3 -3
- package/docs/en/configure/app/performance/build-cache.mdx +1 -5
- package/docs/en/configure/app/performance/profile.mdx +1 -1
- package/docs/en/configure/app/plugins.mdx +1 -3
- package/docs/en/configure/app/resolve/alias-strategy.mdx +14 -0
- package/docs/en/configure/app/resolve/alias.mdx +13 -0
- package/docs/en/configure/app/resolve/condition-names.mdx +18 -0
- package/docs/en/configure/app/resolve/dedupe.mdx +13 -0
- package/docs/en/configure/app/resolve/extensions.mdx +18 -0
- package/docs/en/configure/app/runtime/0-intro.mdx +2 -51
- package/docs/en/configure/app/runtime/router.mdx +0 -4
- package/docs/en/configure/app/security/check-syntax.mdx +1 -1
- package/docs/en/configure/app/security/sri.mdx +0 -1
- package/docs/en/configure/app/server/port.mdx +1 -21
- package/docs/en/configure/app/server/rsc.mdx +30 -0
- package/docs/en/configure/app/server/ssr.mdx +20 -9
- package/docs/en/configure/app/source/alias.mdx +1 -1
- package/docs/en/configure/app/source/decorators.mdx +4 -2
- package/docs/en/configure/app/source/enable-async-entry.mdx +1 -1
- package/docs/en/configure/app/source/entries.mdx +0 -2
- package/docs/en/configure/app/source/include.mdx +2 -14
- package/docs/en/configure/app/source/main-entry-name.mdx +4 -4
- package/docs/en/configure/app/source/transform-import.mdx +1 -59
- package/docs/en/configure/app/tools/bundler-chain.mdx +5 -5
- package/docs/en/configure/app/tools/css-extract.mdx +1 -1
- package/docs/en/configure/app/tools/dev-server.mdx +22 -256
- package/docs/en/configure/app/tools/html-plugin.mdx +3 -3
- package/docs/en/configure/app/tools/lightningcss-loader.mdx +0 -1
- package/docs/en/configure/app/tools/swc.mdx +1 -43
- package/docs/en/configure/app/usage.mdx +5 -27
- package/docs/en/guides/_meta.json +5 -1
- package/docs/en/guides/advanced-features/_meta.json +6 -0
- package/docs/en/guides/advanced-features/bff/_meta.json +9 -1
- package/docs/en/guides/advanced-features/bff/cross-project.mdx +2 -8
- package/docs/en/guides/advanced-features/bff/extend-server.mdx +18 -3
- package/docs/en/guides/advanced-features/bff/frameworks.mdx +2 -15
- package/docs/en/guides/advanced-features/bff/function.mdx +6 -10
- package/docs/en/guides/advanced-features/bff/operators.mdx +628 -0
- package/docs/en/guides/advanced-features/bff/sdk.mdx +20 -12
- package/docs/en/guides/advanced-features/bff/upload.mdx +3 -1
- package/docs/en/guides/advanced-features/build-performance.mdx +23 -26
- package/docs/en/guides/advanced-features/compatibility.mdx +53 -9
- package/docs/en/guides/advanced-features/international/_meta.json +11 -0
- package/docs/en/guides/advanced-features/international/advanced.mdx +193 -0
- package/docs/en/guides/advanced-features/international/api.mdx +400 -0
- package/docs/en/guides/advanced-features/international/basic.mdx +417 -0
- package/docs/en/guides/advanced-features/international/best-practices.mdx +135 -0
- package/docs/en/guides/advanced-features/international/configuration.mdx +428 -0
- package/docs/en/guides/advanced-features/international/locale-detection.mdx +276 -0
- package/docs/en/guides/advanced-features/international/quick-start.mdx +126 -0
- package/docs/en/guides/advanced-features/international/resource-loading.mdx +417 -0
- package/docs/en/guides/advanced-features/international/routing.mdx +212 -0
- package/docs/en/guides/advanced-features/international.mdx +37 -0
- package/docs/en/guides/advanced-features/low-level.mdx +21 -16
- package/docs/en/guides/advanced-features/page-performance/code-split.mdx +4 -4
- package/docs/en/guides/advanced-features/page-performance/inline-assets.mdx +4 -4
- package/docs/en/guides/advanced-features/page-performance/optimize-bundle.mdx +8 -22
- package/docs/en/guides/advanced-features/page-performance/react-compiler.mdx +19 -12
- package/docs/en/guides/advanced-features/rspack-start.mdx +3 -23
- package/docs/en/guides/advanced-features/server-monitor/logger.mdx +0 -4
- package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +121 -36
- package/docs/en/guides/advanced-features/web-server.mdx +82 -299
- package/docs/en/guides/basic-features/_meta.json +6 -1
- package/docs/en/guides/basic-features/css/css-in-js.mdx +46 -11
- package/docs/en/guides/basic-features/css/css-modules.mdx +5 -17
- package/docs/en/guides/basic-features/css/css.mdx +3 -3
- package/docs/en/guides/basic-features/css/tailwindcss.mdx +5 -89
- package/docs/en/guides/basic-features/data/data-cache.mdx +65 -77
- package/docs/en/guides/basic-features/data/data-fetch.mdx +19 -18
- package/docs/en/guides/basic-features/data/data-write.mdx +2 -2
- package/docs/en/guides/basic-features/debug/mock.mdx +4 -1
- package/docs/en/guides/basic-features/debug/proxy.mdx +6 -17
- package/docs/en/guides/basic-features/debug/rsdoctor.mdx +5 -5
- package/docs/en/guides/basic-features/deploy.mdx +25 -18
- package/docs/en/guides/basic-features/env-vars.mdx +1 -1
- package/docs/en/guides/basic-features/html.mdx +1 -1
- package/docs/en/guides/basic-features/output-files.mdx +3 -3
- package/docs/en/guides/basic-features/render/_meta.json +1 -1
- package/docs/en/guides/basic-features/render/before-render.mdx +16 -23
- package/docs/en/guides/basic-features/render/overview.mdx +51 -0
- package/docs/en/guides/basic-features/render/rsc.mdx +399 -0
- package/docs/en/guides/basic-features/render/ssg.mdx +26 -67
- package/docs/en/guides/basic-features/render/ssr-cache.mdx +6 -10
- package/docs/en/guides/basic-features/render/ssr.mdx +31 -31
- package/docs/en/guides/basic-features/render/streaming-ssr.mdx +29 -9
- package/docs/en/guides/basic-features/routes/_meta.json +1 -0
- package/docs/en/guides/basic-features/routes/config-routes.mdx +427 -0
- package/docs/en/guides/basic-features/{routes.mdx → routes/routes.mdx} +7 -110
- package/docs/en/guides/basic-features/static-assets/json-files.mdx +21 -3
- package/docs/en/guides/basic-features/static-assets/svg-assets.mdx +0 -4
- package/docs/en/guides/basic-features/static-assets.mdx +2 -2
- package/docs/en/guides/concept/builder.mdx +27 -12
- package/docs/en/guides/concept/entries.mdx +139 -147
- package/docs/en/guides/get-started/glossary.mdx +0 -18
- package/docs/en/guides/get-started/introduction.mdx +1 -4
- package/docs/en/guides/get-started/quick-start.mdx +4 -71
- package/docs/en/guides/get-started/tech-stack.mdx +7 -27
- package/docs/en/guides/get-started/upgrade.mdx +30 -23
- package/docs/en/guides/topic-detail/_meta.json +0 -12
- package/docs/en/guides/topic-detail/module-federation/_meta.json +1 -1
- package/docs/en/guides/topic-detail/module-federation/application.mdx +16 -15
- package/docs/en/guides/topic-detail/module-federation/i18n.mdx +670 -0
- package/docs/en/guides/topic-detail/module-federation/introduce.mdx +5 -4
- package/docs/en/guides/topic-detail/module-federation/ssr.mdx +50 -2
- package/docs/en/guides/topic-detail/module-federation/usage.mdx +10 -30
- package/docs/en/guides/troubleshooting/builder.mdx +3 -82
- package/docs/en/guides/troubleshooting/cli.mdx +6 -30
- package/docs/en/guides/troubleshooting/dependencies.mdx +22 -22
- package/docs/en/guides/upgrade/_meta.json +1 -0
- package/docs/en/guides/upgrade/config.mdx +936 -0
- package/docs/en/guides/upgrade/entry.mdx +463 -0
- package/docs/en/guides/upgrade/other.mdx +83 -0
- package/docs/en/guides/upgrade/overview.mdx +33 -0
- package/docs/en/guides/upgrade/tailwindcss.mdx +130 -0
- package/docs/en/guides/upgrade/web-server.mdx +91 -0
- package/docs/en/plugin/_meta.json +5 -0
- package/docs/en/plugin/cli-plugins/_meta.json +1 -1
- package/docs/en/plugin/cli-plugins/api.mdx +17 -68
- package/docs/en/plugin/cli-plugins/life-cycle.mdx +0 -4
- package/docs/en/plugin/introduction.mdx +44 -44
- package/docs/en/plugin/official/_meta.json +0 -5
- package/docs/en/plugin/official/cli-plugins/_meta.json +1 -1
- package/docs/en/plugin/official/cli-plugins/plugin-styled-components.mdx +5 -0
- package/docs/en/plugin/official/cli-plugins.mdx +0 -2
- package/docs/en/plugin/plugin-system.mdx +69 -62
- package/docs/en/plugin/runtime-plugins/_meta.json +1 -1
- package/docs/en/plugin/runtime-plugins/api.mdx +62 -59
- package/docs/en/plugin/server-plugins/_meta.json +1 -0
- package/docs/en/plugin/server-plugins/api.mdx +210 -1
- package/docs/en/plugin/server-plugins/life-cycle.mdx +41 -1
- package/docs/en/tutorials/_meta.json +0 -10
- package/docs/en/tutorials/examples/csr-auth.mdx +1 -1
- package/docs/en/tutorials/foundations/introduction.mdx +9 -25
- package/docs/zh/{_meta.json → _nav.json} +10 -6
- package/docs/zh/apis/app/commands.mdx +8 -33
- package/docs/zh/apis/app/hooks/src/entry.mdx +1 -5
- package/docs/zh/apis/app/hooks/src/entry.server.mdx +4 -5
- package/docs/zh/apis/app/hooks/src/routes.mdx +2 -2
- package/docs/zh/apis/app/runtime/_meta.json +0 -18
- package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +2 -2
- package/docs/zh/apis/app/runtime/utility/css-in-js.mdx +3 -2
- package/docs/zh/community/blog/v2-release-note.mdx +0 -2
- package/docs/zh/community/contributing-guide.mdx +10 -12
- package/docs/zh/components/auto-upgrade.mdx +0 -0
- package/docs/zh/components/bff-operator-code.mdx +5 -0
- package/docs/zh/components/bff-upload.mdx +8 -7
- package/docs/zh/components/build-output.mdx +45 -0
- package/docs/zh/components/bundler.mdx +1 -1
- package/docs/zh/components/debug-app.mdx +1 -1
- package/docs/zh/components/enable-bff-caution.mdx +1 -1
- package/docs/zh/components/enable-bff.mdx +41 -8
- package/docs/zh/components/enable-ssg.mdx +49 -0
- package/docs/zh/components/entry-scan-logic.mdx +7 -0
- package/docs/zh/components/esbuild.mdx +2 -2
- package/docs/zh/components/extend-bff-function.mdx +2 -4
- package/docs/zh/components/hono.mdx +119 -0
- package/docs/zh/components/init-app.mdx +40 -18
- package/docs/zh/components/international/custom-instance-code.mdx +16 -0
- package/docs/zh/components/international/init-options-desc.mdx +1 -0
- package/docs/zh/components/international/install-command.mdx +23 -0
- package/docs/zh/components/international/instance-code.mdx +26 -0
- package/docs/zh/components/international/introduce.mdx +2 -0
- package/docs/zh/components/international/platform-support.mdx +0 -0
- package/docs/zh/components/module-federation.mdx +4 -4
- package/docs/zh/components/new-entry-tooltip.mdx +0 -0
- package/docs/zh/components/nodeVersion.mdx +3 -7
- package/docs/zh/components/prerequisites.mdx +1 -1
- package/docs/zh/components/self-route-example.mdx +3 -3
- package/docs/zh/components/ua-polyfill.mdx +11 -6
- package/docs/zh/components/upgrade-browserslist.mdx +0 -0
- package/docs/zh/components/upgrade-config-deploy.mdx +0 -0
- package/docs/zh/configure/_meta.json +7 -8
- package/docs/zh/configure/app/bff/cross-project.mdx +24 -0
- package/docs/zh/configure/app/builder-plugins.mdx +1 -2
- package/docs/zh/configure/app/dev/lazy-compilation.mdx +44 -0
- package/docs/zh/configure/app/dev/server.mdx +211 -0
- package/docs/zh/configure/app/dev/setup-middlewares.mdx +4 -23
- package/docs/zh/configure/app/experiments/source-build.mdx +0 -1
- package/docs/zh/configure/app/html/app-icon.mdx +1 -23
- package/docs/zh/configure/app/output/assets-retry.mdx +1 -1
- package/docs/zh/configure/app/output/disable-inline-runtime-chunk.mdx +2 -2
- package/docs/zh/configure/app/output/filename.mdx +2 -4
- package/docs/zh/configure/app/output/inline-scripts.mdx +1 -1
- package/docs/zh/configure/app/output/override-browserslist.mdx +3 -3
- package/docs/zh/configure/app/output/source-map.mdx +10 -3
- package/docs/zh/configure/app/output/ssg.mdx +13 -45
- package/docs/zh/configure/app/output/ssgByEntries.mdx +94 -0
- package/docs/zh/configure/app/output/temp-dir.mdx +3 -3
- package/docs/zh/configure/app/performance/build-cache.mdx +1 -5
- package/docs/zh/configure/app/performance/profile.mdx +1 -1
- package/docs/zh/configure/app/plugins.mdx +1 -2
- package/docs/zh/configure/app/resolve/alias-strategy.mdx +14 -0
- package/docs/zh/configure/app/resolve/alias.mdx +13 -0
- package/docs/zh/configure/app/resolve/condition-names.mdx +18 -0
- package/docs/zh/configure/app/resolve/dedupe.mdx +14 -0
- package/docs/zh/configure/app/resolve/extensions.mdx +18 -0
- package/docs/zh/configure/app/runtime/0-intro.mdx +2 -53
- package/docs/zh/configure/app/runtime/router.mdx +0 -4
- package/docs/zh/configure/app/security/check-syntax.mdx +1 -1
- package/docs/zh/configure/app/security/sri.mdx +0 -1
- package/docs/zh/configure/app/server/port.mdx +2 -21
- package/docs/zh/configure/app/server/rsc.mdx +30 -0
- package/docs/zh/configure/app/server/ssr.mdx +21 -11
- package/docs/zh/configure/app/source/alias.mdx +1 -1
- package/docs/zh/configure/app/source/decorators.mdx +4 -4
- package/docs/zh/configure/app/source/enable-async-entry.mdx +1 -1
- package/docs/zh/configure/app/source/entries.mdx +0 -2
- package/docs/zh/configure/app/source/include.mdx +2 -16
- package/docs/zh/configure/app/source/main-entry-name.mdx +4 -4
- package/docs/zh/configure/app/source/transform-import.mdx +1 -59
- package/docs/zh/configure/app/tools/bundler-chain.mdx +6 -6
- package/docs/zh/configure/app/tools/css-extract.mdx +1 -1
- package/docs/zh/configure/app/tools/dev-server.mdx +14 -248
- package/docs/zh/configure/app/tools/html-plugin.mdx +3 -2
- package/docs/zh/configure/app/tools/lightningcss-loader.mdx +0 -1
- package/docs/zh/configure/app/tools/swc.mdx +1 -43
- package/docs/zh/configure/app/usage.mdx +6 -28
- package/docs/zh/guides/_meta.json +5 -1
- package/docs/zh/guides/advanced-features/_meta.json +6 -1
- package/docs/zh/guides/advanced-features/bff/_meta.json +9 -1
- package/docs/zh/guides/advanced-features/bff/cross-project.mdx +8 -16
- package/docs/zh/guides/advanced-features/bff/extend-server.mdx +25 -8
- package/docs/zh/guides/advanced-features/bff/frameworks.mdx +2 -16
- package/docs/zh/guides/advanced-features/bff/function.mdx +7 -12
- package/docs/zh/guides/advanced-features/bff/operators.mdx +628 -0
- package/docs/zh/guides/advanced-features/bff/sdk.mdx +23 -16
- package/docs/zh/guides/advanced-features/bff/upload.mdx +3 -1
- package/docs/zh/guides/advanced-features/build-performance.mdx +23 -30
- package/docs/zh/guides/advanced-features/compatibility.mdx +44 -0
- package/docs/zh/guides/advanced-features/international/_meta.json +11 -0
- package/docs/zh/guides/advanced-features/international/advanced.mdx +193 -0
- package/docs/zh/guides/advanced-features/international/api.mdx +400 -0
- package/docs/zh/guides/advanced-features/international/basic.mdx +416 -0
- package/docs/zh/guides/advanced-features/international/best-practices.mdx +135 -0
- package/docs/zh/guides/advanced-features/international/configuration.mdx +432 -0
- package/docs/zh/guides/advanced-features/international/locale-detection.mdx +304 -0
- package/docs/zh/guides/advanced-features/international/quick-start.mdx +126 -0
- package/docs/zh/guides/advanced-features/international/resource-loading.mdx +417 -0
- package/docs/zh/guides/advanced-features/international/routing.mdx +212 -0
- package/docs/zh/guides/advanced-features/international.mdx +36 -0
- package/docs/zh/guides/advanced-features/low-level.mdx +21 -16
- package/docs/zh/guides/advanced-features/page-performance/code-split.mdx +3 -3
- package/docs/zh/guides/advanced-features/page-performance/inline-assets.mdx +4 -4
- package/docs/zh/guides/advanced-features/page-performance/optimize-bundle.mdx +8 -22
- package/docs/zh/guides/advanced-features/page-performance/react-compiler.mdx +19 -12
- package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +0 -4
- package/docs/zh/guides/advanced-features/server-monitor/monitors.mdx +120 -37
- package/docs/zh/guides/advanced-features/web-server.mdx +79 -300
- package/docs/zh/guides/basic-features/_meta.json +6 -1
- package/docs/zh/guides/basic-features/css/css-in-js.mdx +40 -5
- package/docs/zh/guides/basic-features/css/css-modules.mdx +6 -17
- package/docs/zh/guides/basic-features/css/css.mdx +2 -2
- package/docs/zh/guides/basic-features/css/tailwindcss.mdx +6 -90
- package/docs/zh/guides/basic-features/data/data-cache.mdx +55 -59
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +14 -16
- package/docs/zh/guides/basic-features/data/data-write.mdx +4 -4
- package/docs/zh/guides/basic-features/debug/mock.mdx +4 -1
- package/docs/zh/guides/basic-features/debug/proxy.mdx +4 -15
- package/docs/zh/guides/basic-features/debug/rsdoctor.mdx +6 -6
- package/docs/zh/guides/basic-features/deploy.mdx +24 -20
- package/docs/zh/guides/basic-features/env-vars.mdx +1 -1
- package/docs/zh/guides/basic-features/html.mdx +2 -2
- package/docs/zh/guides/basic-features/output-files.mdx +3 -3
- package/docs/zh/guides/basic-features/render/_meta.json +1 -1
- package/docs/zh/guides/basic-features/render/before-render.mdx +17 -24
- package/docs/zh/guides/basic-features/render/overview.mdx +52 -0
- package/docs/zh/guides/basic-features/render/rsc.mdx +399 -0
- package/docs/zh/guides/basic-features/render/ssg.mdx +27 -69
- package/docs/zh/guides/basic-features/render/ssr-cache.mdx +5 -9
- package/docs/zh/guides/basic-features/render/ssr.mdx +34 -31
- package/docs/zh/guides/basic-features/render/streaming-ssr.mdx +34 -14
- package/docs/zh/guides/basic-features/routes/_meta.json +1 -0
- package/docs/zh/guides/basic-features/routes/config-routes.mdx +426 -0
- package/docs/zh/guides/basic-features/{routes.mdx → routes/routes.mdx} +8 -114
- package/docs/zh/guides/basic-features/static-assets/json-files.mdx +21 -3
- package/docs/zh/guides/basic-features/static-assets/svg-assets.mdx +0 -4
- package/docs/zh/guides/basic-features/static-assets.mdx +2 -2
- package/docs/zh/guides/basic-features/testing/cypress.mdx +5 -5
- package/docs/zh/guides/basic-features/testing/jest.mdx +12 -12
- package/docs/zh/guides/concept/builder.mdx +26 -11
- package/docs/zh/guides/concept/entries.mdx +95 -92
- package/docs/zh/guides/get-started/glossary.mdx +0 -18
- package/docs/zh/guides/get-started/introduction.mdx +1 -5
- package/docs/zh/guides/get-started/quick-start.mdx +5 -72
- package/docs/zh/guides/get-started/tech-stack.mdx +8 -28
- package/docs/zh/guides/get-started/upgrade.mdx +30 -23
- package/docs/zh/guides/topic-detail/_meta.json +0 -12
- package/docs/zh/guides/topic-detail/module-federation/_meta.json +1 -1
- package/docs/zh/guides/topic-detail/module-federation/application.mdx +18 -16
- package/docs/zh/guides/topic-detail/module-federation/i18n.mdx +623 -0
- package/docs/zh/guides/topic-detail/module-federation/introduce.mdx +4 -4
- package/docs/zh/guides/topic-detail/module-federation/ssr.mdx +51 -5
- package/docs/zh/guides/topic-detail/module-federation/usage.mdx +11 -31
- package/docs/zh/guides/troubleshooting/builder.mdx +4 -85
- package/docs/zh/guides/troubleshooting/cli.mdx +6 -30
- package/docs/zh/guides/troubleshooting/dependencies.mdx +23 -23
- package/docs/zh/guides/upgrade/_meta.json +1 -0
- package/docs/zh/guides/upgrade/config.mdx +940 -0
- package/docs/zh/guides/upgrade/entry.mdx +463 -0
- package/docs/zh/guides/upgrade/other.md +90 -0
- package/docs/zh/guides/upgrade/overview.mdx +36 -0
- package/docs/zh/guides/upgrade/tailwindcss.mdx +130 -0
- package/docs/zh/guides/upgrade/web-server.md +93 -0
- package/docs/zh/plugin/_meta.json +5 -0
- package/docs/zh/plugin/cli-plugins/_meta.json +1 -1
- package/docs/zh/plugin/cli-plugins/api.mdx +19 -70
- package/docs/zh/plugin/cli-plugins/life-cycle.mdx +0 -4
- package/docs/zh/plugin/introduction.mdx +40 -40
- package/docs/zh/plugin/official/_meta.json +0 -5
- package/docs/zh/plugin/official/cli-plugins/_meta.json +1 -1
- package/docs/zh/plugin/official/cli-plugins/plugin-styled-components.mdx +5 -0
- package/docs/zh/plugin/official/cli-plugins.mdx +0 -2
- package/docs/zh/plugin/plugin-system.mdx +43 -51
- package/docs/zh/plugin/runtime-plugins/_meta.json +1 -1
- package/docs/zh/plugin/runtime-plugins/api.mdx +58 -56
- package/docs/zh/plugin/server-plugins/_meta.json +1 -0
- package/docs/zh/plugin/server-plugins/api.mdx +210 -1
- package/docs/zh/plugin/server-plugins/life-cycle.mdx +41 -1
- package/docs/zh/tutorials/_meta.json +0 -10
- package/docs/zh/tutorials/examples/csr-auth.mdx +1 -1
- package/docs/zh/tutorials/foundations/introduction.mdx +8 -25
- package/i18n.json +0 -16
- package/package.json +12 -12
- package/rspress.config.ts +5 -8
- package/src/components/ContentCard/index.module.scss +11 -7
- package/src/components/ContentCard/index.tsx +1 -1
- package/src/components/FeatureLayout/index.module.css +1 -1
- package/src/components/Footer/index.tsx +2 -14
- package/src/components/Footer/styles.module.scss +5 -5
- package/src/components/FrameworkCode/index.tsx +605 -0
- package/src/components/ListCard/index.tsx +1 -1
- package/src/components/RandomMemberList/index.tsx +1 -1
- package/src/components/RsbuildLink/index.tsx +1 -1
- package/src/components/Sandpack/index.tsx +1 -1
- package/src/custom.scss +15 -0
- package/src/i18n/enUS.ts +2 -4
- package/src/i18n/index.ts +1 -1
- package/src/i18n/zhCN.ts +2 -4
- package/src/index.ts +2 -1
- package/src/pages/index.module.scss +59 -41
- package/src/pages/index.tsx +9 -24
- package/docs/en/apis/app/hooks/server/index_.mdx +0 -10
- package/docs/en/apis/app/hooks/src/index_.mdx +0 -38
- package/docs/en/apis/app/hooks/src/stories.mdx +0 -16
- package/docs/en/apis/app/runtime/app/define-config.mdx +0 -67
- package/docs/en/apis/app/runtime/core/bootstrap.mdx +0 -74
- package/docs/en/apis/app/runtime/core/create-app.mdx +0 -49
- package/docs/en/apis/app/runtime/core/use-loader.mdx +0 -89
- package/docs/en/apis/app/runtime/core/use-module-apps.mdx +0 -140
- package/docs/en/apis/app/runtime/core/use-runtime-context.mdx +0 -116
- package/docs/en/apis/app/runtime/model/Provider.mdx +0 -36
- package/docs/en/apis/app/runtime/model/auto-actions.mdx +0 -122
- package/docs/en/apis/app/runtime/model/connect.mdx +0 -146
- package/docs/en/apis/app/runtime/model/create-app.mdx +0 -75
- package/docs/en/apis/app/runtime/model/create-store.mdx +0 -61
- package/docs/en/apis/app/runtime/model/handle-effect.mdx +0 -107
- package/docs/en/apis/app/runtime/model/model_.mdx +0 -198
- package/docs/en/apis/app/runtime/model/use-local-model.mdx +0 -29
- package/docs/en/apis/app/runtime/model/use-model.mdx +0 -89
- package/docs/en/apis/app/runtime/model/use-static-model.mdx +0 -51
- package/docs/en/apis/app/runtime/model/use-store.mdx +0 -26
- package/docs/en/apis/app/runtime/ssr/pre-render.mdx +0 -96
- package/docs/en/apis/app/runtime/web-server/hook.mdx +0 -134
- package/docs/en/apis/app/runtime/web-server/middleware.mdx +0 -113
- package/docs/en/apis/app/runtime/web-server/unstable_middleware.mdx +0 -167
- package/docs/en/components/bff-proxy-path-rewrite.mdx +0 -16
- package/docs/en/components/bff-proxy-principle.mdx +0 -1
- package/docs/en/components/builder.mdx +0 -3
- package/docs/en/components/create-bff-api-app.mdx +0 -25
- package/docs/en/components/custom-router-micro-frontend.mdx +0 -40
- package/docs/en/components/enable-micro-frontend.mdx +0 -30
- package/docs/en/components/enableSwc.mdx +0 -17
- package/docs/en/components/global-proxy-config.mdx +0 -85
- package/docs/en/components/global-proxy.mdx +0 -29
- package/docs/en/components/package-manager.mdx +0 -11
- package/docs/en/components/reduck-notify.mdx +0 -27
- package/docs/en/components/reduck-tip.mdx +0 -8
- package/docs/en/configure/app/auto-load-plugin.mdx +0 -66
- package/docs/en/configure/app/deploy/microFrontend.mdx +0 -53
- package/docs/en/configure/app/dev/port.mdx +0 -25
- package/docs/en/configure/app/dev/proxy.mdx +0 -9
- package/docs/en/configure/app/experiments/lazy-compilation.mdx +0 -106
- package/docs/en/configure/app/html/disable-html-folder.mdx +0 -46
- package/docs/en/configure/app/html/favicon-by-entries.mdx +0 -36
- package/docs/en/configure/app/html/inject-by-entries.mdx +0 -36
- package/docs/en/configure/app/html/meta-by-entries.mdx +0 -48
- package/docs/en/configure/app/html/tags-by-entries.mdx +0 -44
- package/docs/en/configure/app/html/template-by-entries.mdx +0 -33
- package/docs/en/configure/app/html/template-parameters-by-entries.mdx +0 -35
- package/docs/en/configure/app/html/title-by-entries.mdx +0 -37
- package/docs/en/configure/app/output/css-module-local-ident-name.mdx +0 -21
- package/docs/en/configure/app/output/disable-css-extract.mdx +0 -16
- package/docs/en/configure/app/output/disable-filename-hash.mdx +0 -16
- package/docs/en/configure/app/output/disable-minimize.mdx +0 -14
- package/docs/en/configure/app/output/disable-node-polyfill.mdx +0 -22
- package/docs/en/configure/app/output/disable-source-map.mdx +0 -31
- package/docs/en/configure/app/output/enable-asset-fallback.mdx +0 -36
- package/docs/en/configure/app/output/enable-inline-scripts.mdx +0 -22
- package/docs/en/configure/app/output/enable-inline-styles.mdx +0 -22
- package/docs/en/configure/app/output/enable-latest-decorators.mdx +0 -14
- package/docs/en/configure/app/performance/bundle-analyze.mdx +0 -24
- package/docs/en/configure/app/performance/transform-lodash.mdx +0 -52
- package/docs/en/configure/app/runtime/master-app.mdx +0 -36
- package/docs/en/configure/app/runtime/state.mdx +0 -52
- package/docs/en/configure/app/source/disable-entry-dirs.mdx +0 -38
- package/docs/en/configure/app/source/enable-custom-entry.mdx +0 -68
- package/docs/en/configure/app/source/module-scopes.mdx +0 -72
- package/docs/en/configure/app/source/resolve-extension-prefix.mdx +0 -55
- package/docs/en/configure/app/source/resolve-main-fields.mdx +0 -46
- package/docs/en/configure/app/tools/babel.mdx +0 -225
- package/docs/en/configure/app/tools/esbuild.mdx +0 -44
- package/docs/en/configure/app/tools/pug.mdx +0 -54
- package/docs/en/configure/app/tools/styled-components.mdx +0 -55
- package/docs/en/configure/app/tools/tailwindcss.mdx +0 -98
- package/docs/en/configure/app/tools/terser.mdx +0 -58
- package/docs/en/configure/app/tools/ts-loader.mdx +0 -76
- package/docs/en/configure/app/tools/webpack-chain.mdx +0 -253
- package/docs/en/configure/app/tools/webpack.mdx +0 -309
- package/docs/en/guides/deprecated.md +0 -17
- package/docs/en/guides/topic-detail/micro-frontend/c01-introduction.mdx +0 -27
- package/docs/en/guides/topic-detail/micro-frontend/c02-development.mdx +0 -290
- package/docs/en/guides/topic-detail/micro-frontend/c03-main-app.mdx +0 -298
- package/docs/en/guides/topic-detail/micro-frontend/c04-communicate.mdx +0 -58
- package/docs/en/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +0 -26
- package/docs/en/guides/topic-detail/model/_meta.json +0 -14
- package/docs/en/guides/topic-detail/model/auto-actions.mdx +0 -85
- package/docs/en/guides/topic-detail/model/computed-state.mdx +0 -148
- package/docs/en/guides/topic-detail/model/define-model.mdx +0 -62
- package/docs/en/guides/topic-detail/model/faq.mdx +0 -35
- package/docs/en/guides/topic-detail/model/manage-effects.mdx +0 -247
- package/docs/en/guides/topic-detail/model/model-communicate.mdx +0 -217
- package/docs/en/guides/topic-detail/model/performance.mdx +0 -167
- package/docs/en/guides/topic-detail/model/quick-start.mdx +0 -117
- package/docs/en/guides/topic-detail/model/redux-integration.mdx +0 -20
- package/docs/en/guides/topic-detail/model/typescript-best-practice.mdx +0 -68
- package/docs/en/guides/topic-detail/model/use-model.mdx +0 -243
- package/docs/en/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -46
- package/docs/en/plugin/cli-plugins/migration.mdx +0 -98
- package/docs/en/plugin/official/cli-plugins/plugin-swc.mdx +0 -363
- package/docs/en/plugin/official/cli-plugins/plugin-tailwind.mdx +0 -5
- package/docs/en/plugin/official/rsbuild-plugins/_meta.json +0 -1
- package/docs/en/plugin/official/rsbuild-plugins/plugin-esbuild.mdx +0 -205
- package/docs/en/plugin/official/rsbuild-plugins.mdx +0 -3
- package/docs/en/plugin/runtime-plugins/migration.mdx +0 -101
- package/docs/en/tutorials/first-app/c01-start.mdx +0 -99
- package/docs/en/tutorials/first-app/c02-component.mdx +0 -60
- package/docs/en/tutorials/first-app/c03-css.mdx +0 -324
- package/docs/en/tutorials/first-app/c04-routes.mdx +0 -172
- package/docs/en/tutorials/first-app/c05-loader.mdx +0 -87
- package/docs/en/tutorials/first-app/c06-model.mdx +0 -278
- package/docs/en/tutorials/first-app/c07-container.mdx +0 -281
- package/docs/en/tutorials/first-app/c08-entries.mdx +0 -135
- package/docs/zh/apis/app/hooks/server/index_.mdx +0 -10
- package/docs/zh/apis/app/hooks/src/index_.mdx +0 -39
- package/docs/zh/apis/app/hooks/src/stories.mdx +0 -16
- package/docs/zh/apis/app/runtime/app/define-config.mdx +0 -67
- package/docs/zh/apis/app/runtime/core/bootstrap.mdx +0 -74
- package/docs/zh/apis/app/runtime/core/create-app.mdx +0 -35
- package/docs/zh/apis/app/runtime/core/use-loader.mdx +0 -89
- package/docs/zh/apis/app/runtime/core/use-module-apps.mdx +0 -179
- package/docs/zh/apis/app/runtime/core/use-runtime-context.mdx +0 -116
- package/docs/zh/apis/app/runtime/model/Provider.mdx +0 -36
- package/docs/zh/apis/app/runtime/model/auto-actions.mdx +0 -122
- package/docs/zh/apis/app/runtime/model/connect.mdx +0 -143
- package/docs/zh/apis/app/runtime/model/create-app.mdx +0 -75
- package/docs/zh/apis/app/runtime/model/create-store.mdx +0 -61
- package/docs/zh/apis/app/runtime/model/handle-effect.mdx +0 -108
- package/docs/zh/apis/app/runtime/model/model_.mdx +0 -201
- package/docs/zh/apis/app/runtime/model/use-local-model.mdx +0 -29
- package/docs/zh/apis/app/runtime/model/use-model.mdx +0 -89
- package/docs/zh/apis/app/runtime/model/use-static-model.mdx +0 -49
- package/docs/zh/apis/app/runtime/model/use-store.mdx +0 -26
- package/docs/zh/apis/app/runtime/ssr/pre-render.mdx +0 -96
- package/docs/zh/apis/app/runtime/web-server/hook.mdx +0 -136
- package/docs/zh/apis/app/runtime/web-server/middleware.mdx +0 -114
- package/docs/zh/apis/app/runtime/web-server/unstable_middleware.mdx +0 -165
- package/docs/zh/components/bff-proxy-path-rewrite.mdx +0 -16
- package/docs/zh/components/bff-proxy-principle.mdx +0 -1
- package/docs/zh/components/builder.mdx +0 -3
- package/docs/zh/components/create-bff-api-app.mdx +0 -25
- package/docs/zh/components/custom-router-micro-frontend.mdx +0 -40
- package/docs/zh/components/default-mwa-generate.mdx +0 -4
- package/docs/zh/components/enable-micro-frontend.mdx +0 -30
- package/docs/zh/components/enableSwc.mdx +0 -17
- package/docs/zh/components/global-proxy-config.mdx +0 -85
- package/docs/zh/components/global-proxy.mdx +0 -29
- package/docs/zh/components/package-manager.mdx +0 -11
- package/docs/zh/components/reduck-notify.mdx +0 -27
- package/docs/zh/components/reduck-tip.mdx +0 -8
- package/docs/zh/configure/app/auto-load-plugin.mdx +0 -66
- package/docs/zh/configure/app/deploy/microFrontend.mdx +0 -55
- package/docs/zh/configure/app/dev/port.mdx +0 -25
- package/docs/zh/configure/app/dev/proxy.mdx +0 -9
- package/docs/zh/configure/app/experiments/lazy-compilation.mdx +0 -105
- package/docs/zh/configure/app/html/disable-html-folder.mdx +0 -45
- package/docs/zh/configure/app/html/favicon-by-entries.mdx +0 -37
- package/docs/zh/configure/app/html/inject-by-entries.mdx +0 -37
- package/docs/zh/configure/app/html/meta-by-entries.mdx +0 -48
- package/docs/zh/configure/app/html/tags-by-entries.mdx +0 -44
- package/docs/zh/configure/app/html/template-by-entries.mdx +0 -33
- package/docs/zh/configure/app/html/template-parameters-by-entries.mdx +0 -36
- package/docs/zh/configure/app/html/title-by-entries.mdx +0 -37
- package/docs/zh/configure/app/output/css-module-local-ident-name.mdx +0 -21
- package/docs/zh/configure/app/output/disable-css-extract.mdx +0 -16
- package/docs/zh/configure/app/output/disable-filename-hash.mdx +0 -16
- package/docs/zh/configure/app/output/disable-minimize.mdx +0 -14
- package/docs/zh/configure/app/output/disable-node-polyfill.mdx +0 -22
- package/docs/zh/configure/app/output/disable-source-map.mdx +0 -31
- package/docs/zh/configure/app/output/enable-asset-fallback.mdx +0 -36
- package/docs/zh/configure/app/output/enable-inline-scripts.mdx +0 -22
- package/docs/zh/configure/app/output/enable-inline-styles.mdx +0 -22
- package/docs/zh/configure/app/output/enable-latest-decorators.mdx +0 -14
- package/docs/zh/configure/app/performance/bundle-analyze.mdx +0 -24
- package/docs/zh/configure/app/performance/transform-lodash.mdx +0 -52
- package/docs/zh/configure/app/runtime/master-app.mdx +0 -38
- package/docs/zh/configure/app/runtime/state.mdx +0 -52
- package/docs/zh/configure/app/source/disable-entry-dirs.mdx +0 -38
- package/docs/zh/configure/app/source/enable-custom-entry.mdx +0 -67
- package/docs/zh/configure/app/source/module-scopes.mdx +0 -72
- package/docs/zh/configure/app/source/resolve-extension-prefix.mdx +0 -57
- package/docs/zh/configure/app/source/resolve-main-fields.mdx +0 -46
- package/docs/zh/configure/app/tools/babel.mdx +0 -224
- package/docs/zh/configure/app/tools/esbuild.mdx +0 -44
- package/docs/zh/configure/app/tools/pug.mdx +0 -54
- package/docs/zh/configure/app/tools/styled-components.mdx +0 -54
- package/docs/zh/configure/app/tools/tailwindcss.mdx +0 -98
- package/docs/zh/configure/app/tools/terser.mdx +0 -58
- package/docs/zh/configure/app/tools/ts-loader.mdx +0 -76
- package/docs/zh/configure/app/tools/webpack-chain.mdx +0 -257
- package/docs/zh/configure/app/tools/webpack.mdx +0 -309
- package/docs/zh/guides/advanced-features/rspack-start.mdx +0 -154
- package/docs/zh/guides/deprecated.md +0 -19
- package/docs/zh/guides/topic-detail/micro-frontend/c01-introduction.mdx +0 -26
- package/docs/zh/guides/topic-detail/micro-frontend/c02-development.mdx +0 -332
- package/docs/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +0 -296
- package/docs/zh/guides/topic-detail/micro-frontend/c04-communicate.mdx +0 -58
- package/docs/zh/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +0 -27
- package/docs/zh/guides/topic-detail/model/_meta.json +0 -14
- package/docs/zh/guides/topic-detail/model/auto-actions.mdx +0 -88
- package/docs/zh/guides/topic-detail/model/computed-state.mdx +0 -147
- package/docs/zh/guides/topic-detail/model/define-model.mdx +0 -63
- package/docs/zh/guides/topic-detail/model/faq.mdx +0 -36
- package/docs/zh/guides/topic-detail/model/manage-effects.mdx +0 -256
- package/docs/zh/guides/topic-detail/model/model-communicate.mdx +0 -217
- package/docs/zh/guides/topic-detail/model/performance.mdx +0 -167
- package/docs/zh/guides/topic-detail/model/quick-start.mdx +0 -117
- package/docs/zh/guides/topic-detail/model/redux-integration.mdx +0 -20
- package/docs/zh/guides/topic-detail/model/typescript-best-practice.mdx +0 -67
- package/docs/zh/guides/topic-detail/model/use-model.mdx +0 -248
- package/docs/zh/guides/topic-detail/model/use-out-of-modernjs.mdx +0 -46
- package/docs/zh/plugin/cli-plugins/migration.mdx +0 -98
- package/docs/zh/plugin/official/cli-plugins/plugin-swc.mdx +0 -351
- package/docs/zh/plugin/official/cli-plugins/plugin-tailwind.mdx +0 -5
- package/docs/zh/plugin/official/rsbuild-plugins/_meta.json +0 -1
- package/docs/zh/plugin/official/rsbuild-plugins/plugin-esbuild.mdx +0 -201
- package/docs/zh/plugin/official/rsbuild-plugins.mdx +0 -3
- package/docs/zh/plugin/runtime-plugins/migration.mdx +0 -101
- package/docs/zh/tutorials/first-app/c01-start.mdx +0 -99
- package/docs/zh/tutorials/first-app/c02-component.mdx +0 -60
- package/docs/zh/tutorials/first-app/c03-css.mdx +0 -323
- package/docs/zh/tutorials/first-app/c04-routes.mdx +0 -172
- package/docs/zh/tutorials/first-app/c05-loader.mdx +0 -89
- package/docs/zh/tutorials/first-app/c06-model.mdx +0 -274
- package/docs/zh/tutorials/first-app/c07-container.mdx +0 -281
- package/docs/zh/tutorials/first-app/c08-entries.mdx +0 -135
- /package/docs/en/components/{reduck-migration.mdx → auto-upgrade.mdx} +0 -0
- /package/docs/en/components/{router-legacy-tip.mdx → international/platform-support.mdx} +0 -0
- /package/docs/{zh/components/reduck-migration.mdx → en/components/new-entry-tooltip.mdx} +0 -0
- /package/docs/{zh/components/router-legacy-tip.mdx → en/components/upgrade-browserslist.mdx} +0 -0
|
@@ -1,23 +1,60 @@
|
|
|
1
1
|
# Using CSS-in-JS
|
|
2
2
|
|
|
3
|
-
CSS-in-JS is a technique that allows you to write CSS styles
|
|
3
|
+
CSS-in-JS is a technique that allows you to write CSS styles within JS files.
|
|
4
4
|
|
|
5
|
-
Modern.js
|
|
5
|
+
Modern.js supports the commonly used community CSS-in-JS library [styled-components](https://styled-components.com/), which uses JavaScript's new feature [Tagged template](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates) to write component CSS styles.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
The Modern.js plugin `@modern-js/plugin-styled-components` provides support for styled-components and adds server-side rendering capability for styled-components. You can use styled-components by installing the `@modern-js/plugin-styled-components` plugin.
|
|
8
|
+
|
|
9
|
+
## Using styled-components in Modern.js
|
|
10
|
+
|
|
11
|
+
First, you need to install the `styled-components` plugin dependency and the `styled-components` library:
|
|
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
|
+
Then configure the `styled-components` plugin in `modern.config.ts`:
|
|
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
|
+
The configuration options of the styledComponentsPlugin plugin are the same as those of the [@rsbuild/plugin-styled-components](https://www.npmjs.com/package/@rsbuild/plugin-styled-components) plugin. You can refer to the documentation of [@rsbuild/plugin-styled-components](https://www.npmjs.com/package/@rsbuild/plugin-styled-components) for configuration.
|
|
41
|
+
|
|
42
|
+
## Writing styles with styled-components
|
|
43
|
+
|
|
44
|
+
When you need to write a `div` component with red text inside, you can implement it as follows:
|
|
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;
|
|
14
51
|
`;
|
|
15
52
|
```
|
|
16
53
|
|
|
17
|
-
|
|
54
|
+
When you need to dynamically set component styles based on the component's `props`, for example, when the `primary` attribute of `props` is `true`, the button's color is white, otherwise red, the implementation is as follows:
|
|
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')};
|
|
@@ -25,10 +62,8 @@ const Button = styled.button`
|
|
|
25
62
|
`;
|
|
26
63
|
```
|
|
27
64
|
|
|
28
|
-
For more usage of styled-components, please refer to [styled-components official website](https://styled-components.com/).
|
|
29
|
-
|
|
30
|
-
Modern.js integrates Babel's [babel-plugin-styled-components](https://github.com/styled-components/babel-plugin-styled-components) plugin internally, and you can configure the plugin through [tools.styledComponents](/configure/app/tools/styled-components).
|
|
65
|
+
For more usage of styled-components, please refer to the [styled-components official website](https://styled-components.com/).
|
|
31
66
|
|
|
32
|
-
:::tip
|
|
33
|
-
If you
|
|
67
|
+
:::tip Tip
|
|
68
|
+
If you want to use other CSS-in-JS libraries such as [styled-jsx](https://www.npmjs.com/package/styled-jsx), [Emotion](https://emotion.sh/), etc., you need to install the corresponding dependencies first. Please refer to the official websites of the respective libraries for specific usage.
|
|
34
69
|
:::
|
|
@@ -77,20 +77,6 @@ export default {
|
|
|
77
77
|
};
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
## Custom Class Names
|
|
81
|
-
|
|
82
|
-
Customizing the class names generated by CSS Modules is also a commonly used function, you can use [output.cssModuleLocalIdentName](/configure/app/output/css-modules.html#cssmodulesexportlocalsconvention) to configure it.
|
|
83
|
-
|
|
84
|
-
```ts
|
|
85
|
-
export default {
|
|
86
|
-
output: {
|
|
87
|
-
cssModuleLocalIdentName: '[hash:base64:4]',
|
|
88
|
-
},
|
|
89
|
-
};
|
|
90
|
-
```
|
|
91
|
-
|
|
92
|
-
If you need to customize other configs of CSS Modules, you can set them via [tools.cssLoader](/configure/app/tools/css-loader).
|
|
93
|
-
|
|
94
80
|
## Add Type Declaration
|
|
95
81
|
|
|
96
82
|
When you import CSS Modules in TypeScript code, TypeScript may prompt that the module is missing a type definition:
|
|
@@ -181,9 +167,11 @@ For example, there are two files `src/index.ts` and `src/index.module.scss` unde
|
|
|
181
167
|
import styles from './index.module.scss';
|
|
182
168
|
|
|
183
169
|
export default () => {
|
|
184
|
-
|
|
185
|
-
<div
|
|
186
|
-
|
|
170
|
+
return (
|
|
171
|
+
<div>
|
|
172
|
+
<div className={styles.pageHeader}>Page Header</div>
|
|
173
|
+
</div>
|
|
174
|
+
);
|
|
187
175
|
};
|
|
188
176
|
```
|
|
189
177
|
|
|
@@ -18,14 +18,14 @@ You can also use Stylus in Modern.js by installing the Stylus plugin provided by
|
|
|
18
18
|
|
|
19
19
|
Modern.js has built-in [PostCSS](https://postcss.org/) to transform CSS code.
|
|
20
20
|
|
|
21
|
-
Please refer to [Rsbuild - Using PostCSS](https://rsbuild.rs/guide/
|
|
21
|
+
Please refer to [Rsbuild - Using PostCSS](https://rsbuild.rs/guide/styling/css-usage) for detailed usage.
|
|
22
22
|
|
|
23
23
|
## Using Lightning CSS
|
|
24
24
|
|
|
25
25
|
Modern.js supports using [Lightning CSS](https://lightningcss.dev/) to convert CSS code. This feature can be turned on by configuring [tools.lightningcssLoader](/configure/app/tools/lightningcss-loader).
|
|
26
26
|
|
|
27
|
-
Please refer to [Rsbuild - Using Lightning CSS](https://rsbuild.rs/guide/
|
|
27
|
+
Please refer to [Rsbuild - Using Lightning CSS](https://rsbuild.rs/guide/styling/css-usage#lightning-css) for detailed usage.
|
|
28
28
|
|
|
29
29
|
## Using Uno CSS
|
|
30
30
|
|
|
31
|
-
Please read the [Rsbuild - Using UnoCSS](https://rsbuild.rs/
|
|
31
|
+
Please read the [Rsbuild - Using UnoCSS](https://rsbuild.rs/guide/styling/unocss) for detailed usage.
|
|
@@ -2,86 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
[Tailwind CSS](https://tailwindcss.com/) is a CSS framework and design system based on Utility Class, which can quickly add common styles to components, and support flexible extension of theme styles.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## Using Tailwind CSS in Modern.js
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
To use [Tailwind CSS](https://tailwindcss.com/) in Modern.js, you only need to configure it according to the Rsbuild steps. Rsbuild supports Tailwind CSS versions v3 and v4:
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
? Please select the feature name: Enable Tailwind CSS
|
|
12
|
-
```
|
|
13
|
-
|
|
14
|
-
After successful initialization, you will see that the `package.json` has added dependencies for `tailwindcss` and `@modern-js/plugin-tailwindcss`.
|
|
15
|
-
|
|
16
|
-
2. Register the Tailwind plugin in `modern.config.ts`:
|
|
17
|
-
|
|
18
|
-
```ts title="modern.config.ts"
|
|
19
|
-
import { tailwindcssPlugin } from '@modern-js/plugin-tailwindcss';
|
|
20
|
-
|
|
21
|
-
export default defineConfig({
|
|
22
|
-
plugins: [..., tailwindcssPlugin()],
|
|
23
|
-
});
|
|
24
|
-
```
|
|
25
|
-
|
|
26
|
-
3. Create a `index.css` file and add the following code:
|
|
27
|
-
|
|
28
|
-
```css title="index.css"
|
|
29
|
-
@tailwind base;
|
|
30
|
-
@tailwind components;
|
|
31
|
-
@tailwind utilities;
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
:::info
|
|
35
|
-
Depending on your needs, you can selectively import the CSS styles provided by Tailwind CSS. Please refer to the [`@tailwind` documentation](https://tailwindcss.com/docs/functions-and-directives#tailwind) for detailed usage of the `@tailwind` directive.
|
|
36
|
-
:::
|
|
37
|
-
|
|
38
|
-
4. Import the `index.css` file, for example, add the following code in the root component `src/App.jsx`:
|
|
39
|
-
|
|
40
|
-
```js
|
|
41
|
-
import './index.css';
|
|
42
|
-
```
|
|
43
|
-
|
|
44
|
-
5. Now you can use the Utility Classes provided by Tailwind CSS in your components:
|
|
45
|
-
|
|
46
|
-
```tsx
|
|
47
|
-
const Hello = () => (
|
|
48
|
-
<div className="h-12 w-48">
|
|
49
|
-
<p className="text-xl font-medium text-black">hello world</p>
|
|
50
|
-
</div>
|
|
51
|
-
);
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
## Configuring Tailwind CSS
|
|
55
|
-
|
|
56
|
-
In Modern.js, you have two ways to configure Tailwind CSS:
|
|
57
|
-
|
|
58
|
-
1. Using the `tailwind.config.{ts,js}` file, which follows the official usage of Tailwind CSS. Please refer to ["Tailwind CSS - Configuration"](https://tailwindcss.com/docs/configuration) for more details.
|
|
59
|
-
|
|
60
|
-
```ts title="tailwind.config.ts"
|
|
61
|
-
import type { Config } from 'tailwindcss';
|
|
62
|
-
|
|
63
|
-
export default {
|
|
64
|
-
content: ['./src/**/*.{js,jsx,ts,tsx}'],
|
|
65
|
-
} as Config;
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
:::tip
|
|
69
|
-
Please upgrade Modern.js to version >= MAJOR_VERSION.33.0 to support automatic reading of `tailwind.config.{ts,js}` files.
|
|
70
|
-
:::
|
|
71
|
-
|
|
72
|
-
2. Using the [tools.tailwindcss](/configure/app/tools/tailwindcss.html) configuration option. This is the old way of configuring Tailwind CSS, and we recommend using the `tailwind.config.{ts,js}` file for configuration.
|
|
73
|
-
|
|
74
|
-
```ts title="modern.config.ts"
|
|
75
|
-
export default {
|
|
76
|
-
tools: {
|
|
77
|
-
tailwindcss: {
|
|
78
|
-
content: ['./src/**/*.{js,jsx,ts,tsx}'],
|
|
79
|
-
},
|
|
80
|
-
},
|
|
81
|
-
};
|
|
82
|
-
```
|
|
83
|
-
|
|
84
|
-
If you are using both the `tailwind.config.{ts,js}` file and `tools.tailwindcss` option, the configuration defined in `tools.tailwindcss` will take precedence and override the content defined in `tailwind.config.{ts,js}`.
|
|
9
|
+
- [Tailwind CSS v3](https://rsbuild.rs/guide/styling/tailwindcss-v3#tailwind-css-v3)
|
|
10
|
+
- [Tailwind CSS v4](https://rsbuild.rs/guide/styling/tailwindcss)
|
|
85
11
|
|
|
86
12
|
## Tailwind CSS Autocomplete
|
|
87
13
|
|
|
@@ -92,20 +18,10 @@ You can follow the steps below to enable the autocomplete feature:
|
|
|
92
18
|
1. Install the [Tailwind CSS IntelliSense](https://github.com/tailwindlabs/tailwindcss-intellisense) extension in VS Code.
|
|
93
19
|
2. If the root directory of your project does not have a `tailwind.config.{ts,js}` file, you need to create one and write the Tailwind CSS configuration for your current project. Otherwise, the IDE plugin will not work correctly.
|
|
94
20
|
|
|
95
|
-
## Tailwind CSS Version
|
|
96
|
-
|
|
97
|
-
Modern.js supports both Tailwind CSS v2 and v3 versions, and the framework will recognize the version of the `tailwindcss` dependency in the project `package.json` file and enable the corresponding configuration. By default, we will install Tailwind CSS v3 version for you.
|
|
98
|
-
|
|
99
|
-
If your project is still using Tailwind CSS v2, we recommend that you upgrade to v3 to support JIT and other capabilities. For the differences between Tailwind CSS v2 and v3 versions, please refer to the following articles:
|
|
100
|
-
|
|
101
|
-
- [Tailwind CSS v3.0](https://tailwindcss.com/blog/tailwindcss-v3)
|
|
102
|
-
- [Upgrade Guide](https://tailwindcss.com/docs/upgrade-guide)
|
|
103
|
-
|
|
104
21
|
## Browser Compatibility
|
|
105
22
|
|
|
106
|
-
Tailwind CSS
|
|
23
|
+
Tailwind CSS v3 does not support the IE 11 browser, please refer to:
|
|
107
24
|
|
|
108
25
|
- [Tailwind CSS v3 - Browser Support](https://tailwindcss.com/docs/browser-support).
|
|
109
|
-
- [Tailwind CSS v2 - Browser Support](https://v2.tailwindcss.com/docs/browser-support)
|
|
110
26
|
|
|
111
27
|
If you use Tailwind CSS on IE 11 browser, some styles may not be available, please use it with caution.
|
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
title: Data Caching
|
|
3
3
|
sidebar_position: 4
|
|
4
4
|
---
|
|
5
|
+
|
|
5
6
|
# Data Caching
|
|
6
7
|
|
|
7
8
|
The `cache` function allows you to cache the results of data fetching or computation, Compared to full-page [rendering cache](/guides/basic-features/render/ssr-cache), it provides more fine-grained control over data granularity and is applicable to various scenarios such as Client-Side Rendering (CSR), Server-Side Rendering (SSR), and API services (BFF).
|
|
8
9
|
|
|
9
|
-
:::info
|
|
10
|
-
X.65.5 and above versions are required
|
|
11
|
-
:::
|
|
12
|
-
|
|
13
10
|
## Basic Usage
|
|
14
11
|
|
|
15
12
|
:::note
|
|
@@ -20,7 +17,6 @@ If you use the `cache` function in BFF, you should import the cache funtion from
|
|
|
20
17
|
|
|
21
18
|
:::
|
|
22
19
|
|
|
23
|
-
|
|
24
20
|
```ts
|
|
25
21
|
import { cache } from '@modern-js/runtime/cache';
|
|
26
22
|
import { fetchUserData } from './api';
|
|
@@ -28,14 +24,13 @@ import { fetchUserData } from './api';
|
|
|
28
24
|
const getUser = cache(fetchUserData);
|
|
29
25
|
|
|
30
26
|
const loader = async () => {
|
|
31
|
-
const user = await getUser(
|
|
27
|
+
const user = await getUser('123'); // When the parameters of the function changes, the function will be re-executed
|
|
32
28
|
return {
|
|
33
29
|
user,
|
|
34
30
|
};
|
|
35
31
|
};
|
|
36
32
|
```
|
|
37
33
|
|
|
38
|
-
|
|
39
34
|
### Parameters
|
|
40
35
|
|
|
41
36
|
- `fn`: The data fetching or computation function to be cached
|
|
@@ -44,7 +39,7 @@ const loader = async () => {
|
|
|
44
39
|
- `maxAge`: Cache validity period (milliseconds)
|
|
45
40
|
- `revalidate`: Time window for revalidating the cache (milliseconds), similar to HTTP Cache-Control's stale-while-revalidate functionality
|
|
46
41
|
- `getKey`: Simplified cache key generation function based on function parameters
|
|
47
|
-
- `customKey`: Custom cache key function
|
|
42
|
+
- `customKey`: Custom cache key generation function, used to maintain cache when function references change
|
|
48
43
|
|
|
49
44
|
The type of the `options` parameter is as follows:
|
|
50
45
|
|
|
@@ -62,7 +57,6 @@ interface CacheOptions {
|
|
|
62
57
|
}
|
|
63
58
|
```
|
|
64
59
|
|
|
65
|
-
|
|
66
60
|
### Return Value
|
|
67
61
|
|
|
68
62
|
The `cache` function returns a new function with caching capabilities. Multiple calls to this function will not re-execute the `fn` function.
|
|
@@ -76,7 +70,7 @@ EdenX's `cache` function can be used in any frontend or server-side code.
|
|
|
76
70
|
|
|
77
71
|
### Without options Parameter
|
|
78
72
|
|
|
79
|
-
When no `options` parameter is provided, it's primarily useful in SSR projects, the cache lifecycle is limited to a single SSR rendering request. For example, when the same cachedFn is called in multiple data loaders, the cachedFn function won't be executed repeatedly. This allows data sharing between different data loaders while avoiding duplicate requests.
|
|
73
|
+
When no `options` parameter is provided, it's primarily useful in SSR projects, the cache lifecycle is limited to a single SSR rendering request. For example, when the same cachedFn is called in multiple data loaders, the cachedFn function won't be executed repeatedly. This allows data sharing between different data loaders while avoiding duplicate requests. Modern.js will re-execute the `fn` function with each server request.
|
|
80
74
|
|
|
81
75
|
:::info
|
|
82
76
|
Without the `options` parameter, it can be considered a replacement for React's [`cache`](https://react.dev/reference/react/cache) function and can be used in any server-side code (such as in data loaders of SSR projects), not limited to server components.
|
|
@@ -96,7 +90,6 @@ const loader = async () => {
|
|
|
96
90
|
};
|
|
97
91
|
```
|
|
98
92
|
|
|
99
|
-
|
|
100
93
|
### With options Parameter
|
|
101
94
|
|
|
102
95
|
#### `maxAge` Parameter
|
|
@@ -113,17 +106,20 @@ const getDashboardStats = cache(
|
|
|
113
106
|
return await fetchComplexStatistics();
|
|
114
107
|
},
|
|
115
108
|
{
|
|
116
|
-
maxAge: CacheTime.MINUTE * 2,
|
|
117
|
-
}
|
|
109
|
+
maxAge: CacheTime.MINUTE * 2, // Calling this function within 2 minutes will return cached data
|
|
110
|
+
},
|
|
118
111
|
);
|
|
119
112
|
```
|
|
120
113
|
|
|
121
|
-
|
|
122
114
|
#### `revalidate` Parameter
|
|
123
115
|
|
|
124
116
|
The `revalidate` parameter sets a time window for revalidating the cache after it expires. It can be used together with the `maxAge` parameter, similar to HTTP Cache-Control's stale-while-revalidate mode.
|
|
125
117
|
|
|
126
|
-
In the following example,
|
|
118
|
+
In the following example, the cache behavior is divided into three phases based on time:
|
|
119
|
+
|
|
120
|
+
1. **0 to 2 minutes (within `maxAge`)**: Cache is fresh, returns cached data directly without re-fetching
|
|
121
|
+
2. **2 to 3 minutes (between `maxAge` and `maxAge + revalidate`)**: Cache has expired but is within the revalidation window, returns stale data immediately while re-fetching and updating the cache in the background
|
|
122
|
+
3. **Beyond 3 minutes (exceeding `maxAge + revalidate`)**: Cache is completely expired, re-executes the function to fetch new data
|
|
127
123
|
|
|
128
124
|
```ts
|
|
129
125
|
import { cache, CacheTime } from '@modern-js/runtime/cache';
|
|
@@ -135,11 +131,10 @@ const getDashboardStats = cache(
|
|
|
135
131
|
{
|
|
136
132
|
maxAge: CacheTime.MINUTE * 2,
|
|
137
133
|
revalidate: CacheTime.MINUTE * 1,
|
|
138
|
-
}
|
|
134
|
+
},
|
|
139
135
|
);
|
|
140
136
|
```
|
|
141
137
|
|
|
142
|
-
|
|
143
138
|
#### `tag` Parameter
|
|
144
139
|
|
|
145
140
|
The `tag` parameter identifies the cache with a tag, which can be a string or an array of strings.
|
|
@@ -154,7 +149,7 @@ const getDashboardStats = cache(
|
|
|
154
149
|
},
|
|
155
150
|
{
|
|
156
151
|
tag: 'dashboard',
|
|
157
|
-
}
|
|
152
|
+
},
|
|
158
153
|
);
|
|
159
154
|
|
|
160
155
|
const getComplexStatistics = cache(
|
|
@@ -163,13 +158,12 @@ const getComplexStatistics = cache(
|
|
|
163
158
|
},
|
|
164
159
|
{
|
|
165
160
|
tag: 'dashboard',
|
|
166
|
-
}
|
|
161
|
+
},
|
|
167
162
|
);
|
|
168
163
|
|
|
169
|
-
await revalidateTag('dashboard
|
|
164
|
+
await revalidateTag('dashboard'); // Invalidates the cache for both getDashboardStats and getComplexStatistics functions
|
|
170
165
|
```
|
|
171
166
|
|
|
172
|
-
|
|
173
167
|
#### `getKey` Parameter
|
|
174
168
|
|
|
175
169
|
The `getKey` parameter simplifies cache key generation, especially useful when you only need to rely on part of the function parameters to differentiate caches. It's a function that receives the same parameters as the original function and returns a string.
|
|
@@ -189,15 +183,15 @@ const getUser = cache(
|
|
|
189
183
|
maxAge: CacheTime.MINUTE * 5,
|
|
190
184
|
// Only use the first parameter (userId) as the cache key
|
|
191
185
|
getKey: (userId, options) => userId,
|
|
192
|
-
}
|
|
186
|
+
},
|
|
193
187
|
);
|
|
194
188
|
|
|
195
189
|
// The following two calls will share the cache because getKey only uses userId
|
|
196
|
-
await getUser(123, { language: '
|
|
197
|
-
await getUser(123, { language: '
|
|
190
|
+
await getUser(123, { language: 'zh' });
|
|
191
|
+
await getUser(123, { language: 'en' }); // Cache hit, won't request again
|
|
198
192
|
|
|
199
193
|
// Different userId will use different cache
|
|
200
|
-
await getUser(456, { language: '
|
|
194
|
+
await getUser(456, { language: 'zh' }); // Won't hit cache, will request again
|
|
201
195
|
```
|
|
202
196
|
|
|
203
197
|
You can also use Modern.js's `generateKey` function together with getKey to generate the cache key:
|
|
@@ -219,21 +213,18 @@ const getUser = cache(
|
|
|
219
213
|
{
|
|
220
214
|
maxAge: CacheTime.MINUTE * 5,
|
|
221
215
|
getKey: (userId, options) => generateKey(userId),
|
|
222
|
-
}
|
|
216
|
+
},
|
|
223
217
|
);
|
|
224
218
|
```
|
|
225
219
|
|
|
226
220
|
Additionally, `getKey` can also return a numeric type as a cache key:
|
|
227
221
|
|
|
228
222
|
```ts
|
|
229
|
-
const getUserById = cache(
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
getKey: (id) => id,
|
|
235
|
-
}
|
|
236
|
-
);
|
|
223
|
+
const getUserById = cache(fetchUserDataById, {
|
|
224
|
+
maxAge: CacheTime.MINUTE * 5,
|
|
225
|
+
// Directly use the numeric ID as the cache key
|
|
226
|
+
getKey: id => id,
|
|
227
|
+
});
|
|
237
228
|
|
|
238
229
|
await getUserById(42); // Uses 42 as the cache key
|
|
239
230
|
```
|
|
@@ -251,6 +242,7 @@ Its return value **directly becomes** the final cache key, **overriding** the de
|
|
|
251
242
|
:::info
|
|
252
243
|
|
|
253
244
|
Generally, the cache will be invalidated in the following scenarios:
|
|
245
|
+
|
|
254
246
|
1. The function's input parameters change
|
|
255
247
|
2. The maxAge condition is no longer satisfied
|
|
256
248
|
3. The `revalidateTag` method has been called
|
|
@@ -266,16 +258,13 @@ import { cache } from '@modern-js/runtime/cache';
|
|
|
266
258
|
import { fetchUserData } from './api';
|
|
267
259
|
|
|
268
260
|
// Different function references, but share the same cache via customKey
|
|
269
|
-
const getUserA = cache(
|
|
270
|
-
|
|
271
|
-
{
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
},
|
|
277
|
-
}
|
|
278
|
-
);
|
|
261
|
+
const getUserA = cache(fetchUserData, {
|
|
262
|
+
maxAge: CacheTime.MINUTE * 5,
|
|
263
|
+
customKey: ({ params }) => {
|
|
264
|
+
// Return a stable string as the cache key
|
|
265
|
+
return `user-${params[0]}`;
|
|
266
|
+
},
|
|
267
|
+
});
|
|
279
268
|
|
|
280
269
|
// Even if the function reference changes,
|
|
281
270
|
// as long as customKey returns the same value, the cache will be hit
|
|
@@ -287,7 +276,7 @@ const getUserB = cache(
|
|
|
287
276
|
// Return the same key as getUserA
|
|
288
277
|
return `user-${params[0]}`;
|
|
289
278
|
},
|
|
290
|
-
}
|
|
279
|
+
},
|
|
291
280
|
);
|
|
292
281
|
|
|
293
282
|
// Now you can share cache across different function implementations
|
|
@@ -295,12 +284,9 @@ await getUserA(123); // Fetches data and caches with key "user-123"
|
|
|
295
284
|
await getUserB(123); // Cache hit, returns cached data
|
|
296
285
|
|
|
297
286
|
// You can utilize the generatedKey parameter to modify the default key
|
|
298
|
-
const getUserC = cache(
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
customKey: ({ generatedKey }) => `prefix-${generatedKey}`,
|
|
302
|
-
}
|
|
303
|
-
);
|
|
287
|
+
const getUserC = cache(fetchUserData, {
|
|
288
|
+
customKey: ({ generatedKey }) => `prefix-${generatedKey}`,
|
|
289
|
+
});
|
|
304
290
|
|
|
305
291
|
// For predictable cache keys that can be managed externally
|
|
306
292
|
const getUserD = cache(
|
|
@@ -310,7 +296,7 @@ const getUserD = cache(
|
|
|
310
296
|
{
|
|
311
297
|
maxAge: CacheTime.MINUTE * 5,
|
|
312
298
|
customKey: ({ params }) => `app:user:${params[0]}`,
|
|
313
|
-
}
|
|
299
|
+
},
|
|
314
300
|
);
|
|
315
301
|
```
|
|
316
302
|
|
|
@@ -327,30 +313,31 @@ const stats = {
|
|
|
327
313
|
hits: 0,
|
|
328
314
|
misses: 0,
|
|
329
315
|
stales: 0,
|
|
330
|
-
hitRate: () => stats.hits / stats.total
|
|
316
|
+
hitRate: () => stats.hits / stats.total,
|
|
331
317
|
};
|
|
332
318
|
|
|
333
|
-
const getUser = cache(
|
|
334
|
-
|
|
335
|
-
{
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
} else if (status === 'stale') {
|
|
346
|
-
stats.stales++;
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
console.log(`Cache ${status} for key: ${String(key)}`);
|
|
350
|
-
console.log(`Current hit rate: ${stats.hitRate() * 100}%`);
|
|
319
|
+
const getUser = cache(fetchUserData, {
|
|
320
|
+
maxAge: CacheTime.MINUTE * 5,
|
|
321
|
+
onCache({ status, key, params, result }) {
|
|
322
|
+
// status can be 'hit', 'miss', or 'stale'
|
|
323
|
+
stats.total++;
|
|
324
|
+
|
|
325
|
+
if (status === 'hit') {
|
|
326
|
+
stats.hits++;
|
|
327
|
+
} else if (status === 'miss') {
|
|
328
|
+
stats.misses++;
|
|
329
|
+
} else if (status === 'stale') {
|
|
330
|
+
stats.stales++;
|
|
351
331
|
}
|
|
352
|
-
|
|
353
|
-
|
|
332
|
+
|
|
333
|
+
console.log(
|
|
334
|
+
`Cache ${
|
|
335
|
+
status === 'hit' ? 'hit' : status === 'miss' ? 'miss' : 'stale'
|
|
336
|
+
} for key: ${String(key)}`,
|
|
337
|
+
);
|
|
338
|
+
console.log(`Current hit rate: ${stats.hitRate() * 100}%`);
|
|
339
|
+
},
|
|
340
|
+
});
|
|
354
341
|
|
|
355
342
|
// Usage example
|
|
356
343
|
await getUser(1); // Cache miss
|
|
@@ -371,6 +358,7 @@ The `onCache` callback receives an object with the following properties:
|
|
|
371
358
|
This callback is only invoked when the `options` parameter is provided. When using the cache function without options, the `onCache` callback is not called.
|
|
372
359
|
|
|
373
360
|
The `onCache` callback is useful for:
|
|
361
|
+
|
|
374
362
|
- Monitoring cache performance
|
|
375
363
|
- Calculating hit rates
|
|
376
364
|
- Logging cache operations
|
|
@@ -428,7 +416,7 @@ configureCache({
|
|
|
428
416
|
|
|
429
417
|
##### Using `customKey` to Ensure Cache Key Stability
|
|
430
418
|
|
|
431
|
-
:::
|
|
419
|
+
:::warning Important Recommendation
|
|
432
420
|
|
|
433
421
|
When using custom storage containers (such as Redis), **it's recommended to configure `customKey`** to ensure cache key stability. This ensures:
|
|
434
422
|
|
|
@@ -457,7 +445,7 @@ const getUser = cache(
|
|
|
457
445
|
maxAge: CacheTime.MINUTE * 5,
|
|
458
446
|
// Use stable identifiers related to the cached function as cache keys
|
|
459
447
|
customKey: () => `fetchUserData`,
|
|
460
|
-
}
|
|
448
|
+
},
|
|
461
449
|
);
|
|
462
450
|
```
|
|
463
451
|
|
|
@@ -477,7 +465,7 @@ class RedisContainer implements Container {
|
|
|
477
465
|
}
|
|
478
466
|
|
|
479
467
|
async get(key: string): Promise<string | null> {
|
|
480
|
-
const value = await this.
|
|
468
|
+
const value = await this.client.get(key);
|
|
481
469
|
return value ? JSON.parse(value) : null;
|
|
482
470
|
}
|
|
483
471
|
|
|
@@ -520,7 +508,7 @@ configureCache({
|
|
|
520
508
|
});
|
|
521
509
|
```
|
|
522
510
|
|
|
523
|
-
#####
|
|
511
|
+
##### Notes
|
|
524
512
|
|
|
525
513
|
1. **Serialization**: All cached data will be serialized to strings for storage. The container only needs to handle string get/set operations.
|
|
526
514
|
|