@modern-js/app-tools 3.9.2 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.js +54 -2
- package/dist/cjs/commands/build.js +1 -2
- package/dist/cjs/commands/deploy.js +1 -3
- package/dist/cjs/commands/index.js +4 -0
- package/dist/cjs/compat/hooks.js +0 -5
- package/dist/cjs/compat/index.js +0 -5
- package/dist/cjs/compat/utils.js +0 -5
- package/dist/cjs/index.js +15 -39
- package/dist/cjs/plugins/analyze/index.js +2 -2
- package/dist/cjs/plugins/analyze/utils.js +2 -3
- package/dist/cjs/plugins/initialize/index.js +3 -5
- package/dist/esm/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.mjs +54 -2
- package/dist/esm/commands/build.mjs +1 -2
- package/dist/esm/commands/deploy.mjs +1 -3
- package/dist/esm/commands/index.mjs +4 -0
- package/dist/esm/compat/hooks.mjs +0 -5
- package/dist/esm/compat/index.mjs +0 -5
- package/dist/esm/compat/utils.mjs +0 -5
- package/dist/esm/index.mjs +2 -10
- package/dist/esm/plugins/analyze/index.mjs +2 -2
- package/dist/esm/plugins/analyze/utils.mjs +2 -3
- package/dist/esm/plugins/initialize/index.mjs +3 -5
- package/dist/esm-node/builder/shared/bundlerPlugins/HtmlAsyncChunkPlugin.mjs +54 -2
- package/dist/esm-node/commands/build.mjs +1 -2
- package/dist/esm-node/commands/deploy.mjs +1 -3
- package/dist/esm-node/commands/index.mjs +4 -0
- package/dist/esm-node/compat/hooks.mjs +0 -5
- package/dist/esm-node/compat/index.mjs +0 -5
- package/dist/esm-node/compat/utils.mjs +0 -5
- package/dist/esm-node/index.mjs +2 -10
- package/dist/esm-node/plugins/analyze/index.mjs +2 -2
- package/dist/esm-node/plugins/analyze/utils.mjs +2 -3
- package/dist/esm-node/plugins/initialize/index.mjs +3 -5
- package/dist/types/index.d.ts +1 -3
- package/dist/types/plugins/analyze/utils.d.ts +1 -1
- package/dist/types/types/config/index.d.ts +0 -2
- package/dist/types/types/config/tools.d.ts +0 -8
- package/docs/apis/app/commands.md +2 -0
- package/docs/apis/app/hooks/api/lambda.md +2 -0
- package/docs/apis/app/hooks/config/favicon.md +2 -0
- package/docs/apis/app/hooks/config/html.md +2 -0
- package/docs/apis/app/hooks/config/icon.md +2 -0
- package/docs/apis/app/hooks/config/mock.md +2 -0
- package/docs/apis/app/hooks/config/public.md +2 -0
- package/docs/apis/app/hooks/config/upload.md +3 -3
- package/docs/apis/app/hooks/modern-config.md +2 -0
- package/docs/apis/app/hooks/server/server.md +2 -0
- package/docs/apis/app/hooks/shared.md +2 -0
- package/docs/apis/app/hooks/src/app.md +2 -0
- package/docs/apis/app/hooks/src/entry.md +2 -0
- package/docs/apis/app/hooks/src/entry.server.md +2 -0
- package/docs/apis/app/hooks/src/modern.runtime.md +2 -0
- package/docs/apis/app/hooks/src/routes.md +2 -0
- package/docs/apis/app/hooks/src/server.md +2 -0
- package/docs/apis/app/runtime/bff/use-hono-context.md +2 -0
- package/docs/apis/app/runtime/core/create-root.md +5 -1
- package/docs/apis/app/runtime/core/render.md +7 -2
- package/docs/apis/app/runtime/core/runtime-context.md +18 -16
- package/docs/apis/app/runtime/router/router.md +11 -6
- package/docs/apis/app/runtime/ssr/no-ssr.md +2 -0
- package/docs/apis/app/runtime/ssr/renderStreaming.md +2 -0
- package/docs/apis/app/runtime/ssr/renderString.md +2 -0
- package/docs/apis/app/runtime/ssr/requestHandler.md +2 -0
- package/docs/apis/app/runtime/utility/css-in-js.md +2 -0
- package/docs/apis/app/runtime/utility/head.md +2 -0
- package/docs/apis/app/runtime/utility/loadable.md +2 -0
- package/docs/community/blog/2022-0708-updates.md +2 -0
- package/docs/community/blog/2022-0910-updates.md +2 -0
- package/docs/community/blog/overview.md +2 -0
- package/docs/community/blog/v2-release-note.md +2 -0
- package/docs/community/blog/v3-release-note.md +18 -13
- package/docs/community/contributing-guide.md +17 -33
- package/docs/community/releases.md +2 -0
- package/docs/community/showcase.md +2 -0
- package/docs/community/team.md +2 -0
- package/docs/configure/app/bff/cross-project.md +2 -0
- package/docs/configure/app/bff/prefix.md +2 -0
- package/docs/configure/app/builder-plugins.md +2 -0
- package/docs/configure/app/dev/asset-prefix.md +2 -0
- package/docs/configure/app/dev/before-start-url.md +2 -0
- package/docs/configure/app/dev/client.md +2 -0
- package/docs/configure/app/dev/hmr.md +2 -0
- package/docs/configure/app/dev/host.md +2 -0
- package/docs/configure/app/dev/https.md +2 -0
- package/docs/configure/app/dev/lazy-compilation.md +19 -1
- package/docs/configure/app/dev/live-reload.md +2 -0
- package/docs/configure/app/dev/mock-dir.md +2 -0
- package/docs/configure/app/dev/progress-bar.md +2 -0
- package/docs/configure/app/dev/server.md +2 -0
- package/docs/configure/app/dev/setup-middlewares.md +2 -0
- package/docs/configure/app/dev/start-url.md +2 -0
- package/docs/configure/app/dev/watch-files.md +2 -0
- package/docs/configure/app/dev/write-to-disk.md +2 -0
- package/docs/configure/app/experiments/source-build.md +2 -0
- package/docs/configure/app/html/app-icon.md +2 -0
- package/docs/configure/app/html/crossorigin.md +2 -0
- package/docs/configure/app/html/favicon.md +2 -0
- package/docs/configure/app/html/inject.md +2 -0
- package/docs/configure/app/html/meta.md +2 -0
- package/docs/configure/app/html/mount-id.md +2 -0
- package/docs/configure/app/html/output-structure.md +2 -0
- package/docs/configure/app/html/script-loading.md +2 -0
- package/docs/configure/app/html/tags.md +2 -0
- package/docs/configure/app/html/template-parameters.md +2 -0
- package/docs/configure/app/html/template.md +2 -0
- package/docs/configure/app/html/title.md +2 -0
- package/docs/configure/app/output/asset-prefix.md +2 -0
- package/docs/configure/app/output/assets-retry.md +2 -0
- package/docs/configure/app/output/charset.md +2 -0
- package/docs/configure/app/output/clean-dist-path.md +2 -0
- package/docs/configure/app/output/convert-to-rem.md +2 -0
- package/docs/configure/app/output/copy.md +2 -0
- package/docs/configure/app/output/css-modules.md +3 -5
- package/docs/configure/app/output/data-uri-limit.md +2 -0
- package/docs/configure/app/output/disable-css-module-extension.md +2 -0
- package/docs/configure/app/output/disable-inline-runtime-chunk.md +2 -0
- package/docs/configure/app/output/disable-svgr.md +6 -0
- package/docs/configure/app/output/disable-ts-checker.md +2 -0
- package/docs/configure/app/output/dist-path.md +2 -0
- package/docs/configure/app/output/enable-asset-manifest.md +2 -0
- package/docs/configure/app/output/enable-css-module-tsdeclaration.md +2 -0
- package/docs/configure/app/output/enable-inline-route-manifests.md +2 -0
- package/docs/configure/app/output/externals.md +2 -0
- package/docs/configure/app/output/filename-hash.md +2 -0
- package/docs/configure/app/output/filename.md +2 -0
- package/docs/configure/app/output/inject-styles.md +2 -0
- package/docs/configure/app/output/inline-scripts.md +3 -2
- package/docs/configure/app/output/inline-styles.md +3 -2
- package/docs/configure/app/output/legal-comments.md +2 -0
- package/docs/configure/app/output/minify.md +2 -0
- package/docs/configure/app/output/override-browserslist.md +2 -0
- package/docs/configure/app/output/polyfill.md +2 -0
- package/docs/configure/app/output/source-map.md +2 -0
- package/docs/configure/app/output/split-route-chunks.md +3 -1
- package/docs/configure/app/output/ssg.md +2 -0
- package/docs/configure/app/output/ssgByEntries.md +2 -0
- package/docs/configure/app/output/svg-default-export.md +6 -0
- package/docs/configure/app/output/temp-dir.md +2 -0
- package/docs/configure/app/performance/build-cache.md +2 -0
- package/docs/configure/app/performance/chunk-split.md +3 -4
- package/docs/configure/app/performance/dns-prefetch.md +2 -0
- package/docs/configure/app/performance/preconnect.md +2 -0
- package/docs/configure/app/performance/prefetch.md +2 -0
- package/docs/configure/app/performance/preload.md +2 -0
- package/docs/configure/app/performance/print-file-size.md +2 -0
- package/docs/configure/app/performance/profile.md +2 -0
- package/docs/configure/app/performance/remove-console.md +2 -0
- package/docs/configure/app/performance/remove-moment-locale.md +2 -0
- package/docs/configure/app/plugins.md +2 -0
- package/docs/configure/app/resolve/alias-strategy.md +2 -0
- package/docs/configure/app/resolve/alias.md +2 -0
- package/docs/configure/app/resolve/condition-names.md +2 -0
- package/docs/configure/app/resolve/dedupe.md +2 -0
- package/docs/configure/app/resolve/extensions.md +2 -0
- package/docs/configure/app/runtime/0-intro.md +2 -0
- package/docs/configure/app/runtime/plugins.md +8 -4
- package/docs/configure/app/runtime/router.md +2 -0
- package/docs/configure/app/security/check-syntax.md +2 -0
- package/docs/configure/app/security/nonce.md +2 -0
- package/docs/configure/app/security/sri.md +2 -0
- package/docs/configure/app/server/base-url.md +2 -0
- package/docs/configure/app/server/port.md +2 -0
- package/docs/configure/app/server/public-routes.md +2 -0
- package/docs/configure/app/server/routes.md +2 -0
- package/docs/configure/app/server/rsc.md +2 -0
- package/docs/configure/app/server/ssr-by-entries.md +2 -0
- package/docs/configure/app/server/ssr.md +3 -1
- package/docs/configure/app/server/tsconfig-path.md +4 -2
- package/docs/configure/app/source/alias-strategy.md +2 -0
- package/docs/configure/app/source/alias.md +2 -0
- package/docs/configure/app/source/config-dir.md +2 -0
- package/docs/configure/app/source/decorators.md +2 -0
- package/docs/configure/app/source/define.md +2 -0
- package/docs/configure/app/source/disable-default-entries.md +2 -0
- package/docs/configure/app/source/enable-async-entry.md +2 -0
- package/docs/configure/app/source/enable-async-pre-entry.md +2 -0
- package/docs/configure/app/source/entries-dir.md +2 -0
- package/docs/configure/app/source/entries.md +2 -0
- package/docs/configure/app/source/exclude.md +2 -0
- package/docs/configure/app/source/global-vars.md +2 -0
- package/docs/configure/app/source/include.md +2 -0
- package/docs/configure/app/source/main-entry-name.md +2 -0
- package/docs/configure/app/source/pre-entry.md +2 -0
- package/docs/configure/app/source/react-compiler.md +2 -0
- package/docs/configure/app/source/transform-import.md +2 -0
- package/docs/configure/app/split-chunks.md +2 -0
- package/docs/configure/app/tools/autoprefixer.md +2 -0
- package/docs/configure/app/tools/bundler-chain.md +2 -0
- package/docs/configure/app/tools/css-extract.md +2 -0
- package/docs/configure/app/tools/css-loader.md +2 -0
- package/docs/configure/app/tools/dev-server.md +2 -0
- package/docs/configure/app/tools/html-plugin.md +2 -0
- package/docs/configure/app/tools/less.md +96 -19
- package/docs/configure/app/tools/lightningcss-loader.md +2 -0
- package/docs/configure/app/tools/minify-css.md +2 -0
- package/docs/configure/app/tools/postcss.md +2 -0
- package/docs/configure/app/tools/rspack.md +2 -0
- package/docs/configure/app/tools/sass.md +89 -18
- package/docs/configure/app/tools/style-loader.md +2 -0
- package/docs/configure/app/tools/svgr.md +91 -0
- package/docs/configure/app/tools/swc.md +2 -0
- package/docs/configure/app/tools/ts-checker.md +2 -0
- package/docs/configure/app/usage.md +3 -5
- package/docs/guides/advanced-features/bff/cross-project.md +6 -4
- package/docs/guides/advanced-features/bff/extend-server.md +2 -0
- package/docs/guides/advanced-features/bff/frameworks.md +2 -0
- package/docs/guides/advanced-features/bff/function.md +2 -0
- package/docs/guides/advanced-features/bff/operators.md +2 -0
- package/docs/guides/advanced-features/bff/sdk.md +2 -0
- package/docs/guides/advanced-features/bff/upload.md +2 -0
- package/docs/guides/advanced-features/bff.md +2 -0
- package/docs/guides/advanced-features/build-performance.md +2 -0
- package/docs/guides/advanced-features/compatibility.md +2 -0
- package/docs/guides/advanced-features/international/advanced.md +3 -1
- package/docs/guides/advanced-features/international/api.md +21 -13
- package/docs/guides/advanced-features/international/best-practices.md +17 -15
- package/docs/guides/advanced-features/international/configuration.md +3 -1
- package/docs/guides/advanced-features/international/locale-detection.md +15 -4
- package/docs/guides/advanced-features/international/quick-start.md +2 -0
- package/docs/guides/advanced-features/international/resource-loading.md +11 -7
- package/docs/guides/advanced-features/international/routing.md +5 -1
- package/docs/guides/advanced-features/international.md +2 -0
- package/docs/guides/advanced-features/low-level.md +2 -0
- package/docs/guides/advanced-features/page-performance/code-split.md +2 -0
- package/docs/guides/advanced-features/page-performance/inline-assets.md +2 -0
- package/docs/guides/advanced-features/page-performance/optimize-bundle.md +2 -0
- package/docs/guides/advanced-features/page-performance/react-compiler.md +2 -0
- package/docs/guides/advanced-features/server-monitor/logger.md +2 -0
- package/docs/guides/advanced-features/server-monitor/metrics.md +2 -0
- package/docs/guides/advanced-features/server-monitor/monitors.md +3 -3
- package/docs/guides/advanced-features/source-build.md +3 -1
- package/docs/guides/advanced-features/web-server.md +5 -3
- package/docs/guides/basic-features/alias.md +2 -0
- package/docs/guides/basic-features/css/css-in-js.md +2 -0
- package/docs/guides/basic-features/css/css-modules.md +2 -0
- package/docs/guides/basic-features/css/css.md +2 -0
- package/docs/guides/basic-features/css/tailwindcss.md +2 -0
- package/docs/guides/basic-features/data/data-cache.md +2 -0
- package/docs/guides/basic-features/data/data-fetch.md +3 -3
- package/docs/guides/basic-features/data/data-write.md +25 -28
- package/docs/guides/basic-features/debug/mock.md +4 -2
- package/docs/guides/basic-features/debug/proxy.md +2 -0
- package/docs/guides/basic-features/debug/rsdoctor.md +2 -0
- package/docs/guides/basic-features/debug/using-storybook.md +6 -4
- package/docs/guides/basic-features/deploy.md +2 -0
- package/docs/guides/basic-features/env-vars.md +2 -0
- package/docs/guides/basic-features/html.md +4 -3
- package/docs/guides/basic-features/output-files.md +3 -1
- package/docs/guides/basic-features/render/before-render.md +2 -0
- package/docs/guides/basic-features/render/overview.md +2 -0
- package/docs/guides/basic-features/render/rsc.md +12 -2
- package/docs/guides/basic-features/render/ssg.md +2 -0
- package/docs/guides/basic-features/render/ssr-cache.md +2 -0
- package/docs/guides/basic-features/render/ssr.md +10 -12
- package/docs/guides/basic-features/render/streaming-ssr.md +4 -1
- package/docs/guides/basic-features/routes/config-routes.md +54 -54
- package/docs/guides/basic-features/routes/routes.md +2 -0
- package/docs/guides/basic-features/static-assets/json-files.md +2 -0
- package/docs/guides/basic-features/static-assets/svg-assets.md +31 -17
- package/docs/guides/basic-features/static-assets/wasm-assets.md +2 -0
- package/docs/guides/basic-features/static-assets.md +2 -0
- package/docs/guides/basic-features/testing/playwright.md +8 -6
- package/docs/guides/basic-features/testing/rstest.md +7 -5
- package/docs/guides/concept/builder.md +2 -0
- package/docs/guides/concept/entries.md +2 -0
- package/docs/guides/concept/server.md +2 -0
- package/docs/guides/get-started/ai-coding-agents.md +5 -3
- package/docs/guides/get-started/glossary.md +2 -0
- package/docs/guides/get-started/introduction.md +2 -0
- package/docs/guides/get-started/quick-start.md +13 -5
- package/docs/guides/get-started/tech-stack.md +2 -0
- package/docs/guides/get-started/upgrade.md +2 -0
- package/docs/guides/topic-detail/module-federation/application.md +2 -0
- package/docs/guides/topic-detail/module-federation/deploy.md +4 -2
- package/docs/guides/topic-detail/module-federation/i18n.md +2 -0
- package/docs/guides/topic-detail/module-federation/introduce.md +2 -0
- package/docs/guides/topic-detail/module-federation/ssr.md +2 -0
- package/docs/guides/topic-detail/module-federation/usage.md +2 -0
- package/docs/guides/troubleshooting/builder.md +2 -0
- package/docs/guides/troubleshooting/cli.md +2 -0
- package/docs/guides/troubleshooting/dependencies.md +2 -0
- package/docs/guides/troubleshooting/hmr.md +2 -0
- package/docs/guides/upgrade/config.md +14 -0
- package/docs/guides/upgrade/entry.md +2 -0
- package/docs/guides/upgrade/other.md +2 -0
- package/docs/guides/upgrade/overview.md +2 -0
- package/docs/guides/upgrade/tailwindcss.md +2 -0
- package/docs/guides/upgrade/web-server.md +25 -6
- package/docs/index.md +2 -0
- package/docs/llms.txt +8 -7
- package/docs/plugin/cli-plugins/api.md +2 -0
- package/docs/plugin/cli-plugins/life-cycle.md +2 -0
- package/docs/plugin/introduction.md +12 -10
- package/docs/plugin/official/cli-plugins/plugin-bff.md +2 -0
- package/docs/plugin/official/cli-plugins/plugin-ssg.md +2 -0
- package/docs/plugin/official/cli-plugins/plugin-styled-components.md +2 -0
- package/docs/plugin/official/cli-plugins.md +2 -0
- package/docs/plugin/plugin-system.md +3 -3
- package/docs/plugin/runtime-plugins/api.md +2 -0
- package/docs/plugin/runtime-plugins/life-cycle.md +2 -0
- package/docs/plugin/server-plugins/api.md +2 -0
- package/docs/plugin/server-plugins/life-cycle.md +2 -0
- package/docs/tutorials/examples/csr-auth.md +2 -0
- package/docs/tutorials/foundations/introduction.md +2 -0
- package/lib/types.d.ts +0 -1
- package/package.json +18 -19
- package/{rslib.config.mts → rstack.config.mts} +4 -4
- package/dist/cjs/types/config/testing.js +0 -18
- package/dist/esm/types/config/testing.mjs +0 -0
- package/dist/esm-node/types/config/testing.mjs +0 -1
- package/dist/types/types/config/testing.d.ts +0 -8
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# tools.less
|
|
2
4
|
|
|
3
5
|
- **Type:** `Object | Function`
|
|
@@ -5,49 +7,78 @@
|
|
|
5
7
|
|
|
6
8
|
```js
|
|
7
9
|
const defaultOptions = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
lessLoaderOptions: {
|
|
11
|
+
lessOptions: {
|
|
12
|
+
javascriptEnabled: true,
|
|
13
|
+
},
|
|
14
|
+
// CSS Source Map enabled by default in development environment
|
|
15
|
+
sourceMap: isDev,
|
|
10
16
|
},
|
|
11
|
-
// CSS Source Map enabled by default in development environment
|
|
12
|
-
sourceMap: isDev,
|
|
13
17
|
};
|
|
14
18
|
```
|
|
15
19
|
|
|
16
|
-
|
|
20
|
+
`tools.less` modifies the options of [@rsbuild/plugin-less](https://rsbuild.rs/plugins/list/plugin-less). It accepts the full plugin options:
|
|
17
21
|
|
|
18
|
-
|
|
22
|
+
| Option | Description |
|
|
23
|
+
| ------------------- | --------------------------------------------------------------------------------------------------- |
|
|
24
|
+
| `lessLoaderOptions` | Options passed to [less-loader](https://github.com/webpack-contrib/less-loader), object or function |
|
|
25
|
+
| `include` | Files handled by less-loader, defaults to `/\.less$/` |
|
|
26
|
+
| `exclude` | Files that less-loader should skip |
|
|
27
|
+
| `parallel` | Whether to compile Less modules in worker threads, defaults to `false` |
|
|
19
28
|
|
|
20
|
-
|
|
29
|
+
### Modifying less-loader options
|
|
30
|
+
|
|
31
|
+
When `lessLoaderOptions` is an `Object`, it is merged with the default config through Object.assign in a shallow way. It should be noted that `lessOptions` is merged through deepMerge in a deep way. For example:
|
|
21
32
|
|
|
22
33
|
```js
|
|
23
34
|
export default {
|
|
24
35
|
tools: {
|
|
25
36
|
less: {
|
|
26
|
-
|
|
27
|
-
|
|
37
|
+
lessLoaderOptions: {
|
|
38
|
+
lessOptions: {
|
|
39
|
+
javascriptEnabled: false,
|
|
40
|
+
},
|
|
28
41
|
},
|
|
29
42
|
},
|
|
30
43
|
},
|
|
31
44
|
};
|
|
32
45
|
```
|
|
33
46
|
|
|
34
|
-
|
|
47
|
+
When `lessLoaderOptions` is a `Function`, the default config is passed as the first parameter, which can be directly modified or returned as the final result. The second parameter provides some utility functions that can be called directly. For example:
|
|
48
|
+
|
|
49
|
+
```js
|
|
50
|
+
export default {
|
|
51
|
+
tools: {
|
|
52
|
+
less: {
|
|
53
|
+
lessLoaderOptions(config) {
|
|
54
|
+
// Modify the config of lessOptions
|
|
55
|
+
config.lessOptions = {
|
|
56
|
+
javascriptEnabled: false,
|
|
57
|
+
};
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
};
|
|
62
|
+
```
|
|
35
63
|
|
|
36
|
-
|
|
64
|
+
### Parallel compilation
|
|
65
|
+
|
|
66
|
+
Less compilation is pure JavaScript and runs on the Node.js main thread by default. With `parallel` enabled, Less modules are compiled in a pool of worker threads, which shortens the build when a project has many Less files.
|
|
37
67
|
|
|
38
68
|
```js
|
|
39
69
|
export default {
|
|
40
70
|
tools: {
|
|
41
|
-
less
|
|
42
|
-
|
|
43
|
-
config.lessOptions = {
|
|
44
|
-
javascriptEnabled: false,
|
|
45
|
-
};
|
|
71
|
+
less: {
|
|
72
|
+
parallel: true,
|
|
46
73
|
},
|
|
47
74
|
},
|
|
48
75
|
};
|
|
49
76
|
```
|
|
50
77
|
|
|
78
|
+
:::tip
|
|
79
|
+
Options sent to worker threads must satisfy the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm). With `parallel` enabled, `lessLoaderOptions` therefore cannot contain functions, such as an `additionalData` function or a custom `implementation`.
|
|
80
|
+
:::
|
|
81
|
+
|
|
51
82
|
### Modifying Less Version
|
|
52
83
|
|
|
53
84
|
In some scenarios, if you need to use a specific version of Less instead of the built-in Less v4 in Modern.js, you can install the desired Less version in your project and set it up using the `implementation` option of the `less-loader`.
|
|
@@ -56,7 +87,9 @@ In some scenarios, if you need to use a specific version of Less instead of the
|
|
|
56
87
|
export default {
|
|
57
88
|
tools: {
|
|
58
89
|
less: {
|
|
59
|
-
|
|
90
|
+
lessLoaderOptions: {
|
|
91
|
+
implementation: require('less'),
|
|
92
|
+
},
|
|
60
93
|
},
|
|
61
94
|
},
|
|
62
95
|
};
|
|
@@ -73,8 +106,52 @@ Used to specify which files `less-loader` does not compile, You can pass in one
|
|
|
73
106
|
```js
|
|
74
107
|
export default {
|
|
75
108
|
tools: {
|
|
76
|
-
less
|
|
77
|
-
addExcludes
|
|
109
|
+
less: {
|
|
110
|
+
lessLoaderOptions(config, { addExcludes }) {
|
|
111
|
+
addExcludes(/node_modules/);
|
|
112
|
+
},
|
|
113
|
+
},
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
The plugin's `exclude` option is the recommended equivalent:
|
|
119
|
+
|
|
120
|
+
```js
|
|
121
|
+
export default {
|
|
122
|
+
tools: {
|
|
123
|
+
less: {
|
|
124
|
+
exclude: /node_modules/,
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
};
|
|
128
|
+
```
|
|
129
|
+
|
|
130
|
+
### Legacy form
|
|
131
|
+
|
|
132
|
+
:::warning Do not mix the two layers
|
|
133
|
+
As soon as an object contains a plugin-level key (`lessLoaderOptions`, `include`, `exclude`, ...), the whole object is parsed as plugin options and any loader option in it has no effect. For example, `lessOptions` in `tools.less: { parallel: true, lessOptions: { ... } }` is ignored and must be moved under `lessLoaderOptions`; a hint is printed in development.
|
|
134
|
+
:::
|
|
135
|
+
|
|
136
|
+
In earlier versions, `tools.less` took the less-loader options directly, e.g. `tools.less: { lessOptions: {} }` or `tools.less(config, { addExcludes }) {}`. This form still works: Modern.js wraps it into `lessLoaderOptions` and produces exactly the same config as before. A migration hint is printed in development, and the legacy form will be removed in the next major version.
|
|
137
|
+
|
|
138
|
+
```js
|
|
139
|
+
// legacy
|
|
140
|
+
export default {
|
|
141
|
+
tools: {
|
|
142
|
+
less: {
|
|
143
|
+
lessOptions: { javascriptEnabled: false },
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
// current
|
|
149
|
+
export default {
|
|
150
|
+
tools: {
|
|
151
|
+
less: {
|
|
152
|
+
lessLoaderOptions: {
|
|
153
|
+
lessOptions: { javascriptEnabled: false },
|
|
154
|
+
},
|
|
78
155
|
},
|
|
79
156
|
},
|
|
80
157
|
};
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# tools.sass
|
|
2
4
|
|
|
3
5
|
- **Type:** `Object | Function`
|
|
@@ -5,41 +7,64 @@
|
|
|
5
7
|
|
|
6
8
|
```js
|
|
7
9
|
const defaultOptions = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
+
sassLoaderOptions: {
|
|
11
|
+
// CSS Source Map enabled by default in development environment
|
|
12
|
+
sourceMap: isDev,
|
|
13
|
+
},
|
|
10
14
|
};
|
|
11
15
|
```
|
|
12
16
|
|
|
13
|
-
|
|
17
|
+
`tools.sass` modifies the options of [@rsbuild/plugin-sass](https://rsbuild.rs/plugins/list/plugin-sass). It accepts the full plugin options:
|
|
14
18
|
|
|
15
|
-
|
|
19
|
+
| Option | Description |
|
|
20
|
+
| ------------------- | --------------------------------------------------------------------------------------------------- |
|
|
21
|
+
| `sassLoaderOptions` | Options passed to [sass-loader](https://github.com/webpack-contrib/sass-loader), object or function |
|
|
22
|
+
| `include` | Files handled by sass-loader, defaults to `/\.s(?:a\|c)ss$/` |
|
|
23
|
+
| `exclude` | Files that sass-loader should skip |
|
|
24
|
+
| `rewriteUrls` | Whether to rewrite relative URLs in Sass files with resolve-url-loader, defaults to `true` |
|
|
16
25
|
|
|
17
|
-
|
|
26
|
+
### Modifying sass-loader options
|
|
18
27
|
|
|
19
|
-
For example:
|
|
28
|
+
When `sassLoaderOptions` is an `Object`, it is merged with the default config through Object.assign in a shallow way. It should be noted that `sassOptions` is merged through deepMerge in a deep way. For example:
|
|
20
29
|
|
|
21
30
|
```js
|
|
22
31
|
export default {
|
|
23
32
|
tools: {
|
|
24
33
|
sass: {
|
|
25
|
-
|
|
34
|
+
sassLoaderOptions: {
|
|
35
|
+
sourceMap: true,
|
|
36
|
+
},
|
|
26
37
|
},
|
|
27
38
|
},
|
|
28
39
|
};
|
|
29
40
|
```
|
|
30
41
|
|
|
31
|
-
|
|
42
|
+
When `sassLoaderOptions` is a `Function`, the default config is passed as the first parameter, which can be directly modified or returned as the final result. The second parameter provides some utility functions that can be called directly. For example:
|
|
43
|
+
|
|
44
|
+
```js
|
|
45
|
+
export default {
|
|
46
|
+
tools: {
|
|
47
|
+
sass: {
|
|
48
|
+
sassLoaderOptions(config) {
|
|
49
|
+
// Modify the additionalData config
|
|
50
|
+
config.additionalData = async (content, loaderContext) => {
|
|
51
|
+
// ...
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
};
|
|
57
|
+
```
|
|
32
58
|
|
|
33
|
-
|
|
59
|
+
### Disabling URL rewriting
|
|
60
|
+
|
|
61
|
+
By default, relative URLs in Sass files are rewritten by resolve-url-loader so that they resolve relative to the source file. If your project does not rely on this, turn it off to drop one loader from the chain:
|
|
34
62
|
|
|
35
63
|
```js
|
|
36
64
|
export default {
|
|
37
65
|
tools: {
|
|
38
|
-
sass
|
|
39
|
-
|
|
40
|
-
config.additionalData = async (content, loaderContext) => {
|
|
41
|
-
// ...
|
|
42
|
-
};
|
|
66
|
+
sass: {
|
|
67
|
+
rewriteUrls: false,
|
|
43
68
|
},
|
|
44
69
|
},
|
|
45
70
|
};
|
|
@@ -53,13 +78,15 @@ In some scenarios, if you need to use a specific version of Sass instead of the
|
|
|
53
78
|
export default {
|
|
54
79
|
tools: {
|
|
55
80
|
sass: {
|
|
56
|
-
|
|
81
|
+
sassLoaderOptions: {
|
|
82
|
+
implementation: require('sass'),
|
|
83
|
+
},
|
|
57
84
|
},
|
|
58
85
|
},
|
|
59
86
|
};
|
|
60
87
|
```
|
|
61
88
|
|
|
62
|
-
###
|
|
89
|
+
### Util Function
|
|
63
90
|
|
|
64
91
|
#### addExcludes
|
|
65
92
|
|
|
@@ -70,8 +97,52 @@ Used to specify which files `sass-loader` does not compile, You can pass in one
|
|
|
70
97
|
```js
|
|
71
98
|
export default {
|
|
72
99
|
tools: {
|
|
73
|
-
sass
|
|
74
|
-
addExcludes
|
|
100
|
+
sass: {
|
|
101
|
+
sassLoaderOptions(config, { addExcludes }) {
|
|
102
|
+
addExcludes(/node_modules/);
|
|
103
|
+
},
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
The plugin's `exclude` option is the recommended equivalent:
|
|
110
|
+
|
|
111
|
+
```js
|
|
112
|
+
export default {
|
|
113
|
+
tools: {
|
|
114
|
+
sass: {
|
|
115
|
+
exclude: /node_modules/,
|
|
116
|
+
},
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
### Legacy form
|
|
122
|
+
|
|
123
|
+
:::warning Do not mix the two layers
|
|
124
|
+
As soon as an object contains a plugin-level key (`sassLoaderOptions`, `include`, `exclude`, ...), the whole object is parsed as plugin options and any loader option in it has no effect. For example, `sassOptions` in `tools.sass: { rewriteUrls: false, sassOptions: { ... } }` is ignored and must be moved under `sassLoaderOptions`; a hint is printed in development.
|
|
125
|
+
:::
|
|
126
|
+
|
|
127
|
+
In earlier versions, `tools.sass` took the sass-loader options directly, e.g. `tools.sass: { sassOptions: {} }` or `tools.sass(config, { addExcludes }) {}`. This form still works: Modern.js wraps it into `sassLoaderOptions` and produces exactly the same config as before. A migration hint is printed in development, and the legacy form will be removed in the next major version.
|
|
128
|
+
|
|
129
|
+
```js
|
|
130
|
+
// legacy
|
|
131
|
+
export default {
|
|
132
|
+
tools: {
|
|
133
|
+
sass: {
|
|
134
|
+
sourceMap: true,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// current
|
|
140
|
+
export default {
|
|
141
|
+
tools: {
|
|
142
|
+
sass: {
|
|
143
|
+
sassLoaderOptions: {
|
|
144
|
+
sourceMap: true,
|
|
145
|
+
},
|
|
75
146
|
},
|
|
76
147
|
},
|
|
77
148
|
};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
3
|
+
# tools.svgr
|
|
4
|
+
|
|
5
|
+
- **Type:** `Object | Function | false`
|
|
6
|
+
- **Default:**
|
|
7
|
+
|
|
8
|
+
```js
|
|
9
|
+
const defaultOptions = {
|
|
10
|
+
mixedImport: true,
|
|
11
|
+
svgrOptions: {
|
|
12
|
+
exportType: 'named',
|
|
13
|
+
},
|
|
14
|
+
};
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
`tools.svgr` modifies the options of [@rsbuild/plugin-svgr](https://rsbuild.rs/plugins/list/plugin-svgr). It accepts the full plugin options. Set it to `false` to skip registering the SVGR plugin; all `.svg` files are then treated as static assets.
|
|
18
|
+
|
|
19
|
+
| Option | Description |
|
|
20
|
+
| ----------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
21
|
+
| `svgrOptions` | Options passed to [SVGR](https://react-svgr.com/docs/options/), such as `exportType`, `icon`, `svgoConfig` |
|
|
22
|
+
| `parallel` | Whether to transform SVG files in worker threads, defaults to `false` |
|
|
23
|
+
| `exclude` | SVG files that SVGR should skip |
|
|
24
|
+
| `excludeImporter` | Importer files whose SVG imports should skip SVGR |
|
|
25
|
+
| `query` | Query that triggers the SVGR transform, defaults to `/react/` |
|
|
26
|
+
| `mixedImport` | Whether a module may import both the URL and the React component, defaults to `true` |
|
|
27
|
+
|
|
28
|
+
### Merge rules
|
|
29
|
+
|
|
30
|
+
When `tools.svgr` is an `Object`, its top-level fields are merged with the defaults through Object.assign in a shallow way, and `svgrOptions` is merged one level deeper, so setting only `svgrOptions.icon` keeps the default `exportType`.
|
|
31
|
+
|
|
32
|
+
When `tools.svgr` is a `Function`, the default config is passed as the first parameter, which can be directly modified or returned as the final result. An array of objects and functions is also accepted and applied in order.
|
|
33
|
+
|
|
34
|
+
### Parallel transform
|
|
35
|
+
|
|
36
|
+
The SVGR transform is pure JavaScript and runs on the Node.js main thread by default. With many SVG files, enable `parallel` to move the transform into a pool of worker threads:
|
|
37
|
+
|
|
38
|
+
```js
|
|
39
|
+
export default {
|
|
40
|
+
tools: {
|
|
41
|
+
svgr: {
|
|
42
|
+
parallel: true,
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
:::tip
|
|
49
|
+
Options sent to worker threads must satisfy the [structured clone algorithm](https://developer.mozilla.org/en-US/docs/Web/API/Web_Workers_API/Structured_clone_algorithm). With `parallel` enabled, `svgrOptions` therefore cannot contain functions.
|
|
50
|
+
:::
|
|
51
|
+
|
|
52
|
+
### Changing the default export
|
|
53
|
+
|
|
54
|
+
`svgrOptions.exportType` controls what an SVG file exports by default: `'named'` exports the file URL by default and the React component as the named export `ReactComponent`; `'default'` exports the React component by default.
|
|
55
|
+
|
|
56
|
+
```js
|
|
57
|
+
export default {
|
|
58
|
+
tools: {
|
|
59
|
+
svgr: {
|
|
60
|
+
svgrOptions: {
|
|
61
|
+
exportType: 'default',
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
};
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
### Disabling SVGR
|
|
69
|
+
|
|
70
|
+
If you are sure that no SVG asset in your project is used as a React component, disable SVGR to improve build performance:
|
|
71
|
+
|
|
72
|
+
```js
|
|
73
|
+
export default {
|
|
74
|
+
tools: {
|
|
75
|
+
svgr: false,
|
|
76
|
+
},
|
|
77
|
+
};
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
### Relation to the legacy options
|
|
81
|
+
|
|
82
|
+
`tools.svgr` replaces the two deprecated options below. They still work today and will be removed in the next major version:
|
|
83
|
+
|
|
84
|
+
| Legacy option | Replacement |
|
|
85
|
+
| -------------------------------------- | -------------------------------------------------------- |
|
|
86
|
+
| `output.svgDefaultExport: 'component'` | `tools.svgr: { svgrOptions: { exportType: 'default' } }` |
|
|
87
|
+
| `output.svgDefaultExport: 'url'` | `tools.svgr: { svgrOptions: { exportType: 'named' } }` |
|
|
88
|
+
| `output.disableSvgr: true` | `tools.svgr: false` |
|
|
89
|
+
| `output.disableSvgr: false` | Default behavior, just remove it |
|
|
90
|
+
|
|
91
|
+
When both are set, `tools.svgr` wins: once `tools.svgr` is set explicitly, `output.disableSvgr` no longer applies, and `tools.svgr.svgrOptions.exportType` overrides the value derived from `output.svgDefaultExport`.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Configuration
|
|
2
4
|
|
|
3
5
|
There are three types of configurations in Modern.js: Compile configuration, Runtime configuration, and Server Runtime configuration.
|
|
@@ -265,11 +267,7 @@ import { defineConfig } from '@modern-js/app-tools';
|
|
|
265
267
|
import { xxPlugin } from '@modern-js/plugin-xx';
|
|
266
268
|
|
|
267
269
|
export default defineConfig({
|
|
268
|
-
plugins: [
|
|
269
|
-
xxPlugin({
|
|
270
|
-
/** Add parameters here */
|
|
271
|
-
}),
|
|
272
|
-
],
|
|
270
|
+
plugins: [xxPlugin({/** Add parameters here */})],
|
|
273
271
|
});
|
|
274
272
|
```
|
|
275
273
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Cross-Project Invocation
|
|
2
4
|
|
|
3
5
|
Based on the BFF architecture, Modern.js provides cross-project invocation capabilities, allowing BFF functions created in one project to be invoked by other projects through integrated calls, enabling function sharing and feature reuse across projects.
|
|
@@ -23,7 +25,7 @@ Ensure the current project has BFF enabled with API files defined under `api/lam
|
|
|
23
25
|
export default defineConfig({
|
|
24
26
|
bff: {
|
|
25
27
|
crossProject: true,
|
|
26
|
-
}
|
|
28
|
+
},
|
|
27
29
|
});
|
|
28
30
|
```
|
|
29
31
|
|
|
@@ -87,9 +89,9 @@ import { configure as innerConfigure } from '@modern-js/plugin-bff/client';
|
|
|
87
89
|
import axios from 'axios';
|
|
88
90
|
|
|
89
91
|
configure({
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
92
|
+
setDomain() {
|
|
93
|
+
return 'https://your-bff-api.com';
|
|
94
|
+
},
|
|
93
95
|
});
|
|
94
96
|
|
|
95
97
|
innerConfigure({
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Extend BFF Server
|
|
2
4
|
|
|
3
5
|
In some applications, developers may want to handle all BFF functions uniformly, such as authentication, logging, data processing, etc.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Runtime Framework
|
|
2
4
|
|
|
3
5
|
Modern.js uses [Hono.js](https://hono.dev/) as the BFF and Server runtime framework, so you can [extend BFF Server](/guides/advanced-features/bff/extend-server.md) based on the Hono.js ecosystem.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Basic Usage
|
|
2
4
|
|
|
3
5
|
In a Modern.js application, developers can define API files under the `api/lambda` directory and export API functions from these files. In the frontend code, these API functions can be directly invoked by importing the file, which initiates the API requests.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Creating Extensible BFF Functions
|
|
2
4
|
|
|
3
5
|
The previous section showed how to export a simple BFF function in a file. In more complex scenarios, each BFF function may need to do independent type validation, pre-logic, etc.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Extend Request SDK
|
|
2
4
|
|
|
3
5
|
The unified invocation of BFF functions is isomorphic in both CSR and SSR. The request SDK encapsulated by Modern.js relies on the [Fetch API](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API/Using_Fetch) on the browser side, and on [node-fetch](https://www.npmjs.com/package/node-fetch) on the server side. However, in actual business scenarios, additional processing may be required for requests or responses, such as:
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# File Upload
|
|
2
4
|
|
|
3
5
|
BFF combined with runtime framework provides file upload capabilities, supporting integrated calls and pure function manual calls.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# BFF
|
|
2
4
|
|
|
3
5
|
BFF (Backends for Frontends) is an architectural pattern primarily used to address issues of data aggregation in front-end and back-end collaboration. Under the BFF architecture, front-end applications do not communicate directly with backend services. Instead, they interact with backend services through a dedicated BFF middleware layer, custom-made for the front end.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Improve Build Performance
|
|
2
4
|
|
|
3
5
|
Modern.js optimizes build performance by default, but as the project becomes larger, you may encounter some build performance problems.
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# Advanced Usage
|
|
2
4
|
|
|
3
5
|
## SSR Scenarios
|
|
@@ -64,7 +66,7 @@ i18nPlugin({
|
|
|
64
66
|
localeDetectionByEntry: {
|
|
65
67
|
admin: {
|
|
66
68
|
localePathRedirect: false, // admin does not use path prefixes
|
|
67
|
-
languages: ['en'],
|
|
69
|
+
languages: ['en'], // admin only supports English
|
|
68
70
|
},
|
|
69
71
|
mobile: {
|
|
70
72
|
languages: ['zh', 'en', 'ja'], // mobile supports more languages
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
> For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt.
|
|
2
|
+
|
|
1
3
|
# API Reference
|
|
2
4
|
|
|
3
5
|
## useModernI18n
|
|
@@ -162,11 +164,11 @@ Type of the custom backend loader function:
|
|
|
162
164
|
type I18nSdkLoader = (options: I18nSdkLoadOptions) => Promise<Resources>;
|
|
163
165
|
|
|
164
166
|
interface I18nSdkLoadOptions {
|
|
165
|
-
lng?: string;
|
|
166
|
-
ns?: string;
|
|
167
|
-
lngs?: string[];
|
|
168
|
-
nss?: string[];
|
|
169
|
-
all?: boolean;
|
|
167
|
+
lng?: string; // Single language code
|
|
168
|
+
ns?: string; // Single namespace
|
|
169
|
+
lngs?: string[]; // Multiple language codes
|
|
170
|
+
nss?: string[]; // Multiple namespaces
|
|
171
|
+
all?: boolean; // Load all resources
|
|
170
172
|
}
|
|
171
173
|
|
|
172
174
|
type Resources = {
|
|
@@ -181,14 +183,14 @@ type Resources = {
|
|
|
181
183
|
```ts
|
|
182
184
|
interface LanguageDetectorOptions {
|
|
183
185
|
order?: string[];
|
|
184
|
-
lookupQuerystring?: string;
|
|
185
|
-
lookupCookie?: string;
|
|
186
|
-
lookupLocalStorage?: string;
|
|
186
|
+
lookupQuerystring?: string; // Default: 'lng'
|
|
187
|
+
lookupCookie?: string; // Default: 'i18next'
|
|
188
|
+
lookupLocalStorage?: string; // Default: 'i18nextLng'
|
|
187
189
|
lookupSession?: string;
|
|
188
|
-
lookupHeader?: string;
|
|
190
|
+
lookupHeader?: string; // Default: 'accept-language'
|
|
189
191
|
lookupFromPathIndex?: number; // Default: 0
|
|
190
192
|
caches?: false | string[];
|
|
191
|
-
cookieMinutes?: number;
|
|
193
|
+
cookieMinutes?: number; // Default: 525600 (1 year)
|
|
192
194
|
cookieExpirationDate?: Date;
|
|
193
195
|
cookieDomain?: string;
|
|
194
196
|
}
|
|
@@ -208,8 +210,8 @@ import { useTranslation } from 'react-i18next';
|
|
|
208
210
|
import { useModernI18n } from '@modern-js/plugin-i18n/runtime';
|
|
209
211
|
|
|
210
212
|
function App() {
|
|
211
|
-
const { t } = useTranslation();
|
|
212
|
-
const { language, changeLanguage } = useModernI18n();
|
|
213
|
+
const { t } = useTranslation(); // Translate text
|
|
214
|
+
const { language, changeLanguage } = useModernI18n(); // Switch language
|
|
213
215
|
|
|
214
216
|
return (
|
|
215
217
|
<div>
|
|
@@ -227,5 +229,11 @@ You can also get the i18next instance from `useModernI18n` and call capabilities
|
|
|
227
229
|
const { i18nInstance } = useModernI18n();
|
|
228
230
|
|
|
229
231
|
// Dynamically add translation resources.
|
|
230
|
-
i18nInstance.addResourceBundle(
|
|
232
|
+
i18nInstance.addResourceBundle(
|
|
233
|
+
'zh',
|
|
234
|
+
'translation',
|
|
235
|
+
{ key: 'Value' },
|
|
236
|
+
true,
|
|
237
|
+
true,
|
|
238
|
+
);
|
|
231
239
|
```
|