@modern-js/main-doc 3.9.3 → 3.10.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/docs/en/apis/app/hooks/api/lambda.mdx +2 -1
- package/docs/en/apis/app/hooks/config/html.mdx +1 -0
- package/docs/en/apis/app/hooks/config/mock.mdx +1 -0
- package/docs/en/apis/app/hooks/config/public.mdx +1 -0
- package/docs/en/apis/app/hooks/config/upload.mdx +2 -3
- package/docs/en/apis/app/hooks/modern-config.mdx +1 -0
- package/docs/en/apis/app/hooks/shared.mdx +1 -0
- package/docs/en/apis/app/hooks/src/modern.runtime.mdx +1 -0
- package/docs/en/apis/app/hooks/src/routes.mdx +1 -0
- package/docs/en/apis/app/hooks/src/server.mdx +2 -1
- package/docs/en/apis/app/runtime/bff/use-hono-context.mdx +1 -0
- package/docs/en/apis/app/runtime/core/create-root.mdx +4 -1
- package/docs/en/apis/app/runtime/core/render.mdx +6 -2
- package/docs/en/apis/app/runtime/core/runtime-context.mdx +17 -17
- package/docs/en/apis/app/runtime/router/router.mdx +9 -6
- package/docs/en/apis/app/runtime/ssr/no-ssr.mdx +1 -0
- package/docs/en/apis/app/runtime/utility/head.mdx +1 -0
- package/docs/en/apis/app/runtime/utility/loadable.mdx +1 -0
- package/docs/en/community/blog/v3-release-note.mdx +36 -27
- package/docs/en/community/contributing-guide.mdx +15 -33
- package/docs/en/components/default-browserslist.mdx +0 -1
- package/docs/en/components/deploy-command.mdx +1 -1
- package/docs/en/components/deploy.mdx +1 -1
- package/docs/en/components/entry-scan-logic.mdx +1 -1
- package/docs/en/components/init-app.mdx +9 -3
- package/docs/en/components/international/custom-instance-code.mdx +0 -1
- package/docs/en/components/micro-runtime-config.mdx +12 -9
- package/docs/en/components/nodeVersion.mdx +2 -2
- package/docs/en/components/rsc-deploy-tip.mdx +0 -1
- package/docs/en/components/ssr-monitor.mdx +1 -1
- package/docs/en/configure/app/bff/cross-project.mdx +2 -2
- package/docs/en/configure/app/bff/prefix.mdx +1 -1
- package/docs/en/configure/app/dev/lazy-compilation.mdx +17 -1
- package/docs/en/configure/app/dev/start-url.mdx +0 -1
- package/docs/en/configure/app/output/css-modules.mdx +1 -5
- package/docs/en/configure/app/output/dist-path.mdx +0 -1
- package/docs/en/configure/app/output/inline-scripts.mdx +1 -2
- package/docs/en/configure/app/output/inline-styles.mdx +1 -2
- package/docs/en/configure/app/output/split-route-chunks.mdx +1 -1
- package/docs/en/configure/app/output/ssg.mdx +1 -1
- package/docs/en/configure/app/output/ssgByEntries.mdx +1 -0
- package/docs/en/configure/app/performance/chunk-split.mdx +1 -4
- package/docs/en/configure/app/runtime/plugins.mdx +6 -4
- package/docs/en/configure/app/server/rsc.mdx +1 -1
- package/docs/en/configure/app/server/ssr.mdx +7 -8
- package/docs/en/configure/app/server/tsconfig-path.mdx +2 -2
- package/docs/en/configure/app/tools/less.mdx +5 -6
- package/docs/en/configure/app/tools/sass.mdx +5 -6
- package/docs/en/configure/app/tools/svgr.mdx +7 -7
- package/docs/en/configure/app/usage.mdx +1 -5
- package/docs/en/guides/advanced-features/bff/cross-project.mdx +5 -4
- package/docs/en/guides/advanced-features/compatibility.mdx +0 -1
- package/docs/en/guides/advanced-features/international/advanced.mdx +1 -1
- package/docs/en/guides/advanced-features/international/api.mdx +34 -28
- package/docs/en/guides/advanced-features/international/best-practices.mdx +15 -15
- package/docs/en/guides/advanced-features/international/configuration.mdx +37 -37
- package/docs/en/guides/advanced-features/international/locale-detection.mdx +37 -28
- package/docs/en/guides/advanced-features/international/resource-loading.mdx +19 -17
- package/docs/en/guides/advanced-features/international/routing.mdx +8 -6
- package/docs/en/guides/advanced-features/international.mdx +8 -8
- package/docs/en/guides/advanced-features/server-monitor/logger.mdx +5 -5
- package/docs/en/guides/advanced-features/server-monitor/metrics.mdx +8 -8
- package/docs/en/guides/advanced-features/server-monitor/monitors.mdx +1 -3
- package/docs/en/guides/advanced-features/source-build.mdx +1 -1
- package/docs/en/guides/advanced-features/web-server.mdx +3 -3
- package/docs/en/guides/basic-features/data/data-fetch.mdx +1 -3
- package/docs/en/guides/basic-features/data/data-write.mdx +24 -28
- package/docs/en/guides/basic-features/debug/mock.mdx +2 -2
- package/docs/en/guides/basic-features/debug/using-storybook.mdx +5 -6
- package/docs/en/guides/basic-features/html.mdx +2 -3
- package/docs/en/guides/basic-features/output-files.mdx +1 -1
- package/docs/en/guides/basic-features/render/overview.mdx +12 -12
- package/docs/en/guides/basic-features/render/rsc.mdx +16 -9
- package/docs/en/guides/basic-features/render/ssr-cache.mdx +5 -5
- package/docs/en/guides/basic-features/render/ssr.mdx +8 -12
- package/docs/en/guides/basic-features/render/streaming-ssr.mdx +2 -1
- package/docs/en/guides/basic-features/routes/config-routes.mdx +60 -59
- package/docs/en/guides/basic-features/testing/playwright.mdx +14 -8
- package/docs/en/guides/basic-features/testing/rstest.mdx +6 -4
- package/docs/en/guides/get-started/ai-coding-agents.mdx +6 -6
- package/docs/en/guides/get-started/introduction.mdx +0 -1
- package/docs/en/guides/topic-detail/module-federation/deploy.mdx +2 -2
- package/docs/en/guides/topic-detail/module-federation/introduce.mdx +0 -1
- package/docs/en/guides/upgrade/config.mdx +12 -0
- package/docs/en/guides/upgrade/other.mdx +4 -4
- package/docs/en/guides/upgrade/tailwindcss.mdx +0 -1
- package/docs/en/guides/upgrade/web-server.md +34 -17
- package/docs/en/index.md +1 -0
- package/docs/en/plugin/cli-plugins/api.mdx +23 -23
- package/docs/en/plugin/cli-plugins/life-cycle.mdx +2 -0
- package/docs/en/plugin/introduction.mdx +6 -6
- package/docs/en/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
- package/docs/en/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
- package/docs/en/plugin/plugin-system.mdx +19 -26
- package/docs/en/plugin/runtime-plugins/life-cycle.mdx +2 -0
- package/docs/en/plugin/server-plugins/api.mdx +11 -14
- package/docs/en/plugin/server-plugins/life-cycle.mdx +2 -0
- package/docs/zh/apis/app/hooks/api/lambda.mdx +1 -1
- package/docs/zh/apis/app/hooks/config/html.mdx +1 -0
- package/docs/zh/apis/app/hooks/config/mock.mdx +1 -0
- package/docs/zh/apis/app/hooks/config/public.mdx +1 -0
- package/docs/zh/apis/app/hooks/config/upload.mdx +2 -3
- package/docs/zh/apis/app/hooks/modern-config.mdx +1 -0
- package/docs/zh/apis/app/hooks/shared.mdx +1 -0
- package/docs/zh/apis/app/hooks/src/modern.runtime.mdx +1 -0
- package/docs/zh/apis/app/hooks/src/routes.mdx +1 -0
- package/docs/zh/apis/app/hooks/src/server.mdx +2 -1
- package/docs/zh/apis/app/runtime/bff/use-hono-context.mdx +1 -1
- package/docs/zh/apis/app/runtime/core/create-root.mdx +4 -1
- package/docs/zh/apis/app/runtime/core/render.mdx +6 -3
- package/docs/zh/apis/app/runtime/core/runtime-context.mdx +17 -17
- package/docs/zh/apis/app/runtime/router/router.mdx +10 -6
- package/docs/zh/apis/app/runtime/ssr/no-ssr.mdx +1 -0
- package/docs/zh/apis/app/runtime/utility/head.mdx +1 -0
- package/docs/zh/apis/app/runtime/utility/loadable.mdx +1 -0
- package/docs/zh/community/blog/v3-release-note.mdx +38 -29
- package/docs/zh/community/contributing-guide.mdx +16 -34
- package/docs/zh/components/default-browserslist.mdx +0 -1
- package/docs/zh/components/deploy-command.mdx +1 -1
- package/docs/zh/components/deploy.mdx +1 -1
- package/docs/zh/components/entry-scan-logic.mdx +1 -1
- package/docs/zh/components/init-app.mdx +9 -3
- package/docs/zh/components/international/custom-instance-code.mdx +0 -1
- package/docs/zh/components/international/install-command.mdx +0 -1
- package/docs/zh/components/micro-runtime-config.mdx +12 -9
- package/docs/zh/components/nodeVersion.mdx +2 -2
- package/docs/zh/components/rsc-deploy-tip.mdx +0 -1
- package/docs/zh/components/ssr-monitor.mdx +1 -1
- package/docs/zh/configure/app/bff/cross-project.mdx +2 -2
- package/docs/zh/configure/app/bff/prefix.mdx +1 -1
- package/docs/zh/configure/app/dev/lazy-compilation.mdx +17 -1
- package/docs/zh/configure/app/html/crossorigin.mdx +0 -1
- package/docs/zh/configure/app/html/favicon.mdx +0 -1
- package/docs/zh/configure/app/output/convert-to-rem.mdx +0 -1
- package/docs/zh/configure/app/output/css-modules.mdx +1 -5
- package/docs/zh/configure/app/output/inline-scripts.mdx +1 -2
- package/docs/zh/configure/app/output/inline-styles.mdx +1 -2
- package/docs/zh/configure/app/output/source-map.mdx +0 -2
- package/docs/zh/configure/app/output/split-route-chunks.mdx +1 -1
- package/docs/zh/configure/app/output/ssg.mdx +1 -0
- package/docs/zh/configure/app/output/ssgByEntries.mdx +1 -1
- package/docs/zh/configure/app/performance/chunk-split.mdx +1 -4
- package/docs/zh/configure/app/resolve/dedupe.mdx +0 -1
- package/docs/zh/configure/app/runtime/plugins.mdx +6 -4
- package/docs/zh/configure/app/server/rsc.mdx +1 -1
- package/docs/zh/configure/app/server/ssr.mdx +6 -7
- package/docs/zh/configure/app/server/tsconfig-path.mdx +2 -2
- package/docs/zh/configure/app/tools/less.mdx +6 -7
- package/docs/zh/configure/app/tools/sass.mdx +6 -7
- package/docs/zh/configure/app/tools/svgr.mdx +11 -11
- package/docs/zh/configure/app/usage.mdx +1 -5
- package/docs/zh/guides/advanced-features/bff.mdx +1 -0
- package/docs/zh/guides/advanced-features/international/advanced.mdx +1 -1
- package/docs/zh/guides/advanced-features/international/api.mdx +28 -27
- package/docs/zh/guides/advanced-features/international/best-practices.mdx +15 -15
- package/docs/zh/guides/advanced-features/international/configuration.mdx +38 -36
- package/docs/zh/guides/advanced-features/international/locale-detection.mdx +37 -28
- package/docs/zh/guides/advanced-features/international/resource-loading.mdx +20 -16
- package/docs/zh/guides/advanced-features/international/routing.mdx +6 -4
- package/docs/zh/guides/advanced-features/international.mdx +9 -9
- package/docs/zh/guides/advanced-features/server-monitor/logger.mdx +4 -6
- package/docs/zh/guides/advanced-features/server-monitor/metrics.mdx +9 -10
- package/docs/zh/guides/advanced-features/source-build.mdx +1 -1
- package/docs/zh/guides/advanced-features/web-server.mdx +3 -3
- package/docs/zh/guides/basic-features/data/data-fetch.mdx +1 -3
- package/docs/zh/guides/basic-features/data/data-write.mdx +25 -31
- package/docs/zh/guides/basic-features/debug/mock.mdx +2 -2
- package/docs/zh/guides/basic-features/debug/using-storybook.mdx +5 -5
- package/docs/zh/guides/basic-features/env-vars.mdx +0 -1
- package/docs/zh/guides/basic-features/html.mdx +2 -3
- package/docs/zh/guides/basic-features/render/overview.mdx +12 -13
- package/docs/zh/guides/basic-features/render/rsc.mdx +16 -9
- package/docs/zh/guides/basic-features/render/ssr.mdx +8 -17
- package/docs/zh/guides/basic-features/routes/config-routes.mdx +61 -59
- package/docs/zh/guides/basic-features/testing/playwright.mdx +15 -10
- package/docs/zh/guides/basic-features/testing/rstest.mdx +6 -4
- package/docs/zh/guides/get-started/ai-coding-agents.mdx +7 -7
- package/docs/zh/guides/topic-detail/module-federation/deploy.mdx +2 -2
- package/docs/zh/guides/upgrade/config.mdx +12 -0
- package/docs/zh/guides/upgrade/other.md +4 -11
- package/docs/zh/guides/upgrade/overview.mdx +1 -4
- package/docs/zh/guides/upgrade/tailwindcss.mdx +0 -1
- package/docs/zh/guides/upgrade/web-server.md +34 -19
- package/docs/zh/index.md +1 -0
- package/docs/zh/plugin/cli-plugins/api.mdx +24 -24
- package/docs/zh/plugin/cli-plugins/life-cycle.mdx +2 -0
- package/docs/zh/plugin/introduction.mdx +6 -6
- package/docs/zh/plugin/official/cli-plugins/plugin-bff.mdx +1 -1
- package/docs/zh/plugin/official/cli-plugins/plugin-ssg.mdx +1 -1
- package/docs/zh/plugin/plugin-system.mdx +19 -26
- package/docs/zh/plugin/runtime-plugins/life-cycle.mdx +2 -0
- package/docs/zh/plugin/server-plugins/api.mdx +11 -14
- package/docs/zh/plugin/server-plugins/life-cycle.mdx +2 -0
- package/package.json +11 -13
- package/{rspress.config.ts → rstack.config.mts} +7 -10
- package/src/components/Footer/styles.module.scss +1 -1
- package/src/components/SolutionCards/index.module.scss +3 -1
|
@@ -7,7 +7,7 @@ title: crossProject
|
|
|
7
7
|
- **Type:** `boolean`
|
|
8
8
|
- **Default:** `false`
|
|
9
9
|
|
|
10
|
-
import EnableBFFCaution from
|
|
10
|
+
import EnableBFFCaution from '@site-docs-en/components/enable-bff-caution';
|
|
11
11
|
|
|
12
12
|
<EnableBFFCaution />
|
|
13
13
|
|
|
@@ -21,4 +21,4 @@ export default defineConfig({
|
|
|
21
21
|
});
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
For detailed configuration and usage of BFF cross-project invocation, please refer to the [BFF Cross-Project Invocation Guide](/guides/advanced-features/bff/cross-project.html).
|
|
24
|
+
For detailed configuration and usage of BFF cross-project invocation, please refer to the [BFF Cross-Project Invocation Guide](/guides/advanced-features/bff/cross-project.html).
|
|
@@ -33,10 +33,26 @@ type LazyCompilationOptions =
|
|
|
33
33
|
};
|
|
34
34
|
```
|
|
35
35
|
|
|
36
|
-
- **Default:**
|
|
36
|
+
- **Default:** depends on how the application renders:
|
|
37
|
+
- Pure CSR and streaming SSR applications: `{ imports: true, entries: false }`, which compiles dynamic imports on demand;
|
|
38
|
+
- Applications using string SSR (including any entry in `server.ssrByEntries` using string SSR), RSC or SSG: `false`.
|
|
37
39
|
|
|
38
40
|
Enable lazy compilation (compilation on demand), implemented based on Rspack's [lazy compilation](https://rspack.rs/guide/features/lazy-compilation) feature.
|
|
39
41
|
|
|
42
|
+
This option only takes effect in the dev server and does not affect production build output. When enabled for streaming SSR applications, route components are still compiled eagerly so that first-screen JS/CSS injection stays correct.
|
|
43
|
+
|
|
44
|
+
An explicitly configured `dev.lazyCompilation` always takes precedence over the default. To disable it:
|
|
45
|
+
|
|
46
|
+
```ts
|
|
47
|
+
import { defineConfig } from '@modern-js/app-tools';
|
|
48
|
+
|
|
49
|
+
export default defineConfig({
|
|
50
|
+
dev: {
|
|
51
|
+
lazyCompilation: false,
|
|
52
|
+
},
|
|
53
|
+
});
|
|
54
|
+
```
|
|
55
|
+
|
|
40
56
|
import RsbuildLink from '@site/src/components/RsbuildLink';
|
|
41
57
|
|
|
42
58
|
:::info
|
|
@@ -17,11 +17,7 @@ type CssModules = {
|
|
|
17
17
|
resourceFragment: string,
|
|
18
18
|
) => boolean);
|
|
19
19
|
exportLocalsConvention?:
|
|
20
|
-
| '
|
|
21
|
-
| 'camelCase'
|
|
22
|
-
| 'camelCaseOnly'
|
|
23
|
-
| 'dashes'
|
|
24
|
-
| 'dashesOnly';
|
|
20
|
+
'asIs' | 'camelCase' | 'camelCaseOnly' | 'dashes' | 'dashesOnly';
|
|
25
21
|
exportGlobals?: boolean;
|
|
26
22
|
localIdentName?: string;
|
|
27
23
|
mode?:
|
|
@@ -20,6 +20,7 @@ The SSG feature is closely related to routing. It is recommended to understand t
|
|
|
20
20
|
:::
|
|
21
21
|
|
|
22
22
|
:::info
|
|
23
|
+
|
|
23
24
|
- Use `output.ssg` for single-entry apps.
|
|
24
25
|
- For multi-entry apps, prefer `output.ssgByEntries`.
|
|
25
26
|
- If `output.ssg` is `true` and `output.ssgByEntries` is not set, all routes under all entries are treated as SSG routes.
|
|
@@ -82,4 +83,3 @@ export default defineConfig({
|
|
|
82
83
|
},
|
|
83
84
|
});
|
|
84
85
|
```
|
|
85
|
-
|
|
@@ -10,6 +10,7 @@ title: ssgByEntries
|
|
|
10
10
|
Configure SSG per entry for multi-entry applications.
|
|
11
11
|
|
|
12
12
|
:::info
|
|
13
|
+
|
|
13
14
|
- Use `output.ssg` for single-entry apps.
|
|
14
15
|
- For multi-entry apps, prefer `output.ssgByEntries`.
|
|
15
16
|
- If `output.ssg` is `true` and `output.ssgByEntries` is not set, all routes under all entries are treated as SSG routes.
|
|
@@ -14,10 +14,7 @@ type ForceSplitting = RegExp[] | Record<string, RegExp>;
|
|
|
14
14
|
|
|
15
15
|
interface BaseChunkSplit {
|
|
16
16
|
strategy?:
|
|
17
|
-
| 'split-by-
|
|
18
|
-
| 'split-by-experience'
|
|
19
|
-
| 'all-in-one'
|
|
20
|
-
| 'single-vendor';
|
|
17
|
+
'split-by-module' | 'split-by-experience' | 'all-in-one' | 'single-vendor';
|
|
21
18
|
override?: SplitChunks;
|
|
22
19
|
forceSplitting?: ForceSplitting;
|
|
23
20
|
}
|
|
@@ -50,9 +50,11 @@ import { defineRuntimeConfig } from '@modern-js/runtime';
|
|
|
50
50
|
import { myPlugin } from './config/plugin/myPlugin';
|
|
51
51
|
|
|
52
52
|
export default defineRuntimeConfig({
|
|
53
|
-
plugins: [
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
53
|
+
plugins: [
|
|
54
|
+
myPlugin({
|
|
55
|
+
foo: 1,
|
|
56
|
+
bar: 2,
|
|
57
|
+
}),
|
|
58
|
+
],
|
|
57
59
|
});
|
|
58
60
|
```
|
|
@@ -21,10 +21,10 @@ export default defineConfig({
|
|
|
21
21
|
|
|
22
22
|
:::tip Prerequisites
|
|
23
23
|
Before enabling RSC, ensure:
|
|
24
|
+
|
|
24
25
|
1. React and React DOM are upgraded to version 19 (recommended 19.2.4 or above)
|
|
25
26
|
2. Install the `react-server-dom-rspack@0.0.2` dependency
|
|
26
27
|
|
|
27
28
|
:::
|
|
28
29
|
|
|
29
30
|
For more information about using RSC, see the [React Server Components guide](/guides/basic-features/render/rsc).
|
|
30
|
-
|
|
@@ -25,13 +25,12 @@ export default defineConfig({
|
|
|
25
25
|
|
|
26
26
|
When the value type is `Object`, the following properties can be configured:
|
|
27
27
|
|
|
28
|
-
| Name | Type
|
|
29
|
-
|
|
|
30
|
-
| mode
|
|
31
|
-
| forceCSR
|
|
32
|
-
| unsafeHeaders
|
|
33
|
-
| loaderFailureMode| `clientRender \| errorBoundary`
|
|
34
|
-
|
|
28
|
+
| Name | Type | Default | Description |
|
|
29
|
+
| ----------------- | ------------------------------- | --------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
30
|
+
| mode | `string` | `stream` | which defaults to using streaming rendering. Configure `string` to use `renderToString` for rendering |
|
|
31
|
+
| forceCSR | `boolean` | `false` | which is off by default for forcing CSR rendering. Configure `true` to force CSR by adding `?csr=true` or adding `x-modern-ssr-fallback` header when accessing the page |
|
|
32
|
+
| unsafeHeaders | `string[]` | `[]` | For safety reasons, Modern.js does not add excessive content to SSR_DATA. Developers can use this configuration to specify the headers that need to be injected |
|
|
33
|
+
| loaderFailureMode | `clientRender \| errorBoundary` | `errorBoundary` | The default configuration is `'errorBoundary'`, when an error occurs in [data loader](/en/guides/basic-features/data/data-fetch.html#data-loader-recommended), it will default to rendering the [`Error`](/guides/basic-features/routes/routes#error-handling) component of the route. When configured as `'clientRender'`, if a loader throws an error, it switch to client-side rendering,you can use it with [Client Loader](/en/guides/basic-features/data/data-fetch.html#client-loader) |
|
|
35
34
|
|
|
36
35
|
```ts title="modern.config.ts"
|
|
37
36
|
export default defineConfig({
|
|
@@ -39,7 +38,7 @@ export default defineConfig({
|
|
|
39
38
|
ssr: {
|
|
40
39
|
forceCSR: true,
|
|
41
40
|
mode: 'stream',
|
|
42
|
-
unsafeHeaders: ['User-Agent']
|
|
41
|
+
unsafeHeaders: ['User-Agent'],
|
|
43
42
|
},
|
|
44
43
|
},
|
|
45
44
|
});
|
|
@@ -40,9 +40,9 @@ Add `<appDirectory>/tsconfig.server.json`:
|
|
|
40
40
|
"types": ["node"],
|
|
41
41
|
"esModuleInterop": true,
|
|
42
42
|
"experimentalDecorators": true,
|
|
43
|
-
"emitDecoratorMetadata": true
|
|
43
|
+
"emitDecoratorMetadata": true,
|
|
44
44
|
},
|
|
45
|
-
"include": ["api", "shared", "server", "config", "modern.config.ts"]
|
|
45
|
+
"include": ["api", "shared", "server", "config", "modern.config.ts"],
|
|
46
46
|
}
|
|
47
47
|
```
|
|
48
48
|
|
|
@@ -21,12 +21,12 @@ const defaultOptions = {
|
|
|
21
21
|
|
|
22
22
|
`tools.less` modifies the options of [@rsbuild/plugin-less](https://rsbuild.rs/plugins/list/plugin-less). It accepts the full plugin options:
|
|
23
23
|
|
|
24
|
-
| Option | Description
|
|
25
|
-
| ------------------- |
|
|
24
|
+
| Option | Description |
|
|
25
|
+
| ------------------- | --------------------------------------------------------------------------------------------------- |
|
|
26
26
|
| `lessLoaderOptions` | Options passed to [less-loader](https://github.com/webpack-contrib/less-loader), object or function |
|
|
27
|
-
| `include` | Files handled by less-loader, defaults to `/\.less$/`
|
|
28
|
-
| `exclude` | Files that less-loader should skip
|
|
29
|
-
| `parallel` | Whether to compile Less modules in worker threads, defaults to `false`
|
|
27
|
+
| `include` | Files handled by less-loader, defaults to `/\.less$/` |
|
|
28
|
+
| `exclude` | Files that less-loader should skip |
|
|
29
|
+
| `parallel` | Whether to compile Less modules in worker threads, defaults to `false` |
|
|
30
30
|
|
|
31
31
|
### Modifying less-loader options
|
|
32
32
|
|
|
@@ -135,7 +135,6 @@ export default {
|
|
|
135
135
|
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.
|
|
136
136
|
:::
|
|
137
137
|
|
|
138
|
-
|
|
139
138
|
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.
|
|
140
139
|
|
|
141
140
|
```js
|
|
@@ -18,12 +18,12 @@ const defaultOptions = {
|
|
|
18
18
|
|
|
19
19
|
`tools.sass` modifies the options of [@rsbuild/plugin-sass](https://rsbuild.rs/plugins/list/plugin-sass). It accepts the full plugin options:
|
|
20
20
|
|
|
21
|
-
| Option | Description
|
|
22
|
-
| ------------------- |
|
|
21
|
+
| Option | Description |
|
|
22
|
+
| ------------------- | --------------------------------------------------------------------------------------------------- |
|
|
23
23
|
| `sassLoaderOptions` | Options passed to [sass-loader](https://github.com/webpack-contrib/sass-loader), object or function |
|
|
24
|
-
| `include` | Files handled by sass-loader, defaults to `/\.s(?:a
|
|
25
|
-
| `exclude` | Files that sass-loader should skip
|
|
26
|
-
| `rewriteUrls` | Whether to rewrite relative URLs in Sass files with resolve-url-loader, defaults to `true`
|
|
24
|
+
| `include` | Files handled by sass-loader, defaults to `/\.s(?:a\|c)ss$/` |
|
|
25
|
+
| `exclude` | Files that sass-loader should skip |
|
|
26
|
+
| `rewriteUrls` | Whether to rewrite relative URLs in Sass files with resolve-url-loader, defaults to `true` |
|
|
27
27
|
|
|
28
28
|
### Modifying sass-loader options
|
|
29
29
|
|
|
@@ -126,7 +126,6 @@ export default {
|
|
|
126
126
|
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.
|
|
127
127
|
:::
|
|
128
128
|
|
|
129
|
-
|
|
130
129
|
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.
|
|
131
130
|
|
|
132
131
|
```js
|
|
@@ -18,14 +18,14 @@ const defaultOptions = {
|
|
|
18
18
|
|
|
19
19
|
`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.
|
|
20
20
|
|
|
21
|
-
| Option | Description
|
|
22
|
-
| ----------------- |
|
|
21
|
+
| Option | Description |
|
|
22
|
+
| ----------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
23
23
|
| `svgrOptions` | Options passed to [SVGR](https://react-svgr.com/docs/options/), such as `exportType`, `icon`, `svgoConfig` |
|
|
24
|
-
| `parallel` | Whether to transform SVG files in worker threads, defaults to `false`
|
|
25
|
-
| `exclude` | SVG files that SVGR should skip
|
|
26
|
-
| `excludeImporter` | Importer files whose SVG imports should skip SVGR
|
|
27
|
-
| `query` | Query that triggers the SVGR transform, defaults to `/react/`
|
|
28
|
-
| `mixedImport` | Whether a module may import both the URL and the React component, defaults to `true`
|
|
24
|
+
| `parallel` | Whether to transform SVG files in worker threads, defaults to `false` |
|
|
25
|
+
| `exclude` | SVG files that SVGR should skip |
|
|
26
|
+
| `excludeImporter` | Importer files whose SVG imports should skip SVGR |
|
|
27
|
+
| `query` | Query that triggers the SVGR transform, defaults to `/react/` |
|
|
28
|
+
| `mixedImport` | Whether a module may import both the URL and the React component, defaults to `true` |
|
|
29
29
|
|
|
30
30
|
### Merge rules
|
|
31
31
|
|
|
@@ -265,11 +265,7 @@ import { defineConfig } from '@modern-js/app-tools';
|
|
|
265
265
|
import { xxPlugin } from '@modern-js/plugin-xx';
|
|
266
266
|
|
|
267
267
|
export default defineConfig({
|
|
268
|
-
plugins: [
|
|
269
|
-
xxPlugin({
|
|
270
|
-
/** Add parameters here */
|
|
271
|
-
}),
|
|
272
|
-
],
|
|
268
|
+
plugins: [xxPlugin({/** Add parameters here */})],
|
|
273
269
|
});
|
|
274
270
|
```
|
|
275
271
|
|
|
@@ -9,6 +9,7 @@ Cross-project invocation consists of **producer** and **consumer** sides. The pr
|
|
|
9
9
|
|
|
10
10
|
Enable cross-project invocation via configuration. Projects with BFF capabilities enabled can act as BFF producers, or you can create standalone BFF applications.
|
|
11
11
|
When executing `dev` or `build`, the following artifacts for consumers will be automatically generated:
|
|
12
|
+
|
|
12
13
|
- API functions under the `dist/client` directory
|
|
13
14
|
- Runtime configuration functions under the `dist/runtime` directory
|
|
14
15
|
- Interface exports defined in `exports` field of `package.json`
|
|
@@ -24,7 +25,7 @@ Ensure the current project has BFF enabled with API files defined under `api/lam
|
|
|
24
25
|
export default defineConfig({
|
|
25
26
|
bff: {
|
|
26
27
|
crossProject: true,
|
|
27
|
-
}
|
|
28
|
+
},
|
|
28
29
|
});
|
|
29
30
|
```
|
|
30
31
|
|
|
@@ -88,9 +89,9 @@ import { configure as innerConfigure } from '@modern-js/plugin-bff/client';
|
|
|
88
89
|
import axios from 'axios';
|
|
89
90
|
|
|
90
91
|
configure({
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
setDomain() {
|
|
93
|
+
return 'https://your-bff-api.com';
|
|
94
|
+
},
|
|
94
95
|
});
|
|
95
96
|
|
|
96
97
|
innerConfigure({
|
|
@@ -18,7 +18,6 @@ import DefaultBrowserslist from '@site-docs/components/default-browserslist';
|
|
|
18
18
|
|
|
19
19
|
<DefaultBrowserslist />
|
|
20
20
|
|
|
21
|
-
|
|
22
21
|
When the `overrideBrowserslist` configuration is not specified in the project, this `.browserslistrc` file will take effect.
|
|
23
22
|
|
|
24
23
|
### Method 2: Configure via package.json
|
|
@@ -68,7 +68,7 @@ i18nPlugin({
|
|
|
68
68
|
localeDetectionByEntry: {
|
|
69
69
|
admin: {
|
|
70
70
|
localePathRedirect: false, // admin does not use path prefixes
|
|
71
|
-
languages: ['en'],
|
|
71
|
+
languages: ['en'], // admin only supports English
|
|
72
72
|
},
|
|
73
73
|
mobile: {
|
|
74
74
|
languages: ['zh', 'en', 'ja'], // mobile supports more languages
|
|
@@ -10,14 +10,14 @@ title: API Reference
|
|
|
10
10
|
|
|
11
11
|
### Return Value
|
|
12
12
|
|
|
13
|
-
| Field
|
|
14
|
-
|
|
|
15
|
-
| `language`
|
|
16
|
-
| `changeLanguage`
|
|
17
|
-
| `supportedLanguages`
|
|
18
|
-
| `isLanguageSupported` | `(lang: string) => boolean`
|
|
19
|
-
| `isResourcesReady`
|
|
20
|
-
| `i18nInstance`
|
|
13
|
+
| Field | Type | Description |
|
|
14
|
+
| --------------------- | --------------------------------- | ---------------------------------------------------------------------------- |
|
|
15
|
+
| `language` | `string` | Current language code |
|
|
16
|
+
| `changeLanguage` | `(lang: string) => Promise<void>` | Switches language |
|
|
17
|
+
| `supportedLanguages` | `string[]` | Supported language list, from `localeDetection.languages` |
|
|
18
|
+
| `isLanguageSupported` | `(lang: string) => boolean` | Checks whether a language is in the supported list |
|
|
19
|
+
| `isResourcesReady` | `boolean` | Whether translation resources for the current language have finished loading |
|
|
20
|
+
| `i18nInstance` | `I18nInstance` | i18next instance for advanced scenarios |
|
|
21
21
|
|
|
22
22
|
### Basic Usage
|
|
23
23
|
|
|
@@ -85,13 +85,13 @@ A route link component with a locale prefix.
|
|
|
85
85
|
|
|
86
86
|
### Props
|
|
87
87
|
|
|
88
|
-
| Prop
|
|
89
|
-
|
|
|
90
|
-
| `to`
|
|
91
|
-
| `children`
|
|
92
|
-
| `replace`
|
|
93
|
-
| `state`
|
|
94
|
-
| Other Link props | -
|
|
88
|
+
| Prop | Type | Required | Description |
|
|
89
|
+
| ---------------- | ----------------- | -------- | ------------------------------------------------------------------ |
|
|
90
|
+
| `to` | `string` | Yes | Target path. Do not include the locale prefix |
|
|
91
|
+
| `children` | `React.ReactNode` | Yes | Link content |
|
|
92
|
+
| `replace` | `boolean` | No | Uses `history.replace` instead of `push` |
|
|
93
|
+
| `state` | `any` | No | State passed to the target route |
|
|
94
|
+
| Other Link props | - | No | Inherited from the `Link` component in `@modern-js/runtime/router` |
|
|
95
95
|
|
|
96
96
|
### Usage
|
|
97
97
|
|
|
@@ -166,11 +166,11 @@ Type of the custom backend loader function:
|
|
|
166
166
|
type I18nSdkLoader = (options: I18nSdkLoadOptions) => Promise<Resources>;
|
|
167
167
|
|
|
168
168
|
interface I18nSdkLoadOptions {
|
|
169
|
-
lng?: string;
|
|
170
|
-
ns?: string;
|
|
171
|
-
lngs?: string[];
|
|
172
|
-
nss?: string[];
|
|
173
|
-
all?: boolean;
|
|
169
|
+
lng?: string; // Single language code
|
|
170
|
+
ns?: string; // Single namespace
|
|
171
|
+
lngs?: string[]; // Multiple language codes
|
|
172
|
+
nss?: string[]; // Multiple namespaces
|
|
173
|
+
all?: boolean; // Load all resources
|
|
174
174
|
}
|
|
175
175
|
|
|
176
176
|
type Resources = {
|
|
@@ -185,14 +185,14 @@ type Resources = {
|
|
|
185
185
|
```ts
|
|
186
186
|
interface LanguageDetectorOptions {
|
|
187
187
|
order?: string[];
|
|
188
|
-
lookupQuerystring?: string;
|
|
189
|
-
lookupCookie?: string;
|
|
190
|
-
lookupLocalStorage?: string;
|
|
188
|
+
lookupQuerystring?: string; // Default: 'lng'
|
|
189
|
+
lookupCookie?: string; // Default: 'i18next'
|
|
190
|
+
lookupLocalStorage?: string; // Default: 'i18nextLng'
|
|
191
191
|
lookupSession?: string;
|
|
192
|
-
lookupHeader?: string;
|
|
192
|
+
lookupHeader?: string; // Default: 'accept-language'
|
|
193
193
|
lookupFromPathIndex?: number; // Default: 0
|
|
194
194
|
caches?: false | string[];
|
|
195
|
-
cookieMinutes?: number;
|
|
195
|
+
cookieMinutes?: number; // Default: 525600 (1 year)
|
|
196
196
|
cookieExpirationDate?: Date;
|
|
197
197
|
cookieDomain?: string;
|
|
198
198
|
}
|
|
@@ -212,8 +212,8 @@ import { useTranslation } from 'react-i18next';
|
|
|
212
212
|
import { useModernI18n } from '@modern-js/plugin-i18n/runtime';
|
|
213
213
|
|
|
214
214
|
function App() {
|
|
215
|
-
const { t } = useTranslation();
|
|
216
|
-
const { language, changeLanguage } = useModernI18n();
|
|
215
|
+
const { t } = useTranslation(); // Translate text
|
|
216
|
+
const { language, changeLanguage } = useModernI18n(); // Switch language
|
|
217
217
|
|
|
218
218
|
return (
|
|
219
219
|
<div>
|
|
@@ -231,5 +231,11 @@ You can also get the i18next instance from `useModernI18n` and call capabilities
|
|
|
231
231
|
const { i18nInstance } = useModernI18n();
|
|
232
232
|
|
|
233
233
|
// Dynamically add translation resources.
|
|
234
|
-
i18nInstance.addResourceBundle(
|
|
234
|
+
i18nInstance.addResourceBundle(
|
|
235
|
+
'zh',
|
|
236
|
+
'translation',
|
|
237
|
+
{ key: 'Value' },
|
|
238
|
+
true,
|
|
239
|
+
true,
|
|
240
|
+
);
|
|
235
241
|
```
|
|
@@ -63,8 +63,8 @@ function ButtonGroup() {
|
|
|
63
63
|
const { t } = useTranslation('common', { keyPrefix: 'button' });
|
|
64
64
|
return (
|
|
65
65
|
<>
|
|
66
|
-
<button>{t('submit')}</button>
|
|
67
|
-
<button>{t('cancel')}</button>
|
|
66
|
+
<button>{t('submit')}</button> {/* common:button.submit */}
|
|
67
|
+
<button>{t('cancel')}</button> {/* common:button.cancel */}
|
|
68
68
|
</>
|
|
69
69
|
);
|
|
70
70
|
}
|
|
@@ -94,9 +94,9 @@ The quality of translation key names directly affects maintenance cost. Recommen
|
|
|
94
94
|
```
|
|
95
95
|
|
|
96
96
|
```tsx
|
|
97
|
-
t('page.title')
|
|
98
|
-
t('form.username.label')
|
|
99
|
-
t('form.submit', { defaultValue: 'Save' }) // defaultValue prevents showing the key string when the key is missing.
|
|
97
|
+
t('page.title');
|
|
98
|
+
t('form.username.label');
|
|
99
|
+
t('form.submit', { defaultValue: 'Save' }); // defaultValue prevents showing the key string when the key is missing.
|
|
100
100
|
```
|
|
101
101
|
|
|
102
102
|
## Plurals
|
|
@@ -121,9 +121,9 @@ i18next automatically selects the correct plural form based on the `count` param
|
|
|
121
121
|
```
|
|
122
122
|
|
|
123
123
|
```tsx
|
|
124
|
-
t('item', { count: 0 })
|
|
125
|
-
t('item', { count: 1 })
|
|
126
|
-
t('item', { count: 5 })
|
|
124
|
+
t('item', { count: 0 }); // "没有条目" / "No items"
|
|
125
|
+
t('item', { count: 1 }); // "没有条目" / "1 item" (Chinese usually has only one form)
|
|
126
|
+
t('item', { count: 5 }); // "5 个条目" / "5 items"
|
|
127
127
|
```
|
|
128
128
|
|
|
129
129
|
Different languages have different plural rules. English has singular and plural, while Russian has one/few/many forms. i18next automatically matches CLDR rules based on the language code.
|
|
@@ -152,8 +152,8 @@ Nested structures can clearly reflect UI hierarchy and are accessed with dots:
|
|
|
152
152
|
```
|
|
153
153
|
|
|
154
154
|
```tsx
|
|
155
|
-
t('modal.confirm.title')
|
|
156
|
-
t('modal.confirm.actions.ok')
|
|
155
|
+
t('modal.confirm.title');
|
|
156
|
+
t('modal.confirm.actions.ok');
|
|
157
157
|
```
|
|
158
158
|
|
|
159
159
|
Avoid nesting deeper than 4 levels. Excessive depth makes key names long and hard to maintain.
|
|
@@ -199,8 +199,8 @@ Use `, format` in translation files to specify the formatting type:
|
|
|
199
199
|
```
|
|
200
200
|
|
|
201
201
|
```tsx
|
|
202
|
-
t('price', { value: 99.5 })
|
|
203
|
-
t('expiry', { date: new Date() }) // "到期日:2025年5月12日" (zh)
|
|
202
|
+
t('price', { value: 99.5 }); // "当前价格:¥99.50" (zh) / "$99.50" (en)
|
|
203
|
+
t('expiry', { date: new Date() }); // "到期日:2025年5月12日" (zh)
|
|
204
204
|
```
|
|
205
205
|
|
|
206
206
|
## Error Handling
|
|
@@ -237,7 +237,7 @@ if (!i18n.isInitialized) return null;
|
|
|
237
237
|
Provide fallback text with `defaultValue` to prevent key strings from appearing in the UI:
|
|
238
238
|
|
|
239
239
|
```tsx
|
|
240
|
-
t('missing.key', { defaultValue: 'Default text' })
|
|
240
|
+
t('missing.key', { defaultValue: 'Default text' });
|
|
241
241
|
```
|
|
242
242
|
|
|
243
243
|
In development, you can enable `saveMissing` to output missing keys to the console for debugging:
|
|
@@ -281,8 +281,8 @@ Referencing JSON file types directly is less likely to drift from actual transla
|
|
|
281
281
|
|
|
282
282
|
```tsx
|
|
283
283
|
const { t } = useTranslation();
|
|
284
|
-
t('welcome');
|
|
285
|
-
t('nonExistent');
|
|
284
|
+
t('welcome'); // TypeScript autocomplete
|
|
285
|
+
t('nonExistent'); // TypeScript error
|
|
286
286
|
```
|
|
287
287
|
|
|
288
288
|
:::tip Large projects
|