@modern-js/main-doc 2.2.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- package/.turbo/turbo-build.log +1 -1
- package/en/components/global-proxy-config.mdx +2 -2
- package/en/components/init-app.mdx +1 -1
- package/en/configure/app/auto-load-plugin.mdx +2 -2
- package/en/configure/app/bff/prefix.mdx +2 -2
- package/en/configure/app/bff/proxy.mdx +2 -2
- package/en/configure/app/builder-plugins.mdx +2 -2
- package/en/configure/app/deploy/microFrontend.mdx +6 -6
- package/en/configure/app/dev/asset-prefix.mdx +4 -3
- package/en/configure/app/dev/hmr.mdx +4 -3
- package/en/configure/app/dev/https.mdx +4 -3
- package/en/configure/app/dev/port.mdx +4 -3
- package/en/configure/app/dev/progress-bar.mdx +4 -3
- package/en/configure/app/dev/start-url.mdx +4 -3
- package/en/configure/app/experiments/lazy-compilation.mdx +4 -3
- package/en/configure/app/html/app-icon.mdx +4 -3
- package/en/configure/app/html/crossorigin.mdx +4 -3
- package/en/configure/app/html/disable-html-folder.mdx +4 -3
- package/en/configure/app/html/favicon-by-entries.mdx +4 -3
- package/en/configure/app/html/favicon.mdx +4 -3
- package/en/configure/app/html/inject-by-entries.mdx +4 -3
- package/en/configure/app/html/inject.mdx +4 -3
- package/en/configure/app/html/meta-by-entries.mdx +4 -3
- package/en/configure/app/html/meta.mdx +4 -3
- package/en/configure/app/html/mount-id.mdx +4 -3
- package/en/configure/app/html/tags-by-entries.mdx +4 -3
- package/en/configure/app/html/tags.mdx +4 -3
- package/en/configure/app/html/template-by-entries.mdx +4 -3
- package/en/configure/app/html/template-parameters-by-entries.mdx +4 -3
- package/en/configure/app/html/template-parameters.mdx +4 -3
- package/en/configure/app/html/template.mdx +4 -3
- package/en/configure/app/html/title-by-entries.mdx +4 -3
- package/en/configure/app/html/title.mdx +4 -3
- package/en/configure/app/output/asset-prefix.mdx +4 -3
- package/en/configure/app/output/assets-retry.mdx +4 -3
- package/en/configure/app/output/charset.mdx +4 -3
- package/en/configure/app/output/clean-dist-path.mdx +4 -3
- package/en/configure/app/output/convert-to-rem.mdx +4 -3
- package/en/configure/app/output/copy.mdx +4 -3
- package/en/configure/app/output/css-module-local-ident-name.mdx +4 -3
- package/en/configure/app/output/data-uri-limit.mdx +4 -3
- package/en/configure/app/output/disable-css-extract.mdx +4 -3
- package/en/configure/app/output/disable-css-module-extension.mdx +4 -3
- package/en/configure/app/output/disable-filename-hash.mdx +4 -3
- package/en/configure/app/output/disable-inline-runtime-chunk.mdx +4 -3
- package/en/configure/app/output/disable-minimize.mdx +4 -3
- package/en/configure/app/output/disable-node-polyfill.mdx +2 -2
- package/en/configure/app/output/disable-source-map.mdx +4 -3
- package/en/configure/app/output/disable-ts-checker.mdx +4 -3
- package/en/configure/app/output/dist-path.mdx +4 -3
- package/en/configure/app/output/enable-asset-fallback.mdx +4 -3
- package/en/configure/app/output/enable-asset-manifest.mdx +4 -3
- package/en/configure/app/output/enable-css-module-tsdeclaration.mdx +4 -3
- package/en/configure/app/output/enable-inline-scripts.mdx +4 -3
- package/en/configure/app/output/enable-inline-styles.mdx +4 -3
- package/en/configure/app/output/enable-latest-decorators.mdx +4 -3
- package/en/configure/app/output/externals.mdx +4 -3
- package/en/configure/app/output/filename.mdx +4 -3
- package/en/configure/app/output/legal-comments.mdx +4 -3
- package/en/configure/app/output/override-browserslist.mdx +4 -3
- package/en/configure/app/output/polyfill.mdx +4 -3
- package/en/configure/app/output/ssg.mdx +2 -2
- package/en/configure/app/output/svg-default-export.mdx +4 -3
- package/en/configure/app/performance/build-cache.mdx +4 -3
- package/en/configure/app/performance/bundle-analyze.mdx +4 -3
- package/en/configure/app/performance/chunk-split.mdx +4 -3
- package/en/configure/app/performance/print-file-size.mdx +4 -3
- package/en/configure/app/performance/profile.mdx +4 -3
- package/en/configure/app/performance/remove-console.mdx +4 -3
- package/en/configure/app/performance/remove-moment-locale.mdx +4 -3
- package/en/configure/app/plugins.mdx +2 -2
- package/en/configure/app/runtime/intro.mdx +2 -2
- package/en/configure/app/runtime/master-app.mdx +1 -2
- package/en/configure/app/runtime/router.mdx +6 -6
- package/en/configure/app/runtime/state.mdx +14 -14
- package/en/configure/app/security/check-syntax.mdx +13 -0
- package/en/configure/app/security/sri.mdx +4 -3
- package/en/configure/app/server/base-url.mdx +2 -2
- package/en/configure/app/server/enable-framework-ext.mdx +2 -2
- package/en/configure/app/server/port.mdx +2 -2
- package/en/configure/app/server/public-routes.mdx +2 -2
- package/en/configure/app/server/routes.mdx +2 -2
- package/en/configure/app/server/ssr-by-entries.mdx +2 -2
- package/en/configure/app/server/ssr.mdx +2 -2
- package/en/configure/app/source/alias.mdx +4 -3
- package/en/configure/app/source/compile-js-data-uri.mdx +4 -3
- package/en/configure/app/source/config-dir.mdx +2 -2
- package/en/configure/app/source/define.mdx +4 -3
- package/en/configure/app/source/design-system.mdx +2 -2
- package/en/configure/app/source/disable-default-entries.mdx +2 -2
- package/en/configure/app/source/disable-entry-dirs.mdx +2 -2
- package/en/configure/app/source/enable-async-entry.mdx +2 -2
- package/en/configure/app/source/entries-dir.mdx +2 -2
- package/en/configure/app/source/entries.mdx +2 -2
- package/en/configure/app/source/exclude.mdx +4 -3
- package/en/configure/app/source/global-vars.mdx +4 -3
- package/en/configure/app/source/include.mdx +4 -3
- package/en/configure/app/source/module-scopes.mdx +4 -3
- package/en/configure/app/source/pre-entry.mdx +4 -3
- package/en/configure/app/source/resolve-extension-prefix.mdx +4 -3
- package/en/configure/app/source/resolve-main-fields.mdx +4 -3
- package/en/configure/app/testing/transformer.mdx +2 -2
- package/en/configure/app/tools/autoprefixer.mdx +4 -3
- package/en/configure/app/tools/babel.mdx +4 -3
- package/en/configure/app/tools/css-extract.mdx +4 -3
- package/en/configure/app/tools/css-loader.mdx +4 -3
- package/en/configure/app/tools/dev-server.mdx +4 -3
- package/en/configure/app/tools/esbuild.mdx +2 -2
- package/en/configure/app/tools/html-plugin.mdx +4 -3
- package/en/configure/app/tools/inspector.mdx +4 -3
- package/en/configure/app/tools/jest.mdx +2 -2
- package/en/configure/app/tools/less.mdx +4 -3
- package/en/configure/app/tools/minify-css.mdx +4 -3
- package/en/configure/app/tools/postcss.mdx +4 -3
- package/en/configure/app/tools/pug.mdx +4 -3
- package/en/configure/app/tools/sass.mdx +4 -3
- package/en/configure/app/tools/style-loader.mdx +4 -3
- package/en/configure/app/tools/styled-components.mdx +4 -3
- package/en/configure/app/tools/swc.mdx +2 -2
- package/en/configure/app/tools/tailwindcss.mdx +8 -16
- package/en/configure/app/tools/terser.mdx +4 -3
- package/en/configure/app/tools/ts-checker.mdx +4 -3
- package/en/configure/app/tools/ts-loader.mdx +4 -3
- package/en/configure/app/tools/webpack-chain.mdx +4 -3
- package/en/configure/app/tools/webpack.mdx +4 -3
- package/en/configure/app/usage.mdx +117 -8
- package/en/guides/advanced-features/_category_.json +5 -0
- package/en/guides/advanced-features/ssr.mdx +2 -2
- package/en/guides/basic-features/_category_.json +5 -0
- package/en/guides/basic-features/builder.mdx +3 -3
- package/en/guides/basic-features/routes.mdx +28 -0
- package/en/guides/concept/_category_.json +5 -0
- package/en/guides/get-started/_category_.json +5 -0
- package/en/guides/topic-detail/generator/config/{mwa.mdx → app.mdx} +1 -1
- package/en/guides/topic-detail/generator/config/common.mdx +12 -12
- package/en/guides/topic-detail/generator/plugin/api/new/createElement.mdx +1 -1
- package/en/guides/topic-detail/generator/plugin/api/new/enableFunc.mdx +1 -1
- package/en/guides/topic-detail/generator/plugin/api/new/introduce.mdx +1 -1
- package/en/guides/topic-detail/generator/plugin/develop.mdx +2 -2
- package/package.json +3 -3
- package/scripts/config.ts +6 -5
- package/scripts/summary.en.json +1 -1
- package/scripts/summary.zh.json +1 -1
- package/zh/apis/app/commands/test.mdx +1 -1
- package/zh/apis/app/hooks/api/functions/api.mdx +2 -2
- package/zh/apis/app/hooks/api/test.mdx +1 -1
- package/zh/apis/app/hooks/config/storybook.mdx +1 -1
- package/zh/apis/app/hooks/config/upload.mdx +1 -1
- package/zh/apis/app/hooks/server/test.mdx +1 -1
- package/zh/apis/app/hooks/src/stories.mdx +1 -1
- package/zh/apis/app/hooks/src/test.mdx +1 -1
- package/zh/apis/app/runtime/testing/cleanup.mdx +1 -1
- package/zh/apis/monorepo/commands/bump.mdx +1 -1
- package/zh/apis/monorepo/commands/change.mdx +1 -1
- package/zh/apis/monorepo/hooks/apps.mdx +1 -1
- package/zh/apis/monorepo/hooks/examples.mdx +1 -1
- package/zh/apis/monorepo/hooks/features.mdx +1 -1
- package/zh/apis/monorepo/hooks/packages.mdx +1 -1
- package/zh/components/custom-router-micro-frontend.mdx +40 -0
- package/zh/components/enable-micro-frontend.mdx +12 -2
- package/zh/components/global-proxy-config.mdx +3 -3
- package/zh/components/micro-runtime-config.mdx +9 -10
- package/zh/configure/app/auto-load-plugin.mdx +2 -2
- package/zh/configure/app/bff/prefix.mdx +2 -2
- package/zh/configure/app/bff/proxy.mdx +3 -3
- package/zh/configure/app/builder-plugins.mdx +2 -2
- package/zh/configure/app/deploy/microFrontend.mdx +6 -6
- package/zh/configure/app/dev/asset-prefix.mdx +4 -3
- package/zh/configure/app/dev/hmr.mdx +4 -3
- package/zh/configure/app/dev/https.mdx +4 -3
- package/zh/configure/app/dev/port.mdx +4 -3
- package/zh/configure/app/dev/progress-bar.mdx +4 -3
- package/zh/configure/app/dev/start-url.mdx +4 -3
- package/zh/configure/app/experiments/lazy-compilation.mdx +4 -3
- package/zh/configure/app/html/app-icon.mdx +4 -3
- package/zh/configure/app/html/crossorigin.mdx +4 -3
- package/zh/configure/app/html/disable-html-folder.mdx +4 -3
- package/zh/configure/app/html/favicon-by-entries.mdx +4 -3
- package/zh/configure/app/html/favicon.mdx +4 -3
- package/zh/configure/app/html/inject-by-entries.mdx +4 -3
- package/zh/configure/app/html/inject.mdx +4 -3
- package/zh/configure/app/html/meta-by-entries.mdx +4 -3
- package/zh/configure/app/html/meta.mdx +4 -3
- package/zh/configure/app/html/mount-id.mdx +4 -3
- package/zh/configure/app/html/tags-by-entries.mdx +4 -3
- package/zh/configure/app/html/tags.mdx +4 -3
- package/zh/configure/app/html/template-by-entries.mdx +4 -3
- package/zh/configure/app/html/template-parameters-by-entries.mdx +4 -3
- package/zh/configure/app/html/template-parameters.mdx +4 -3
- package/zh/configure/app/html/template.mdx +4 -3
- package/zh/configure/app/html/title-by-entries.mdx +4 -3
- package/zh/configure/app/html/title.mdx +4 -3
- package/zh/configure/app/output/asset-prefix.mdx +4 -3
- package/zh/configure/app/output/assets-retry.mdx +4 -3
- package/zh/configure/app/output/charset.mdx +4 -3
- package/zh/configure/app/output/clean-dist-path.mdx +4 -3
- package/zh/configure/app/output/convert-to-rem.mdx +4 -3
- package/zh/configure/app/output/copy.mdx +4 -3
- package/zh/configure/app/output/css-module-local-ident-name.mdx +4 -3
- package/zh/configure/app/output/data-uri-limit.mdx +4 -3
- package/zh/configure/app/output/disable-css-extract.mdx +4 -3
- package/zh/configure/app/output/disable-css-module-extension.mdx +4 -3
- package/zh/configure/app/output/disable-filename-hash.mdx +4 -3
- package/zh/configure/app/output/disable-inline-runtime-chunk.mdx +4 -3
- package/zh/configure/app/output/disable-minimize.mdx +4 -3
- package/zh/configure/app/output/disable-node-polyfill.mdx +2 -2
- package/zh/configure/app/output/disable-source-map.mdx +4 -3
- package/zh/configure/app/output/disable-ts-checker.mdx +4 -3
- package/zh/configure/app/output/dist-path.mdx +4 -3
- package/zh/configure/app/output/enable-asset-fallback.mdx +4 -3
- package/zh/configure/app/output/enable-asset-manifest.mdx +4 -3
- package/zh/configure/app/output/enable-css-module-tsdeclaration.mdx +4 -3
- package/zh/configure/app/output/enable-inline-scripts.mdx +4 -3
- package/zh/configure/app/output/enable-inline-styles.mdx +4 -3
- package/zh/configure/app/output/enable-latest-decorators.mdx +4 -3
- package/zh/configure/app/output/externals.mdx +4 -3
- package/zh/configure/app/output/filename.mdx +4 -3
- package/zh/configure/app/output/legal-comments.mdx +4 -3
- package/zh/configure/app/output/override-browserslist.mdx +4 -3
- package/zh/configure/app/output/polyfill.mdx +4 -3
- package/zh/configure/app/output/ssg.mdx +2 -2
- package/zh/configure/app/output/svg-default-export.mdx +4 -3
- package/zh/configure/app/performance/build-cache.mdx +4 -3
- package/zh/configure/app/performance/bundle-analyze.mdx +4 -3
- package/zh/configure/app/performance/chunk-split.mdx +4 -3
- package/zh/configure/app/performance/print-file-size.mdx +4 -3
- package/zh/configure/app/performance/profile.mdx +4 -3
- package/zh/configure/app/performance/remove-console.mdx +4 -3
- package/zh/configure/app/performance/remove-moment-locale.mdx +4 -3
- package/zh/configure/app/plugins.mdx +2 -2
- package/zh/configure/app/runtime/intro.mdx +3 -3
- package/zh/configure/app/runtime/master-app.mdx +1 -1
- package/zh/configure/app/runtime/router.mdx +6 -6
- package/zh/configure/app/runtime/state.mdx +14 -14
- package/zh/configure/app/security/check-syntax.mdx +13 -0
- package/zh/configure/app/security/sri.mdx +4 -3
- package/zh/configure/app/server/base-url.mdx +2 -2
- package/zh/configure/app/server/enable-framework-ext.mdx +2 -2
- package/zh/configure/app/server/port.mdx +2 -2
- package/zh/configure/app/server/public-routes.mdx +2 -2
- package/zh/configure/app/server/routes.mdx +2 -2
- package/zh/configure/app/server/ssr-by-entries.mdx +3 -3
- package/zh/configure/app/server/ssr.mdx +2 -2
- package/zh/configure/app/source/alias.mdx +4 -3
- package/zh/configure/app/source/compile-js-data-uri.mdx +4 -3
- package/zh/configure/app/source/config-dir.mdx +2 -2
- package/zh/configure/app/source/define.mdx +4 -3
- package/zh/configure/app/source/design-system.mdx +2 -2
- package/zh/configure/app/source/disable-default-entries.mdx +2 -2
- package/zh/configure/app/source/disable-entry-dirs.mdx +2 -2
- package/zh/configure/app/source/enable-async-entry.mdx +2 -2
- package/zh/configure/app/source/entries-dir.mdx +2 -2
- package/zh/configure/app/source/entries.mdx +2 -2
- package/zh/configure/app/source/exclude.mdx +4 -3
- package/zh/configure/app/source/global-vars.mdx +4 -3
- package/zh/configure/app/source/include.mdx +4 -3
- package/zh/configure/app/source/module-scopes.mdx +4 -3
- package/zh/configure/app/source/pre-entry.mdx +4 -3
- package/zh/configure/app/source/resolve-extension-prefix.mdx +4 -3
- package/zh/configure/app/source/resolve-main-fields.mdx +4 -3
- package/zh/configure/app/testing/transformer.mdx +2 -2
- package/zh/configure/app/tools/autoprefixer.mdx +4 -3
- package/zh/configure/app/tools/babel.mdx +4 -3
- package/zh/configure/app/tools/css-extract.mdx +4 -3
- package/zh/configure/app/tools/css-loader.mdx +4 -3
- package/zh/configure/app/tools/dev-server.mdx +4 -3
- package/zh/configure/app/tools/esbuild.mdx +2 -2
- package/zh/configure/app/tools/html-plugin.mdx +4 -3
- package/zh/configure/app/tools/inspector.mdx +4 -3
- package/zh/configure/app/tools/jest.mdx +2 -2
- package/zh/configure/app/tools/less.mdx +4 -3
- package/zh/configure/app/tools/minify-css.mdx +4 -3
- package/zh/configure/app/tools/postcss.mdx +4 -3
- package/zh/configure/app/tools/pug.mdx +4 -3
- package/zh/configure/app/tools/sass.mdx +4 -3
- package/zh/configure/app/tools/style-loader.mdx +4 -3
- package/zh/configure/app/tools/styled-components.mdx +4 -3
- package/zh/configure/app/tools/swc.mdx +2 -2
- package/zh/configure/app/tools/tailwindcss.mdx +10 -16
- package/zh/configure/app/tools/terser.mdx +4 -3
- package/zh/configure/app/tools/ts-checker.mdx +4 -3
- package/zh/configure/app/tools/ts-loader.mdx +4 -3
- package/zh/configure/app/tools/webpack-chain.mdx +4 -3
- package/zh/configure/app/tools/webpack.mdx +4 -3
- package/zh/configure/app/usage.mdx +117 -8
- package/zh/guides/advanced-features/bff/function.mdx +3 -3
- package/zh/guides/advanced-features/code-split.mdx +1 -1
- package/zh/guides/advanced-features/compatibility.mdx +1 -1
- package/zh/guides/advanced-features/eslint.mdx +3 -3
- package/zh/guides/advanced-features/ssr.mdx +3 -3
- package/zh/guides/basic-features/alias.mdx +1 -1
- package/zh/guides/basic-features/builder.mdx +2 -2
- package/zh/guides/basic-features/css/postcss.mdx +1 -1
- package/zh/guides/basic-features/html.mdx +1 -1
- package/zh/guides/basic-features/routes.mdx +28 -1
- package/zh/guides/topic-detail/framework-plugin/hook.mdx +1 -1
- package/zh/guides/topic-detail/generator/config/{mwa.mdx → app.mdx} +1 -1
- package/zh/guides/topic-detail/generator/config/common.mdx +12 -12
- package/zh/guides/topic-detail/generator/plugin/api/input/addInputBefore.mdx +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/new/createElement.mdx +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/new/enableFunc.mdx +1 -1
- package/zh/guides/topic-detail/generator/plugin/api/new/introduce.mdx +2 -2
- package/zh/guides/topic-detail/generator/plugin/develop.mdx +3 -3
- package/zh/guides/topic-detail/micro-frontend/c02-development.mdx +128 -61
- package/zh/guides/topic-detail/micro-frontend/c03-main-app.mdx +71 -40
- package/zh/guides/topic-detail/micro-frontend/c05-mixed-stack.mdx +1 -1
- package/zh/guides/topic-detail/model/auto-actions.mdx +1 -1
- package/zh/guides/topic-detail/model/define-model.mdx +1 -1
- package/zh/guides/topic-detail/model/manage-effects.mdx +1 -1
- package/zh/guides/topic-detail/model/quick-start.mdx +2 -2
- package/zh/guides/topic-detail/model/test-model.mdx +1 -1
- package/zh/guides/topic-detail/model/use-model.mdx +3 -3
- package/zh/guides/topic-detail/monorepo/create-sub-project.mdx +2 -2
- package/zh/guides/topic-detail/monorepo/sub-project-interface.mdx +2 -2
- package/zh/tutorials/first-app/c02-component.mdx +1 -1
- package/zh/tutorials/first-app/c03-css.mdx +3 -3
- package/zh/tutorials/first-app/c04-routes.mdx +1 -1
- package/zh/tutorials/first-app/c06-model.mdx +1 -1
@@ -1,10 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title: tools.inspector
|
3
2
|
sidebar_label: inspector
|
4
3
|
---
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
# tools.inspector
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.inspector](https://modernjs.dev/builder/api/config-tools.html#toolsinspector)。
|
8
9
|
:::
|
9
10
|
|
10
11
|
import Main from '@modern-js/builder-doc/docs/zh/config/tools/inspector.md'
|
@@ -1,10 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title: tools.less
|
3
2
|
sidebar_label: less
|
4
3
|
---
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
# tools.less
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.less](https://modernjs.dev/builder/api/config-tools.html#toolsless)。
|
8
9
|
:::
|
9
10
|
|
10
11
|
import Main from '@modern-js/builder-doc/docs/zh/config/tools/less.md'
|
@@ -1,10 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title: tools.minifyCss
|
3
2
|
sidebar_label: minifyCss
|
4
3
|
---
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
# tools.minifyCss
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.minifyCss](https://modernjs.dev/builder/api/config-tools.html#toolsminifycss)。
|
8
9
|
:::
|
9
10
|
|
10
11
|
import Main from '@modern-js/builder-doc/docs/zh/config/tools/minifyCss.md'
|
@@ -1,10 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title: tools.postcss
|
3
2
|
sidebar_label: postcss
|
4
3
|
---
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
# tools.postcss
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.postcss](https://modernjs.dev/builder/api/config-tools.html#toolspostcss)。
|
8
9
|
:::
|
9
10
|
|
10
11
|
import Main from '@modern-js/builder-doc/docs/zh/config/tools/postcss.md'
|
@@ -1,10 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title: tools.pug
|
3
2
|
sidebar_label: pug
|
4
3
|
---
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
# tools.pug
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.pug](https://modernjs.dev/builder/api/config-tools.html#toolspug)。
|
8
9
|
:::
|
9
10
|
|
10
11
|
import Main from '@modern-js/builder-doc/docs/zh/config/tools/pug.md'
|
@@ -1,10 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title: tools.sass
|
3
2
|
sidebar_label: sass
|
4
3
|
---
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
# tools.sass
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.sass](https://modernjs.dev/builder/api/config-tools.html#toolssass)。
|
8
9
|
:::
|
9
10
|
|
10
11
|
import Main from '@modern-js/builder-doc/docs/zh/config/tools/sass.md'
|
@@ -1,10 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title: tools.styleLoader
|
3
2
|
sidebar_label: styleLoader
|
4
3
|
---
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
# tools.styleLoader
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.styleLoader](https://modernjs.dev/builder/api/config-tools.html#toolsstyleloader)。
|
8
9
|
:::
|
9
10
|
|
10
11
|
import Main from '@modern-js/builder-doc/docs/zh/config/tools/styleLoader.md'
|
@@ -1,10 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title: tools.styledComponents
|
3
2
|
sidebar_label: styledComponents
|
4
3
|
---
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
# tools.styledComponents
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.styledComponents](https://modernjs.dev/builder/api/config-tools.html#toolsstyledcomponents)。
|
8
9
|
:::
|
9
10
|
|
10
11
|
import Main from '@modern-js/builder-doc/docs/zh/config/tools/styledComponents.md'
|
@@ -1,15 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title: tools.tailwindcss
|
3
|
-
|
4
2
|
sidebar_label: tailwindcss
|
5
3
|
---
|
6
|
-
# tailwindcss
|
7
4
|
|
8
|
-
|
9
|
-
- 默认值:见下方配置详情。
|
5
|
+
# tools.tailwindcss
|
10
6
|
|
11
|
-
|
12
|
-
|
7
|
+
- **类型:** `Object | Function`
|
8
|
+
- **默认值:**
|
13
9
|
|
14
10
|
```js
|
15
11
|
const tailwind = {
|
@@ -23,21 +19,19 @@ const tailwind = {
|
|
23
19
|
'./src/**/*.tsx',
|
24
20
|
'./storybook/**/*',
|
25
21
|
],
|
26
|
-
|
22
|
+
// 使用 source.designSystem 配置作为 Tailwind CSS Theme 配置
|
23
|
+
theme: source.designSystem,
|
27
24
|
};
|
28
25
|
```
|
29
26
|
|
30
|
-
|
31
|
-
更多关于:<a href="https://tailwindcss.com/docs/configuration" target="_blank">TailwindCSS 配置</a>。
|
32
|
-
|
33
|
-
:::
|
27
|
+
对应 [TailwindCSS](https://tailwindcss.com/docs/configuration) 的配置。
|
34
28
|
|
35
|
-
|
29
|
+
当值为 `Object` 类型时,与默认配置通过 `Object.assign` 合并。
|
36
30
|
|
37
|
-
|
31
|
+
当值为 `Function` 类型时,函数返回的对象与默认配置通过 `Object.assign` 合并。
|
38
32
|
|
39
|
-
|
33
|
+
### 限制
|
40
34
|
|
41
|
-
|
35
|
+
注意,该配置中不允许使用 `theme` 配置项,否则会构建失败。在 Modern.js 中,请使用 [source.designSystem](/configure/app/source/design-system) 作为 `Tailwind CSS Theme` 配置。
|
42
36
|
|
43
37
|
其他的使用方式和 Tailwind CSS 一致: [快速传送门](https://tailwindcss.com/docs/configuration)。
|
@@ -1,10 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title: tools.terser
|
3
2
|
sidebar_label: terser
|
4
3
|
---
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
# tools.terser
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.terser](https://modernjs.dev/builder/api/config-tools.html#toolsterser)。
|
8
9
|
:::
|
9
10
|
|
10
11
|
import Main from '@modern-js/builder-doc/docs/zh/config/tools/terser.md'
|
@@ -1,10 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title: tools.tsChecker
|
3
2
|
sidebar_label: tsChecker
|
4
3
|
---
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
# tools.tsChecker
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.tsChecker](https://modernjs.dev/builder/api/config-tools.html#toolstschecker)。
|
8
9
|
:::
|
9
10
|
|
10
11
|
import Main from '@modern-js/builder-doc/docs/zh/config/tools/tsChecker.md'
|
@@ -1,10 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title: tools.tsLoader
|
3
2
|
sidebar_label: tsLoader
|
4
3
|
---
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
# tools.tsLoader
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.tsLoader](https://modernjs.dev/builder/api/config-tools.html#toolstsloader)。
|
8
9
|
:::
|
9
10
|
|
10
11
|
import Main from '@modern-js/builder-doc/docs/zh/config/tools/tsLoader.md'
|
@@ -1,10 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title: tools.webpackChain
|
3
2
|
sidebar_label: webpackChain
|
4
3
|
---
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
# tools.webpackChain
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.webpackChain](https://modernjs.dev/builder/api/config-tools.html#toolswebpackchain)。
|
8
9
|
:::
|
9
10
|
|
10
11
|
import Main from '@modern-js/builder-doc/docs/zh/config/tools/webpackChain.md'
|
@@ -1,10 +1,11 @@
|
|
1
1
|
---
|
2
|
-
title: tools.webpack
|
3
2
|
sidebar_label: webpack
|
4
3
|
---
|
5
4
|
|
6
|
-
|
7
|
-
|
5
|
+
# tools.webpack
|
6
|
+
|
7
|
+
:::tip
|
8
|
+
该配置由 Modern.js Builder 提供,更多信息可参考 [tools.webpack](https://modernjs.dev/builder/api/config-tools.html#toolswebpack)。
|
8
9
|
:::
|
9
10
|
|
10
11
|
import Main from '@modern-js/builder-doc/docs/zh/config/tools/webpack.md'
|
@@ -8,22 +8,22 @@ Modern.js 中有两种配置,一个是编译时配置,一个是服务端运
|
|
8
8
|
|
9
9
|
编译时配置可以在两个位置进行配置:
|
10
10
|
|
11
|
+
- 根路径下的 `modern.config.(ts|js|mjs)` 文件
|
11
12
|
- `package.json` 文件
|
12
|
-
- 根路径下的 `modern.config.t(j)s` 文件
|
13
|
-
|
14
|
-
:::warning 注意
|
15
|
-
同一个配置不支持同时在 `package.json` 中和 `modern.config.t(j)s` 中配置。推荐在 `modern.config.t(j)s` 中进行配置。
|
16
13
|
|
14
|
+
:::info
|
15
|
+
不支持同时在 package.json 中和 modern.config.ts 中配置同一个配置项,推荐优先在 modern.config.ts 中进行配置。如果 Modern.js 检测到重复配置导致的冲突,将会抛出警告。
|
17
16
|
:::
|
18
17
|
|
19
|
-
服务端运行时配置可以在根路径下的 `modern.server-runtime.config.
|
18
|
+
服务端运行时配置可以在根路径下的 `modern.server-runtime.config.(ts|js|mjs)` 中自定义配置选项。
|
20
19
|
|
21
20
|
## 在配置文件中配置
|
22
21
|
|
23
|
-
Modern.js
|
22
|
+
Modern.js 的配置文件定义在项目的根目录下,支持 `.js`, `.ts` 和 `.mjs` 格式:
|
24
23
|
|
25
24
|
- `modern.config.js`
|
26
25
|
- `modern.config.ts`
|
26
|
+
- `modern.config.mjs`
|
27
27
|
|
28
28
|
### modern.config.js
|
29
29
|
|
@@ -51,7 +51,7 @@ export default {
|
|
51
51
|
};
|
52
52
|
```
|
53
53
|
|
54
|
-
### modern.config.ts
|
54
|
+
### modern.config.ts(推荐)
|
55
55
|
|
56
56
|
我们推荐使用 .ts 格式的配置文件,它提供了友好的 TypeScript 类型提示,从而帮助你避免配置中的错误。
|
57
57
|
|
@@ -69,6 +69,69 @@ export default defineConfig({
|
|
69
69
|
});
|
70
70
|
```
|
71
71
|
|
72
|
+
### 导出配置函数
|
73
|
+
|
74
|
+
Modern.js 支持在配置文件中导出一个函数,你可以在函数中动态计算配置,并返回给 Modern.js。
|
75
|
+
|
76
|
+
```js title="modern.config.js"
|
77
|
+
import { defineConfig } from '@modern-js/app-tools';
|
78
|
+
|
79
|
+
export default defineConfig(({ env, command }) => ({
|
80
|
+
source: {
|
81
|
+
alias: {
|
82
|
+
'@foo': env === 'development' ? './src/foo.dev.ts' : './src/foo.prod.ts',
|
83
|
+
},
|
84
|
+
},
|
85
|
+
}));
|
86
|
+
```
|
87
|
+
|
88
|
+
该函数接受以下入参:
|
89
|
+
|
90
|
+
- `env`:对应 `process.env.NODE_ENV` 的值。
|
91
|
+
- 当运行 `modern dev` 或 `modern start` 时,`env` 的值为 `development`。
|
92
|
+
- 当运行 `modern build` 或 `modern serve` 时,`env` 的值为 `production`。
|
93
|
+
- 当运行 `modern test` 时,`env` 的值为 `test`。
|
94
|
+
- `command`: 对应当前运行的命令,如 `dev`、`start`、`build`、`serve`。
|
95
|
+
|
96
|
+
### 导出异步函数
|
97
|
+
|
98
|
+
Modern.js 也支持在配置文件中导出一个异步函数,你可以在函数中进行一些异步操作:
|
99
|
+
|
100
|
+
```js title="modern.config.js"
|
101
|
+
import { defineConfig } from '@modern-js/app-tools';
|
102
|
+
|
103
|
+
export default defineConfig(async ({ env, command }) => {
|
104
|
+
const result = await someAsyncFunction();
|
105
|
+
|
106
|
+
return {
|
107
|
+
html: {
|
108
|
+
title: result,
|
109
|
+
},
|
110
|
+
};
|
111
|
+
});
|
112
|
+
```
|
113
|
+
|
114
|
+
### 指定配置文件
|
115
|
+
|
116
|
+
Modern.js 命令行支持通过 `--config` 选项来指定配置文件的名称。
|
117
|
+
|
118
|
+
例如,你需要在执行 build 命令时使用 `modern.prod.config.ts` 文件,可以在 `package.json` 中添加如下配置:
|
119
|
+
|
120
|
+
```json title="package.json"
|
121
|
+
{
|
122
|
+
"scripts": {
|
123
|
+
"dev": "modern modern",
|
124
|
+
"build": "modern build --config modern.prod.config.ts"
|
125
|
+
}
|
126
|
+
}
|
127
|
+
```
|
128
|
+
|
129
|
+
你也可以将 `--config` 选项缩写为 `-c`:
|
130
|
+
|
131
|
+
```bash
|
132
|
+
$ modern build -c modern.prod.config.js
|
133
|
+
```
|
134
|
+
|
72
135
|
## 在 package.json 中配置(不推荐)
|
73
136
|
|
74
137
|
除了配置文件外,也可以在 `package.json` 中的 `modernConfig` 字段下设置配置选项,如:
|
@@ -87,7 +150,53 @@ export default defineConfig({
|
|
87
150
|
|
88
151
|
由于 JSON 文件格式的限制,`package.json` 中只能定义数字、字符串、布尔值、数组等简单类型的值,当我们需要设置函数类型的值时,建议在 Modern.js 配置文件中进行设置。
|
89
152
|
|
90
|
-
|
153
|
+
### 注意事项
|
91
154
|
|
92
155
|
- 不建议同时使用 `package.json` 和 `modern.config.js` 进行配置。如果同时使用了两者并出现配置冲突,Modern.js 会在命令行进行提示。
|
93
156
|
- `@modern-js/runtime` 导出了同名的 [defineConfig](/apis/app/runtime/app/define-config) API,请注意区分。
|
157
|
+
|
158
|
+
## 本地调试配置
|
159
|
+
|
160
|
+
为了便于本地调试配置,Modern.js 支持在项目根目录下创建 `modern.config.local.(ts|js|mjs)` 文件,用于覆盖 `modern.config.(ts|js|mjs)` 中的配置选项。
|
161
|
+
|
162
|
+
### 示例
|
163
|
+
|
164
|
+
比如,项目的 `modern.config.ts` 中配置了端口号为 `3000`:
|
165
|
+
|
166
|
+
```ts title="modern.config.ts"
|
167
|
+
import { defineConfig } from '@modern-js/app-tools';
|
168
|
+
|
169
|
+
export default defineConfig({
|
170
|
+
server: {
|
171
|
+
port: 3000,
|
172
|
+
},
|
173
|
+
});
|
174
|
+
```
|
175
|
+
|
176
|
+
如果你在本地调试时需要将端口号修改为 `3001`,但是又不希望修改当前项目的 `modern.config.ts` 文件,那么可以创建一个 `modern.config.local.ts` 文件,并添加以下配置:
|
177
|
+
|
178
|
+
```ts title="modern.config.local.ts"
|
179
|
+
import { defineConfig } from '@modern-js/app-tools';
|
180
|
+
|
181
|
+
export default defineConfig({
|
182
|
+
server: {
|
183
|
+
port: 3001,
|
184
|
+
},
|
185
|
+
});
|
186
|
+
```
|
187
|
+
|
188
|
+
`modern.config.local.ts` 文件中的配置会与 `modern.config.ts` 中的配置进行深层合并,并覆盖 `modern.config.ts` 中的配置选项,因此 `server.port` 会被覆盖为 `3001`。
|
189
|
+
|
190
|
+
### 注意事项
|
191
|
+
|
192
|
+
在使用 `modern.config.local.ts` 时,请注意以下事项:
|
193
|
+
|
194
|
+
- `modern.config.local.ts` 文件仅会在执行 `modern dev` 或 `modern start` 命令时被加载,当执行 `modern build` 时不会被加载。
|
195
|
+
- `modern.config.local.ts` 文件的优先级不仅高于 `modern.config.ts`,也高于 `package.json` 中的 `modernConfig` 字段。
|
196
|
+
- 由于 `modern.config.local.ts` 仅在本地调试时使用,因此不建议将其提交到代码仓库中,请确保项目的 `.gitignore` 文件中包含 `modern.config.local.ts` 等文件。
|
197
|
+
|
198
|
+
```bash title=".gitingore"
|
199
|
+
modern.config.local.ts
|
200
|
+
modern.config.local.js
|
201
|
+
modern.config.local.mjs
|
202
|
+
```
|
@@ -41,7 +41,7 @@ export default () => {
|
|
41
41
|
};
|
42
42
|
```
|
43
43
|
|
44
|
-
:::info
|
44
|
+
:::info
|
45
45
|
Modern.js 生成器已经在 `tsconfig.json` 中配置 `@api` 别名,因此可以直接通过别名的方式引入函数。
|
46
46
|
|
47
47
|
:::
|
@@ -102,7 +102,7 @@ Modern.js 中,BFF 函数对应的路由系统是基于文件系统实现的,
|
|
102
102
|
|
103
103
|
Modern.js 的 BFF 函数需要遵循 RESTful API 标准来定义, 遵循 HTTP Method 规范,并且不允许自由定义参数。
|
104
104
|
|
105
|
-
:::info
|
105
|
+
:::info
|
106
106
|
假设函数允许自由定义参数,产出的路由必然由**私有协议**进行调用(原因是无法区分请求参数与请求体),而无法实现任意的 RESTful API。
|
107
107
|
|
108
108
|
如果服务仅用于应用本身不存在问题,但它**不标准的接口定义**无法融入更大的体系。 在多个系统共同工作的情况下(例如 BFF 低码搭建),会导致其他系统也需要遵循**私有协议**。
|
@@ -141,7 +141,7 @@ export const post = async () => {
|
|
141
141
|
|
142
142
|
- 可以在一个文件中定义多个不同 Method 的函数,但如果定义多个相同 Method 的函数,则只有第一个会生效。
|
143
143
|
|
144
|
-
:::info
|
144
|
+
:::info
|
145
145
|
需要注意的是,定义的函数都应该是异步的,与函数调用时类型有关,后面会提到。
|
146
146
|
|
147
147
|
:::
|
@@ -74,7 +74,7 @@ function MyComponent() {
|
|
74
74
|
|
75
75
|
`loadable` 更多用法请见 [loadable API](/apis/app/runtime/utility/loadable)。
|
76
76
|
|
77
|
-
:::info
|
77
|
+
:::info
|
78
78
|
`loadable` 开箱即用的支持 SSR,但不支持和 Suspense 一起使用,如果是 CSR 项目可以使用 [loadable.lazy](https://loadable-components.com/docs/suspense/)
|
79
79
|
|
80
80
|
:::
|
@@ -31,7 +31,7 @@ Modern.js 在编译时默认通过 [core-js](https://github.com/zloirock/core-js
|
|
31
31
|
|
32
32
|
默认情况下会根据项目 Browserslist 的设置情况引入所需的 Polyfill 代码, 这样基本不用再担心项目源码和第三方依赖的 Polyfill 问题了,但是因为包含了一些没有用到的 Polyfill 代码,所以最终的包大小可能会有所增加。
|
33
33
|
|
34
|
-
:::info
|
34
|
+
:::info
|
35
35
|
对于明确第三方依赖不需要 Polyfill 的场景,可以设置 [`output.polyfill`](/configure/app/output/polyfill) 为 `usage`, 这样 Babel 编译时只会根据代码中使用到的语法引入 Polyfill 代码。
|
36
36
|
|
37
37
|
:::
|
@@ -16,7 +16,7 @@ sidebar_position: 8
|
|
16
16
|
|
17
17
|
多数问题会被 ESLint 规则的自动修复功能或 [Prettier](https://prettier.io/) 的代码格式化功能(已被集成到 ESLint 里)自动解决,开发者不需要关心问题的细节和解决方式。
|
18
18
|
|
19
|
-
:::info
|
19
|
+
:::info
|
20
20
|
主要在 IDE 保存文件的环节执行这种自动修复,少数漏网之鱼会在提交代码环节被自动修复。
|
21
21
|
|
22
22
|
:::
|
@@ -45,7 +45,7 @@ pnpm run lint:error
|
|
45
45
|
/* eslint-enable filenames/match-exported */
|
46
46
|
```
|
47
47
|
|
48
|
-
:::info
|
48
|
+
:::info
|
49
49
|
在 VS Code 编辑器里输入 eslint,会自动出现关于 "eslint-disable" 的提示框,选择提示选项生成对应注释对。
|
50
50
|
|
51
51
|
:::
|
@@ -76,7 +76,7 @@ pnpm run lint:error
|
|
76
76
|
|
77
77
|
Modern.js 的应用工程、模块工程,源代码目录里都会默认有这个配置文件,是针对 Universal JS 代码设计的。
|
78
78
|
|
79
|
-
:::info
|
79
|
+
:::info
|
80
80
|
Universal JS 代码是既能浏览器端也能在服务器端运行的代码。
|
81
81
|
|
82
82
|
:::
|
@@ -66,7 +66,7 @@ Warning: Expected server HTML to contain a matching <div> in <div>.
|
|
66
66
|
|
67
67
|
这是 React 在客户端执行 hydrate 逻辑时,发现渲染结果与 SSR 渲染结果不一致造成的。虽然页面表现正常,但在复杂应用中,很有可能因此出现 DOM 层级混乱、样式混乱等问题。
|
68
68
|
|
69
|
-
:::info
|
69
|
+
:::info
|
70
70
|
关于 hydrate (注水)逻辑请参考[这里](https://reactjs.org/docs/react-dom.html#hydrate)。
|
71
71
|
|
72
72
|
:::
|
@@ -242,11 +242,11 @@ if (process.env.MODERN_TARGET === 'browser') {
|
|
242
242
|
例如在代码中引入了 `fs-extra`,这时候直接引用到组件中,会造成 CSR 加载报错。可以创建同名的 `.ts` 和 `.node.ts` 文件做一层代理:
|
243
243
|
|
244
244
|
```ts title="compat.ts"
|
245
|
-
export
|
245
|
+
export const readFileSync: any = () => {};
|
246
246
|
```
|
247
247
|
|
248
248
|
```ts title="compat.node.ts"
|
249
|
-
export
|
249
|
+
export { readFileSync } from 'fs-extra';
|
250
250
|
```
|
251
251
|
|
252
252
|
在文件中直接引入 `./compat`,此时 SSR 环境下会优先使用 `.node.ts` 后缀的文件,CSR 环境下会使用 `.ts` 后缀的文件。
|
@@ -6,7 +6,7 @@ sidebar_position: 2
|
|
6
6
|
|
7
7
|
**Modern.js 的构建能力由 [Modern.js Builder](https://modernjs.dev/builder) 提供。**
|
8
8
|
|
9
|
-
Modern.js Builder 是 Modern.js
|
9
|
+
Modern.js Builder 是 Modern.js 体系的核心组件之一,它是一个面向 Web 开发场景的构建引擎,可以脱离 Modern.js 被独立使用。Modern.js Builder 同时支持 webpack 和 Rspack 等多种打包工具,默认情况下使用最成熟的 webpack 进行打包。
|
10
10
|
|
11
11
|
## 构建架构
|
12
12
|
|
@@ -14,7 +14,7 @@ Modern.js Builder 是 Modern.js 体系的核心组件之一,它是一个面向
|
|
14
14
|
|
15
15
|
- 上层研发框架:Modern.js。
|
16
16
|
- 通用构建引擎:Modern.js Builder。
|
17
|
-
- 底层打包工具:webpack 和
|
17
|
+
- 底层打包工具:webpack 和 Rspack。
|
18
18
|
|
19
19
|
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/zq-uylkvT/ljhwZthlaukjlkulzlp/builder-layers-1117.png" style={{ maxWidth: '540px' }} />
|
20
20
|
|
@@ -10,7 +10,7 @@ sidebar_position: 3
|
|
10
10
|
|
11
11
|
1. [Autoprefixer](https://github.com/postcss/autoprefixer) 根据需要支持的浏览器范围,会自动为 CSS 规则添加需要的浏览器厂商前缀。Modern.js 默认支持的浏览器范围为:`['> 0.01%', 'not dead', 'not op_mini all']`。
|
12
12
|
|
13
|
-
:::info
|
13
|
+
:::info意
|
14
14
|
- 【支持的浏览器范围为:`> 0.01%`】是指浏览器市场份额大于 0.01%。
|
15
15
|
- `not dead` 是指不包含官方不再支持的浏览器和过去24个月没有更新的浏览器。
|
16
16
|
- `not op_mini all` 是指不包含 Opera Mini。
|
@@ -4,7 +4,7 @@ sidebar_position: 1
|
|
4
4
|
---
|
5
5
|
# 路由
|
6
6
|
|
7
|
-
Modern.js
|
7
|
+
Modern.js 的路由基于 [React Router 6](https://reactrouter.com/en/main),并提供了多种类型的路由模式。根据不同[入口](/docs/guides/concept/entries)类型,将路由分为三种模式,分别是**约定式路由**,**自控式路由**和**其他路由方案**。
|
8
8
|
|
9
9
|
:::note
|
10
10
|
本小节提到的路由,都是客户端路由,即 SPA 路由。
|
@@ -168,6 +168,33 @@ export default () => {
|
|
168
168
|
|
169
169
|
在 loader 中,params 会作为 [loader](/guides/basic-features/data-fetch#loader-函数) 的入参,通过 `params.xxx` 可以获取。
|
170
170
|
|
171
|
+
### 通配路由
|
172
|
+
|
173
|
+
如果在 routes 目录下创建 `$.tsx` 文件,该文件会作为通配路由组件,当没有匹配的路由时,会渲染该路由组件。
|
174
|
+
|
175
|
+
:::note
|
176
|
+
`$.tsx` 可以认为是一种特殊的 `page` 路由组件,当前目录下有 `layout` 组件时,`$.tsx`,会作为 `layout` 的子组件渲染。
|
177
|
+
:::
|
178
|
+
|
179
|
+
例如以下目录结构:
|
180
|
+
```
|
181
|
+
└── routes
|
182
|
+
├── $.tsx
|
183
|
+
├── blog
|
184
|
+
│ └── page.tsx
|
185
|
+
└── page.tsx
|
186
|
+
```
|
187
|
+
|
188
|
+
当访问任何匹配不到的路径时,都会渲染 `routes/$.tsx` 组件,同样,`$.tsx` 中可以使用 [useParams](/apis/app/runtime/router/#useparams) 捕获 url 的剩余部分。
|
189
|
+
```ts title="$.tsx"
|
190
|
+
import { useParams } from '@modern-js/runtime/router';
|
191
|
+
// 当 path 是 `/aaa/bbb` 时
|
192
|
+
const params = useParams();
|
193
|
+
params['*'] // => 'aaa/bbb'
|
194
|
+
```
|
195
|
+
|
196
|
+
`$.tsx` 可以加入到 `routes` 目录下的任意目录中,一个常见的使用示例是添加 `routes/$.tsx` 文件去定制任意层级的 404 页面。
|
197
|
+
|
171
198
|
### 无路径布局
|
172
199
|
|
173
200
|
当目录名以 \_\_ 开头时,对应的目录名不会转换为实际的路由路径,例如以下文件目录:
|