@bleedingdev/modern-js-app-tools 3.5.0-ultramodern.98 → 3.5.0-ultramodern.99
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/dist/cjs/builder/generator/createBuilderProviderConfig.js +5 -1
- package/dist/cjs/builder/generator/getBuilderEnvironments.js +7 -0
- package/dist/cjs/commands/build.js +2 -1
- package/dist/cjs/commands/deploy.js +4 -2
- package/dist/cjs/commands/index.js +0 -4
- package/dist/cjs/config/default.js +2 -0
- package/dist/cjs/index.js +56 -15
- package/dist/cjs/plugins/analyze/index.js +2 -2
- package/dist/cjs/plugins/analyze/utils.js +3 -2
- package/dist/cjs/plugins/initialize/index.js +4 -3
- package/dist/cjs/plugins/serverBuild.js +3 -2
- package/dist/esm/builder/generator/createBuilderProviderConfig.mjs +5 -1
- package/dist/esm/builder/generator/getBuilderEnvironments.mjs +7 -0
- package/dist/esm/commands/build.mjs +2 -1
- package/dist/esm/commands/deploy.mjs +4 -2
- package/dist/esm/commands/index.mjs +0 -4
- package/dist/esm/config/default.mjs +2 -0
- package/dist/esm/index.mjs +15 -1
- package/dist/esm/plugins/analyze/index.mjs +2 -2
- package/dist/esm/plugins/analyze/utils.mjs +3 -2
- package/dist/esm/plugins/initialize/index.mjs +4 -3
- package/dist/esm/plugins/serverBuild.mjs +3 -2
- package/dist/esm-node/builder/generator/createBuilderProviderConfig.mjs +5 -1
- package/dist/esm-node/builder/generator/getBuilderEnvironments.mjs +7 -0
- package/dist/esm-node/commands/build.mjs +2 -1
- package/dist/esm-node/commands/deploy.mjs +4 -2
- package/dist/esm-node/commands/index.mjs +0 -4
- package/dist/esm-node/config/default.mjs +2 -0
- package/dist/esm-node/index.mjs +15 -1
- package/dist/esm-node/plugins/analyze/index.mjs +2 -2
- package/dist/esm-node/plugins/analyze/utils.mjs +3 -2
- package/dist/esm-node/plugins/initialize/index.mjs +4 -3
- package/dist/esm-node/plugins/serverBuild.mjs +3 -2
- package/dist/types/commands/deploy.d.ts +2 -1
- package/dist/types/index.d.ts +4 -1
- package/dist/types/plugins/analyze/utils.d.ts +1 -1
- package/dist/types/types/config/dev.d.ts +6 -0
- package/docs/_nav.json +36 -0
- package/docs/apis/_meta.json +13 -0
- package/docs/apis/app/commands.mdx +205 -0
- package/docs/apis/app/hooks/_meta.json +28 -0
- package/docs/apis/app/hooks/api/lambda.mdx +13 -0
- package/docs/apis/app/hooks/config/_meta.json +1 -0
- package/docs/apis/app/hooks/config/favicon.mdx +29 -0
- package/docs/apis/app/hooks/config/html.mdx +9 -0
- package/docs/apis/app/hooks/config/icon.mdx +29 -0
- package/docs/apis/app/hooks/config/mock.mdx +10 -0
- package/docs/apis/app/hooks/config/public.mdx +30 -0
- package/docs/apis/app/hooks/config/upload.mdx +54 -0
- package/docs/apis/app/hooks/modern-config.mdx +9 -0
- package/docs/apis/app/hooks/server/server.mdx +10 -0
- package/docs/apis/app/hooks/shared.mdx +7 -0
- package/docs/apis/app/hooks/src/app.mdx +30 -0
- package/docs/apis/app/hooks/src/entry.mdx +39 -0
- package/docs/apis/app/hooks/src/entry.server.mdx +56 -0
- package/docs/apis/app/hooks/src/modern.runtime.mdx +9 -0
- package/docs/apis/app/hooks/src/routes.mdx +90 -0
- package/docs/apis/app/hooks/src/server.mdx +7 -0
- package/docs/apis/app/runtime/_meta.json +32 -0
- package/docs/apis/app/runtime/bff/use-backend-context.mdx +30 -0
- package/docs/apis/app/runtime/core/create-root.mdx +22 -0
- package/docs/apis/app/runtime/core/render.mdx +42 -0
- package/docs/apis/app/runtime/core/runtime-context.mdx +160 -0
- package/docs/apis/app/runtime/router/router.mdx +288 -0
- package/docs/apis/app/runtime/ssr/no-ssr.mdx +38 -0
- package/docs/apis/app/runtime/ssr/renderStreaming.mdx +71 -0
- package/docs/apis/app/runtime/ssr/renderString.mdx +64 -0
- package/docs/apis/app/runtime/ssr/requestHandler.mdx +48 -0
- package/docs/apis/app/runtime/utility/css-in-js.mdx +44 -0
- package/docs/apis/app/runtime/utility/head.mdx +38 -0
- package/docs/apis/app/runtime/utility/loadable.mdx +85 -0
- package/docs/components/auto-upgrade.mdx +0 -0
- package/docs/components/bff-upload.mdx +97 -0
- package/docs/components/build-output.mdx +45 -0
- package/docs/components/bundler.mdx +3 -0
- package/docs/components/convention-routing-motivation.mdx +0 -0
- package/docs/components/debug-app.mdx +15 -0
- package/docs/components/default-browserslist.mdx +7 -0
- package/docs/components/deploy-command.mdx +14 -0
- package/docs/components/deploy.mdx +1 -0
- package/docs/components/enable-bff-caution.mdx +3 -0
- package/docs/components/enable-bff.mdx +56 -0
- package/docs/components/enable-ssg.mdx +49 -0
- package/docs/components/entry-mode.mdx +0 -0
- package/docs/components/entry-scan-logic.mdx +7 -0
- package/docs/components/extend-bff-function.mdx +3 -0
- package/docs/components/hono.mdx +120 -0
- package/docs/components/init-app.mdx +93 -0
- package/docs/components/init-rspack-app.mdx +5 -0
- package/docs/components/internal-logger.mdx +25 -0
- package/docs/components/internal-metrics.mdx +20 -0
- package/docs/components/international/custom-instance-code.mdx +16 -0
- package/docs/components/international/init-options-desc.mdx +1 -0
- package/docs/components/international/install-command.mdx +10 -0
- package/docs/components/international/instance-code.mdx +16 -0
- package/docs/components/international/introduce.mdx +5 -0
- package/docs/components/international/platform-support.mdx +0 -0
- package/docs/components/language-config.mdx +9 -0
- package/docs/components/micro-frontend.mdx +6 -0
- package/docs/components/micro-master-manifest-config.mdx +15 -0
- package/docs/components/micro-runtime-config.mdx +17 -0
- package/docs/components/module-federation.mdx +7 -0
- package/docs/components/new-entry-tooltip.mdx +0 -0
- package/docs/components/nodeVersion.mdx +28 -0
- package/docs/components/other-plugins.mdx +0 -0
- package/docs/components/output-asset-prefix-extend.mdx +0 -0
- package/docs/components/output-distpath-warning.mdx +0 -0
- package/docs/components/output-polyfill-extend.mdx +1 -0
- package/docs/components/prerequisites.mdx +18 -0
- package/docs/components/release-note.mdx +1 -0
- package/docs/components/routes-practice.mdx +0 -0
- package/docs/components/rsbuild-config-tooltip.mdx +5 -0
- package/docs/components/rsbuild.mdx +3 -0
- package/docs/components/rsc-deploy-tip.mdx +1 -0
- package/docs/components/rspack.mdx +3 -0
- package/docs/components/rspackTip.mdx +7 -0
- package/docs/components/runtime-cli-config.mdx +0 -0
- package/docs/components/serve-command.mdx +22 -0
- package/docs/components/ssr-monitor.mdx +3 -0
- package/docs/components/stream-ssr-performance.mdx +0 -0
- package/docs/components/swc.mdx +3 -0
- package/docs/components/tech-stack-node-framework.mdx +1 -0
- package/docs/components/turtorials-example-list.mdx +2 -0
- package/docs/components/ua-polyfill.mdx +44 -0
- package/docs/components/upgrade-browserslist.mdx +0 -0
- package/docs/components/upgrade-config-deploy.mdx +0 -0
- package/docs/components/upgrade-faq.mdx +0 -0
- package/docs/configure/_meta.json +78 -0
- package/docs/configure/app/bff/cross-project.mdx +24 -0
- package/docs/configure/app/bff/effect.mdx +319 -0
- package/docs/configure/app/bff/prefix.mdx +33 -0
- package/docs/configure/app/bff/runtime-framework.mdx +30 -0
- package/docs/configure/app/builder-plugins.mdx +70 -0
- package/docs/configure/app/dev/asset-prefix.mdx +18 -0
- package/docs/configure/app/dev/before-start-url.mdx +21 -0
- package/docs/configure/app/dev/client.mdx +45 -0
- package/docs/configure/app/dev/hmr.mdx +14 -0
- package/docs/configure/app/dev/host.mdx +22 -0
- package/docs/configure/app/dev/https.mdx +81 -0
- package/docs/configure/app/dev/lazy-compilation.mdx +45 -0
- package/docs/configure/app/dev/live-reload.mdx +14 -0
- package/docs/configure/app/dev/mock-dir.mdx +35 -0
- package/docs/configure/app/dev/progress-bar.mdx +23 -0
- package/docs/configure/app/dev/server.mdx +128 -0
- package/docs/configure/app/dev/setup-middlewares.mdx +36 -0
- package/docs/configure/app/dev/start-url.mdx +53 -0
- package/docs/configure/app/dev/watch-files.mdx +31 -0
- package/docs/configure/app/dev/write-to-disk.mdx +14 -0
- package/docs/configure/app/experiments/source-build.mdx +33 -0
- package/docs/configure/app/html/app-icon.mdx +32 -0
- package/docs/configure/app/html/crossorigin.mdx +14 -0
- package/docs/configure/app/html/favicon.mdx +20 -0
- package/docs/configure/app/html/inject.mdx +14 -0
- package/docs/configure/app/html/meta.mdx +28 -0
- package/docs/configure/app/html/mount-id.mdx +14 -0
- package/docs/configure/app/html/output-structure.mdx +14 -0
- package/docs/configure/app/html/script-loading.mdx +14 -0
- package/docs/configure/app/html/tags.mdx +19 -0
- package/docs/configure/app/html/template-parameters.mdx +37 -0
- package/docs/configure/app/html/template.mdx +14 -0
- package/docs/configure/app/html/title.mdx +22 -0
- package/docs/configure/app/output/asset-prefix.mdx +18 -0
- package/docs/configure/app/output/assets-retry.mdx +81 -0
- package/docs/configure/app/output/charset.mdx +14 -0
- package/docs/configure/app/output/clean-dist-path.mdx +20 -0
- package/docs/configure/app/output/convert-to-rem.mdx +83 -0
- package/docs/configure/app/output/copy.mdx +14 -0
- package/docs/configure/app/output/css-modules.mdx +52 -0
- package/docs/configure/app/output/data-uri-limit.mdx +30 -0
- package/docs/configure/app/output/disable-css-module-extension.mdx +59 -0
- package/docs/configure/app/output/disable-inline-runtime-chunk.mdx +45 -0
- package/docs/configure/app/output/disable-svgr.mdx +22 -0
- package/docs/configure/app/output/disable-ts-checker.mdx +53 -0
- package/docs/configure/app/output/dist-path.mdx +51 -0
- package/docs/configure/app/output/enable-asset-manifest.mdx +40 -0
- package/docs/configure/app/output/enable-css-module-tsdeclaration.mdx +32 -0
- package/docs/configure/app/output/enable-inline-route-manifests.mdx +20 -0
- package/docs/configure/app/output/externals.mdx +24 -0
- package/docs/configure/app/output/filename-hash.mdx +14 -0
- package/docs/configure/app/output/filename.mdx +59 -0
- package/docs/configure/app/output/inject-styles.mdx +14 -0
- package/docs/configure/app/output/inline-scripts.mdx +33 -0
- package/docs/configure/app/output/inline-styles.mdx +33 -0
- package/docs/configure/app/output/legal-comments.mdx +22 -0
- package/docs/configure/app/output/minify.mdx +26 -0
- package/docs/configure/app/output/override-browserslist.mdx +26 -0
- package/docs/configure/app/output/polyfill.mdx +18 -0
- package/docs/configure/app/output/source-map.mdx +34 -0
- package/docs/configure/app/output/split-route-chunks.mdx +20 -0
- package/docs/configure/app/output/ssg.mdx +85 -0
- package/docs/configure/app/output/ssgByEntries.mdx +93 -0
- package/docs/configure/app/output/svg-default-export.mdx +34 -0
- package/docs/configure/app/output/temp-dir.mdx +24 -0
- package/docs/configure/app/performance/build-cache.mdx +48 -0
- package/docs/configure/app/performance/chunk-split.mdx +44 -0
- package/docs/configure/app/performance/dns-prefetch.mdx +19 -0
- package/docs/configure/app/performance/preconnect.mdx +20 -0
- package/docs/configure/app/performance/prefetch.mdx +25 -0
- package/docs/configure/app/performance/preload.mdx +27 -0
- package/docs/configure/app/performance/print-file-size.mdx +44 -0
- package/docs/configure/app/performance/profile.mdx +14 -0
- package/docs/configure/app/performance/remove-console.mdx +14 -0
- package/docs/configure/app/performance/remove-moment-locale.mdx +14 -0
- package/docs/configure/app/performance/rsdoctor.mdx +42 -0
- package/docs/configure/app/plugins.mdx +59 -0
- package/docs/configure/app/resolve/alias-strategy.mdx +14 -0
- package/docs/configure/app/resolve/alias.mdx +13 -0
- package/docs/configure/app/resolve/condition-names.mdx +18 -0
- package/docs/configure/app/resolve/dedupe.mdx +13 -0
- package/docs/configure/app/resolve/extensions.mdx +18 -0
- package/docs/configure/app/runtime/0-intro.mdx +61 -0
- package/docs/configure/app/runtime/plugins.mdx +58 -0
- package/docs/configure/app/runtime/router.mdx +39 -0
- package/docs/configure/app/security/check-syntax.mdx +73 -0
- package/docs/configure/app/security/nonce.mdx +19 -0
- package/docs/configure/app/security/sri.mdx +24 -0
- package/docs/configure/app/server/base-url.mdx +30 -0
- package/docs/configure/app/server/port.mdx +22 -0
- package/docs/configure/app/server/public-routes.mdx +26 -0
- package/docs/configure/app/server/routes.mdx +90 -0
- package/docs/configure/app/server/rsc.mdx +30 -0
- package/docs/configure/app/server/ssr-by-entries.mdx +29 -0
- package/docs/configure/app/server/ssr.mdx +85 -0
- package/docs/configure/app/server/tsconfig-path.mdx +63 -0
- package/docs/configure/app/source/alias-strategy.mdx +18 -0
- package/docs/configure/app/source/alias.mdx +27 -0
- package/docs/configure/app/source/config-dir.mdx +24 -0
- package/docs/configure/app/source/decorators.mdx +29 -0
- package/docs/configure/app/source/define.mdx +20 -0
- package/docs/configure/app/source/disable-default-entries.mdx +32 -0
- package/docs/configure/app/source/enable-async-entry.mdx +54 -0
- package/docs/configure/app/source/enable-async-pre-entry.mdx +30 -0
- package/docs/configure/app/source/entries-dir.mdx +39 -0
- package/docs/configure/app/source/entries.mdx +183 -0
- package/docs/configure/app/source/exclude.mdx +14 -0
- package/docs/configure/app/source/global-vars.mdx +110 -0
- package/docs/configure/app/source/include.mdx +40 -0
- package/docs/configure/app/source/main-entry-name.mdx +28 -0
- package/docs/configure/app/source/pre-entry.mdx +14 -0
- package/docs/configure/app/source/react-compiler.mdx +72 -0
- package/docs/configure/app/source/transform-import.mdx +31 -0
- package/docs/configure/app/split-chunks.mdx +17 -0
- package/docs/configure/app/tools/autoprefixer.mdx +48 -0
- package/docs/configure/app/tools/bundler-chain.mdx +30 -0
- package/docs/configure/app/tools/css-extract.mdx +37 -0
- package/docs/configure/app/tools/css-loader.mdx +21 -0
- package/docs/configure/app/tools/dev-server.mdx +117 -0
- package/docs/configure/app/tools/html-plugin.mdx +45 -0
- package/docs/configure/app/tools/less.mdx +85 -0
- package/docs/configure/app/tools/lightningcss-loader.mdx +39 -0
- package/docs/configure/app/tools/minify-css.mdx +57 -0
- package/docs/configure/app/tools/postcss.mdx +38 -0
- package/docs/configure/app/tools/rspack.mdx +14 -0
- package/docs/configure/app/tools/sass.mdx +82 -0
- package/docs/configure/app/tools/style-loader.mdx +14 -0
- package/docs/configure/app/tools/swc.mdx +69 -0
- package/docs/configure/app/tools/ts-checker.mdx +103 -0
- package/docs/configure/app/usage.mdx +276 -0
- package/docs/guides/_meta.json +37 -0
- package/docs/guides/advanced-features/_meta.json +32 -0
- package/docs/guides/advanced-features/bff/_meta.json +10 -0
- package/docs/guides/advanced-features/bff/cross-project.mdx +110 -0
- package/docs/guides/advanced-features/bff/data-platform.mdx +120 -0
- package/docs/guides/advanced-features/bff/extend-server.mdx +120 -0
- package/docs/guides/advanced-features/bff/frameworks.mdx +131 -0
- package/docs/guides/advanced-features/bff/function.mdx +265 -0
- package/docs/guides/advanced-features/bff/operators.mdx +629 -0
- package/docs/guides/advanced-features/bff/sdk.mdx +116 -0
- package/docs/guides/advanced-features/bff/upload.mdx +7 -0
- package/docs/guides/advanced-features/bff.mdx +22 -0
- package/docs/guides/advanced-features/build-performance.mdx +134 -0
- package/docs/guides/advanced-features/compatibility.mdx +81 -0
- package/docs/guides/advanced-features/international/_meta.json +10 -0
- package/docs/guides/advanced-features/international/advanced.mdx +132 -0
- package/docs/guides/advanced-features/international/api.mdx +271 -0
- package/docs/guides/advanced-features/international/best-practices.mdx +290 -0
- package/docs/guides/advanced-features/international/configuration.mdx +222 -0
- package/docs/guides/advanced-features/international/locale-detection.mdx +130 -0
- package/docs/guides/advanced-features/international/quick-start.mdx +112 -0
- package/docs/guides/advanced-features/international/resource-loading.mdx +158 -0
- package/docs/guides/advanced-features/international/routing.mdx +177 -0
- package/docs/guides/advanced-features/international.mdx +29 -0
- package/docs/guides/advanced-features/low-level.mdx +50 -0
- package/docs/guides/advanced-features/page-performance/_meta.json +1 -0
- package/docs/guides/advanced-features/page-performance/code-split.mdx +81 -0
- package/docs/guides/advanced-features/page-performance/inline-assets.mdx +163 -0
- package/docs/guides/advanced-features/page-performance/optimize-bundle.mdx +101 -0
- package/docs/guides/advanced-features/page-performance/react-compiler.mdx +51 -0
- package/docs/guides/advanced-features/server-monitor/_meta.json +1 -0
- package/docs/guides/advanced-features/server-monitor/logger.mdx +19 -0
- package/docs/guides/advanced-features/server-monitor/metrics.mdx +41 -0
- package/docs/guides/advanced-features/server-monitor/monitors.mdx +242 -0
- package/docs/guides/advanced-features/source-build.mdx +168 -0
- package/docs/guides/advanced-features/web-server.mdx +296 -0
- package/docs/guides/basic-features/_meta.json +49 -0
- package/docs/guides/basic-features/alias.mdx +106 -0
- package/docs/guides/basic-features/css/_meta.json +1 -0
- package/docs/guides/basic-features/css/css-in-js.mdx +69 -0
- package/docs/guides/basic-features/css/css-modules.mdx +212 -0
- package/docs/guides/basic-features/css/css.mdx +31 -0
- package/docs/guides/basic-features/css/tailwindcss.mdx +27 -0
- package/docs/guides/basic-features/data/_meta.json +1 -0
- package/docs/guides/basic-features/data/data-cache.mdx +515 -0
- package/docs/guides/basic-features/data/data-fetch.mdx +419 -0
- package/docs/guides/basic-features/data/data-write.mdx +230 -0
- package/docs/guides/basic-features/debug/_meta.json +1 -0
- package/docs/guides/basic-features/debug/mock.mdx +113 -0
- package/docs/guides/basic-features/debug/proxy.mdx +25 -0
- package/docs/guides/basic-features/debug/rsdoctor.mdx +47 -0
- package/docs/guides/basic-features/debug/using-storybook.mdx +100 -0
- package/docs/guides/basic-features/deploy.mdx +448 -0
- package/docs/guides/basic-features/env-vars.mdx +181 -0
- package/docs/guides/basic-features/html.mdx +259 -0
- package/docs/guides/basic-features/output-files.mdx +145 -0
- package/docs/guides/basic-features/render/_meta.json +1 -0
- package/docs/guides/basic-features/render/before-render.mdx +108 -0
- package/docs/guides/basic-features/render/overview.mdx +51 -0
- package/docs/guides/basic-features/render/rsc.mdx +533 -0
- package/docs/guides/basic-features/render/ssg.mdx +167 -0
- package/docs/guides/basic-features/render/ssr-cache.mdx +201 -0
- package/docs/guides/basic-features/render/ssr.mdx +323 -0
- package/docs/guides/basic-features/render/streaming-ssr.mdx +267 -0
- package/docs/guides/basic-features/routes/_meta.json +1 -0
- package/docs/guides/basic-features/routes/config-routes.mdx +427 -0
- package/docs/guides/basic-features/routes/routes.mdx +532 -0
- package/docs/guides/basic-features/static-assets/_meta.json +1 -0
- package/docs/guides/basic-features/static-assets/json-files.mdx +124 -0
- package/docs/guides/basic-features/static-assets/svg-assets.mdx +172 -0
- package/docs/guides/basic-features/static-assets/wasm-assets.mdx +66 -0
- package/docs/guides/basic-features/static-assets.mdx +164 -0
- package/docs/guides/basic-features/testing/_meta.json +1 -0
- package/docs/guides/basic-features/testing/playwright.mdx +111 -0
- package/docs/guides/basic-features/testing/rstest.mdx +192 -0
- package/docs/guides/concept/_meta.json +1 -0
- package/docs/guides/concept/builder.mdx +60 -0
- package/docs/guides/concept/entries.mdx +325 -0
- package/docs/guides/concept/server.mdx +35 -0
- package/docs/guides/get-started/_meta.json +9 -0
- package/docs/guides/get-started/ai-coding-agents.mdx +63 -0
- package/docs/guides/get-started/glossary.mdx +63 -0
- package/docs/guides/get-started/introduction.mdx +45 -0
- package/docs/guides/get-started/quick-start.mdx +92 -0
- package/docs/guides/get-started/tech-stack.mdx +97 -0
- package/docs/guides/get-started/ultramodern.mdx +433 -0
- package/docs/guides/get-started/upgrade.mdx +114 -0
- package/docs/guides/topic-detail/_meta.json +8 -0
- package/docs/guides/topic-detail/module-federation/_meta.json +1 -0
- package/docs/guides/topic-detail/module-federation/application.mdx +116 -0
- package/docs/guides/topic-detail/module-federation/deploy.mdx +104 -0
- package/docs/guides/topic-detail/module-federation/i18n.mdx +670 -0
- package/docs/guides/topic-detail/module-federation/introduce.mdx +36 -0
- package/docs/guides/topic-detail/module-federation/ssr.mdx +177 -0
- package/docs/guides/topic-detail/module-federation/usage.mdx +202 -0
- package/docs/guides/troubleshooting/_meta.json +1 -0
- package/docs/guides/troubleshooting/builder.mdx +114 -0
- package/docs/guides/troubleshooting/cli.mdx +39 -0
- package/docs/guides/troubleshooting/dependencies.mdx +123 -0
- package/docs/guides/troubleshooting/hmr.mdx +148 -0
- package/docs/guides/upgrade/_meta.json +1 -0
- package/docs/guides/upgrade/config.mdx +951 -0
- package/docs/guides/upgrade/entry.mdx +463 -0
- package/docs/guides/upgrade/other.mdx +183 -0
- package/docs/guides/upgrade/overview.mdx +33 -0
- package/docs/guides/upgrade/tailwindcss.mdx +92 -0
- package/docs/guides/upgrade/web-server.md +109 -0
- package/docs/index.md +4 -0
- package/package.json +43 -20
- package/scripts/copy-main-doc.mjs +50 -0
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 16
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Custom Web Server
|
|
6
|
+
|
|
7
|
+
Modern.js encapsulates most server-side capabilities required by projects, typically eliminating the need for server-side development. However, in certain scenarios such as user authentication, request preprocessing, or adding page skeletons, custom server-side logic may still be necessary.
|
|
8
|
+
|
|
9
|
+
To use the Custom Web Server in a Modern.js project, follow these steps:
|
|
10
|
+
|
|
11
|
+
1. Install `@modern-js/server-runtime` dependency
|
|
12
|
+
|
|
13
|
+
If the `@modern-js/server-runtime` dependency is not yet installed in your project, install it first:
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
pnpm add @modern-js/server-runtime
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
:::tip Version Consistency
|
|
20
|
+
Make sure the version of `@modern-js/server-runtime` matches the version of `@modern-js/app-tools` in your project. All Modern.js official packages are released with a uniform version number, and version mismatches may cause compatibility issues.
|
|
21
|
+
|
|
22
|
+
Check the version of `@modern-js/app-tools` first, then install the same version of `@modern-js/server-runtime`:
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
# Check the current version of @modern-js/app-tools
|
|
26
|
+
pnpm list @modern-js/app-tools
|
|
27
|
+
|
|
28
|
+
# Install the same version of @modern-js/server-runtime
|
|
29
|
+
pnpm add @modern-js/server-runtime@<version>
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
:::
|
|
33
|
+
|
|
34
|
+
2. Create the `server` directory and configuration file
|
|
35
|
+
|
|
36
|
+
Create a `server/modern.server.ts` file in the project root directory:
|
|
37
|
+
|
|
38
|
+
```ts title="server/modern.server.ts"
|
|
39
|
+
import { defineServerConfig } from '@modern-js/server-runtime';
|
|
40
|
+
|
|
41
|
+
export default defineServerConfig({
|
|
42
|
+
middlewares: [], // Middleware
|
|
43
|
+
renderMiddlewares: [], // Render Middleware
|
|
44
|
+
plugins: [], // Plugins
|
|
45
|
+
onError: () => {}, // Error handling
|
|
46
|
+
});
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
After creating the file, you can write custom logic in this file.
|
|
50
|
+
|
|
51
|
+
3. Include `server` directory in `tsconfig.json`
|
|
52
|
+
|
|
53
|
+
```json5
|
|
54
|
+
{
|
|
55
|
+
// ...
|
|
56
|
+
"include": [
|
|
57
|
+
// ...
|
|
58
|
+
"server"
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## Capabilities of the Custom Web Server
|
|
64
|
+
|
|
65
|
+
Modern.js's Web Server is based on Hono, and in the latest version of the Custom Web Server, we expose Hono's middleware capabilities, you can refer to [Hono API](https://hono.dev/docs/api/context) for more usage.
|
|
66
|
+
|
|
67
|
+
In the `server/modern.server.ts` file, you can add the following configurations to extend the Server:
|
|
68
|
+
|
|
69
|
+
- **Middleware**
|
|
70
|
+
- **Render Middleware**
|
|
71
|
+
- **Server-side Plugin**
|
|
72
|
+
|
|
73
|
+
In the **Plugin**, you can define **Middleware** and **RenderMiddleware**. The middleware loading process is illustrated in the following diagram:
|
|
74
|
+
|
|
75
|
+
<img
|
|
76
|
+
src="https://lf3-static.bytednsdoc.com/obj/eden-cn/10eh7nuhpenuhog/server-md-wf.png"
|
|
77
|
+
style={{ width: '100%', maxWidth: '540px' }}
|
|
78
|
+
/>
|
|
79
|
+
|
|
80
|
+
### Basic Configuration
|
|
81
|
+
|
|
82
|
+
```ts title="server/modern.server.ts"
|
|
83
|
+
import { defineServerConfig } from '@modern-js/server-runtime';
|
|
84
|
+
|
|
85
|
+
export default defineServerConfig({
|
|
86
|
+
middlewares: [],
|
|
87
|
+
renderMiddlewares: [],
|
|
88
|
+
plugins: [],
|
|
89
|
+
onError: () => {},
|
|
90
|
+
});
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
### Type Definition
|
|
94
|
+
|
|
95
|
+
`defineServerConfig` type definition is as follows:
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import type { MiddlewareHandler } from 'hono';
|
|
99
|
+
|
|
100
|
+
type MiddlewareOrder = 'pre' | 'post' | 'default';
|
|
101
|
+
type MiddlewareObj = {
|
|
102
|
+
name: string;
|
|
103
|
+
path?: string;
|
|
104
|
+
method?: 'options' | 'get' | 'post' | 'put' | 'delete' | 'patch' | 'all';
|
|
105
|
+
handler: MiddlewareHandler | MiddlewareHandler[];
|
|
106
|
+
before?: Array<MiddlewareObj['name']>;
|
|
107
|
+
order?: MiddlewareOrder;
|
|
108
|
+
};
|
|
109
|
+
type ServerConfig = {
|
|
110
|
+
middlewares?: MiddlewareObj[];
|
|
111
|
+
renderMiddlewares?: MiddlewareObj[];
|
|
112
|
+
plugins?: ServerPlugin[];
|
|
113
|
+
onError?: (err: Error, c: Context) => Promise<any> | any;
|
|
114
|
+
};
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
### Middleware
|
|
118
|
+
|
|
119
|
+
Middleware supports executing custom logic before and after the **request handling** and **page routing** processes in Modern.js services.
|
|
120
|
+
If custom logic needs to handle both API routes and page routes, Middleware is the clear choice.
|
|
121
|
+
|
|
122
|
+
:::note
|
|
123
|
+
If you only need to handle BFF API routes, you can determine whether a request is for a BFF API by checking if `req.path` starts with the BFF `prefix`.
|
|
124
|
+
:::
|
|
125
|
+
|
|
126
|
+
Usage is as follows:
|
|
127
|
+
|
|
128
|
+
```ts title="server/modern.server.ts"
|
|
129
|
+
import {
|
|
130
|
+
defineServerConfig,
|
|
131
|
+
type MiddlewareHandler,
|
|
132
|
+
} from '@modern-js/server-runtime';
|
|
133
|
+
|
|
134
|
+
export const handler: MiddlewareHandler = async (c, next) => {
|
|
135
|
+
const monitors = c.get('monitors');
|
|
136
|
+
const start = Date.now();
|
|
137
|
+
|
|
138
|
+
await next();
|
|
139
|
+
|
|
140
|
+
const end = Date.now();
|
|
141
|
+
// Report Duration
|
|
142
|
+
monitors.timing('request_timing', end - start);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
export default defineServerConfig({
|
|
146
|
+
middlewares: [
|
|
147
|
+
{
|
|
148
|
+
name: 'request-timing',
|
|
149
|
+
handler,
|
|
150
|
+
},
|
|
151
|
+
],
|
|
152
|
+
});
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
:::warning
|
|
156
|
+
You must execute the `next` function to proceed with the subsequent Middleware.
|
|
157
|
+
:::
|
|
158
|
+
|
|
159
|
+
### RenderMiddleware
|
|
160
|
+
|
|
161
|
+
If you only need to handle the logic before and after page rendering, modern.js also provides rendering middleware, which can be used as follows:
|
|
162
|
+
|
|
163
|
+
```ts title="server/modern.server.ts"
|
|
164
|
+
import {
|
|
165
|
+
defineServerConfig,
|
|
166
|
+
type MiddlewareHandler,
|
|
167
|
+
} from '@modern-js/server-runtime';
|
|
168
|
+
|
|
169
|
+
// Inject render performance metrics
|
|
170
|
+
const renderTiming: MiddlewareHandler = async (c, next) => {
|
|
171
|
+
const start = Date.now();
|
|
172
|
+
|
|
173
|
+
await next();
|
|
174
|
+
|
|
175
|
+
const end = Date.now();
|
|
176
|
+
c.res.headers.set('server-timing', `render; dur=${end - start}`);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
// Modify the Response Body
|
|
180
|
+
const modifyResBody: MiddlewareHandler = async (c, next) => {
|
|
181
|
+
await next();
|
|
182
|
+
|
|
183
|
+
const { res } = c;
|
|
184
|
+
const text = await res.text();
|
|
185
|
+
const newText = text.replace('<body>', '<body> <h3>bytedance</h3>');
|
|
186
|
+
|
|
187
|
+
c.res = c.body(newText, {
|
|
188
|
+
status: res.status,
|
|
189
|
+
headers: res.headers,
|
|
190
|
+
});
|
|
191
|
+
};
|
|
192
|
+
|
|
193
|
+
export default defineServerConfig({
|
|
194
|
+
renderMiddlewares: [
|
|
195
|
+
{
|
|
196
|
+
name: 'render-timing',
|
|
197
|
+
handler: renderTiming,
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: 'modify-res-body',
|
|
201
|
+
handler: modifyResBody,
|
|
202
|
+
},
|
|
203
|
+
],
|
|
204
|
+
});
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Plugin
|
|
208
|
+
|
|
209
|
+
Modern.js supports adding the aforementioned middleware and rendering middleware for the Server in custom plugins, which can be used as follows:
|
|
210
|
+
|
|
211
|
+
```ts title="server/plugins/server.ts"
|
|
212
|
+
import type { ServerPlugin } from '@modern-js/server-runtime';
|
|
213
|
+
|
|
214
|
+
export default (): ServerPlugin => ({
|
|
215
|
+
name: 'serverPlugin',
|
|
216
|
+
setup(api) {
|
|
217
|
+
api.onPrepare(() => {
|
|
218
|
+
const { middlewares, renderMiddlewares } = api.getServerContext();
|
|
219
|
+
|
|
220
|
+
// Inject server-side data for page dataLoader consumption
|
|
221
|
+
middlewares?.push({
|
|
222
|
+
name: 'server-plugin-middleware',
|
|
223
|
+
handler: async (c, next) => {
|
|
224
|
+
c.set('message', 'hi modern.js');
|
|
225
|
+
await next();
|
|
226
|
+
// ...
|
|
227
|
+
},
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// redirect
|
|
231
|
+
renderMiddlewares?.push({
|
|
232
|
+
name: 'server-plugin-render-middleware',
|
|
233
|
+
handler: async (c, next) => {
|
|
234
|
+
const user = getUser(c.req);
|
|
235
|
+
if (!user) {
|
|
236
|
+
return c.redirect('/login');
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
await next();
|
|
240
|
+
},
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
},
|
|
244
|
+
});
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
```ts title="server/modern.server.ts"
|
|
248
|
+
import { defineServerConfig } from '@modern-js/server-runtime';
|
|
249
|
+
import serverPlugin from './plugins/serverPlugin';
|
|
250
|
+
|
|
251
|
+
export default defineServerConfig({
|
|
252
|
+
plugins: [serverPlugin()],
|
|
253
|
+
});
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
```ts title="src/routes/page.data.ts"
|
|
257
|
+
import { useHonoContext } from '@modern-js/server-runtime';
|
|
258
|
+
import { defer } from '@modern-js/runtime/router';
|
|
259
|
+
|
|
260
|
+
export default () => {
|
|
261
|
+
const ctx = useHonoContext();
|
|
262
|
+
// SSR scenario consumes data injected by the Server Side
|
|
263
|
+
const message = ctx.get('message');
|
|
264
|
+
|
|
265
|
+
// ...
|
|
266
|
+
};
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
### onError
|
|
270
|
+
|
|
271
|
+
`onError` is a global error handling function used to capture and handle all uncaught errors in the Modern.js server. By customizing the `onError` function, developers can uniformly handle different types of errors, return custom error responses, and implement features such as error logging and error classification.
|
|
272
|
+
|
|
273
|
+
Below is a basic example of an `onError` configuration:
|
|
274
|
+
|
|
275
|
+
```ts title="server/modern.server.ts"
|
|
276
|
+
import { defineServerConfig } from '@modern-js/server-runtime';
|
|
277
|
+
|
|
278
|
+
export default defineServerConfig({
|
|
279
|
+
onError: (err, c) => {
|
|
280
|
+
// Log the error
|
|
281
|
+
console.error('Server error:', err);
|
|
282
|
+
|
|
283
|
+
// Return different responses based on the error type
|
|
284
|
+
if (err instanceof SyntaxError) {
|
|
285
|
+
return c.json({ error: 'Invalid JSON' }, 400);
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
// Customize BFF error response based on request path
|
|
289
|
+
if (c.req.path.includes('/api')) {
|
|
290
|
+
return c.json({ message: 'API error occurred' }, 500);
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
return c.text('Internal Server Error', 500);
|
|
294
|
+
},
|
|
295
|
+
});
|
|
296
|
+
```
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[
|
|
2
|
+
{
|
|
3
|
+
"type": "dir",
|
|
4
|
+
"name": "routes",
|
|
5
|
+
"label": "Routes",
|
|
6
|
+
"collapsed": true
|
|
7
|
+
},
|
|
8
|
+
{
|
|
9
|
+
"type": "dir",
|
|
10
|
+
"name": "data",
|
|
11
|
+
"label": "data-solution",
|
|
12
|
+
"collapsed": true
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
"type": "dir",
|
|
16
|
+
"name": "render",
|
|
17
|
+
"label": "rendering",
|
|
18
|
+
"collapsed": true
|
|
19
|
+
},
|
|
20
|
+
{
|
|
21
|
+
"type": "dir",
|
|
22
|
+
"name": "css",
|
|
23
|
+
"label": "css-solution",
|
|
24
|
+
"collapsed": true
|
|
25
|
+
},
|
|
26
|
+
"html",
|
|
27
|
+
{
|
|
28
|
+
"type": "dir",
|
|
29
|
+
"name": "static-assets",
|
|
30
|
+
"label": "static-assets",
|
|
31
|
+
"collapsed": true
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"type": "dir",
|
|
35
|
+
"name": "debug",
|
|
36
|
+
"label": "debug",
|
|
37
|
+
"collapsed": true
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
"type": "dir",
|
|
41
|
+
"name": "testing",
|
|
42
|
+
"label": "testing",
|
|
43
|
+
"collapsed": true
|
|
44
|
+
},
|
|
45
|
+
"alias",
|
|
46
|
+
"env-vars",
|
|
47
|
+
"output-files",
|
|
48
|
+
"deploy"
|
|
49
|
+
]
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
---
|
|
2
|
+
sidebar_position: 4
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# Path Alias
|
|
6
|
+
|
|
7
|
+
Path aliases allow developers to define aliases for modules, making it easier to reference them in code. This can be useful when you want to use a short, easy-to-remember name for a module instead of a long, complex path.
|
|
8
|
+
|
|
9
|
+
For example, if you frequently reference the `src/common/request.ts` module in your project, you can define an alias for it as `@request` and then use `import request from '@request'` in your code instead of writing the full relative path every time. This also allows you to move the module to a different location without needing to update all the import statements in your code.
|
|
10
|
+
|
|
11
|
+
In Modern.js, there are two ways to set up path aliases:
|
|
12
|
+
|
|
13
|
+
- Through the `paths` configuration in `tsconfig.json`.
|
|
14
|
+
- Through the [source.alias](/configure/app/source/alias) configuration.
|
|
15
|
+
|
|
16
|
+
## Using `tsconfig.json`'s `paths` Configuration
|
|
17
|
+
|
|
18
|
+
You can configure aliases through the `paths` configuration in `tsconfig.json`, which is the recommended approach in TypeScript projects as it also resolves the TS type issues related to path aliases.
|
|
19
|
+
|
|
20
|
+
For example:
|
|
21
|
+
|
|
22
|
+
```json title="tsconfig.json"
|
|
23
|
+
{
|
|
24
|
+
"compilerOptions": {
|
|
25
|
+
"paths": {
|
|
26
|
+
"@common/*": ["./src/common/*"]
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
After configuring, if you reference `@common/Foo.tsx` in your code, it will be mapped to the `<project>/src/common/Foo.tsx` path.
|
|
33
|
+
|
|
34
|
+
:::tip
|
|
35
|
+
You can refer to the [TypeScript - paths](https://www.typescriptlang.org/tsconfig#paths) documentation for more details.
|
|
36
|
+
:::
|
|
37
|
+
|
|
38
|
+
## Use `source.alias` Configuration
|
|
39
|
+
|
|
40
|
+
Modern.js provides the [source.alias](/configure/app/source/alias) configuration option. You can configure this option using an object or a function.
|
|
41
|
+
|
|
42
|
+
### Use Cases
|
|
43
|
+
|
|
44
|
+
Since the `paths` configuration in `tsconfig.json` is written in a static JSON file, it lacks dynamism.
|
|
45
|
+
|
|
46
|
+
The `source.alias` configuration can address this limitation by allowing you to dynamically set the `source.alias` using JavaScript code, such as based on environment variables.
|
|
47
|
+
|
|
48
|
+
### Object Usage
|
|
49
|
+
|
|
50
|
+
You can configure `source.alias` using an object, where the relative paths will be automatically resolved to absolute paths.
|
|
51
|
+
|
|
52
|
+
For example:
|
|
53
|
+
|
|
54
|
+
```js
|
|
55
|
+
export default {
|
|
56
|
+
source: {
|
|
57
|
+
alias: {
|
|
58
|
+
'@common': './src/common',
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
After configuring, if you reference `@common/Foo.tsx` in your code, it will be mapped to the `<project>/src/common/Foo.tsx` path.
|
|
65
|
+
|
|
66
|
+
### Function Usage
|
|
67
|
+
|
|
68
|
+
You can also configure `source.alias` as a function, which receives the built-in `alias` object and allows you to modify it.
|
|
69
|
+
|
|
70
|
+
For example:
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
export default {
|
|
74
|
+
source: {
|
|
75
|
+
alias: alias => {
|
|
76
|
+
alias['@common'] = './src/common';
|
|
77
|
+
return alias;
|
|
78
|
+
},
|
|
79
|
+
},
|
|
80
|
+
};
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Priority
|
|
84
|
+
|
|
85
|
+
The `paths` configuration in `tsconfig.json` takes precedence over the `source.alias` configuration. When a path matches the rules defined in both `paths` and `source.alias`, the value defined in `paths` will be used.
|
|
86
|
+
|
|
87
|
+
You can adjust the priority of these two options using [source.aliasStrategy](/configure/app/source/alias-strategy).
|
|
88
|
+
|
|
89
|
+
## Default Aliases
|
|
90
|
+
|
|
91
|
+
The Modern.js framework comes with the following aliases built-in:
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"@": "./src",
|
|
96
|
+
"@shared": "./shared"
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Additionally, when the BFF plugin of the framework is enabled, the `@api` alias is automatically added.
|
|
101
|
+
|
|
102
|
+
```json
|
|
103
|
+
{
|
|
104
|
+
"@api": "./api"
|
|
105
|
+
}
|
|
106
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
["css", "css-modules", "css-in-js", "tailwindcss"]
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# Using CSS-in-JS
|
|
2
|
+
|
|
3
|
+
CSS-in-JS is a technique that allows you to write CSS styles within JS files.
|
|
4
|
+
|
|
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
|
+
|
|
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:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import styled from '@modern-js/plugin-styled-components/styled';
|
|
48
|
+
|
|
49
|
+
const RedDiv = styled.div`
|
|
50
|
+
color: red;
|
|
51
|
+
`;
|
|
52
|
+
```
|
|
53
|
+
|
|
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:
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
import styled from '@modern-js/plugin-styled-components/styled';
|
|
58
|
+
|
|
59
|
+
const Button = styled.button`
|
|
60
|
+
color: ${props => (props.primary ? 'white' : 'red')};
|
|
61
|
+
font-size: 1em;
|
|
62
|
+
`;
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
For more usage of styled-components, please refer to the [styled-components official website](https://styled-components.com/).
|
|
66
|
+
|
|
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.
|
|
69
|
+
:::
|