@modern-js/main-doc 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/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/disable-svgr.mdx +4 -0
- 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/output/svg-default-export.mdx +4 -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 +94 -19
- package/docs/en/configure/app/tools/sass.mdx +87 -18
- package/docs/en/configure/app/tools/svgr.mdx +93 -0
- 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/static-assets/svg-assets.mdx +29 -17
- 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/disable-svgr.mdx +4 -0
- 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/output/svg-default-export.mdx +4 -0
- 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 +93 -19
- package/docs/zh/configure/app/tools/sass.mdx +87 -16
- package/docs/zh/configure/app/tools/svgr.mdx +93 -0
- 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/static-assets/svg-assets.mdx +29 -17
- 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?:
|
|
@@ -7,6 +7,10 @@ title: disableSvgr
|
|
|
7
7
|
- **Type:** `boolean`
|
|
8
8
|
- **Default:** `false`
|
|
9
9
|
|
|
10
|
+
:::warning Deprecated
|
|
11
|
+
`output.disableSvgr` is deprecated and will be removed in the next major version. Replace `output.disableSvgr: true` with [tools.svgr](/configure/app/tools/svgr) set to `false`; `output.disableSvgr: false` is the default behavior and can simply be removed. When both are set, `tools.svgr` wins.
|
|
12
|
+
:::
|
|
13
|
+
|
|
10
14
|
Whether to transform SVGs into React components. If true, will treat all .svg files as assets.
|
|
11
15
|
|
|
12
16
|
By default, when an SVG resource is referenced in a JS file, Modern.js will call SVGR to convert the SVG into a React component. If you are sure that all SVG resources in your project are not being used as React components, you can turn off this conversion by setting `disableSvgr` to true to improve build performance.
|
|
@@ -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.
|
|
@@ -7,6 +7,10 @@ title: svgDefaultExport
|
|
|
7
7
|
- **Type:** `'url' | 'component'`
|
|
8
8
|
- **Default:** `'url'`
|
|
9
9
|
|
|
10
|
+
:::warning Deprecated
|
|
11
|
+
`output.svgDefaultExport` is deprecated and will be removed in the next major version. Use `svgrOptions.exportType` of [tools.svgr](/configure/app/tools/svgr) instead: `'component'` maps to `exportType: 'default'`, `'url'` maps to `exportType: 'named'`. When both are set, `tools.svgr` wins.
|
|
12
|
+
:::
|
|
13
|
+
|
|
10
14
|
`output.svgDefaultExport` is used to configure the default export type of SVG files.
|
|
11
15
|
|
|
12
16
|
When `output.svgDefaultExport` is set to `url` , the default export of SVG files is the URL of the file. For example:
|
|
@@ -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
|
|
|
@@ -9,49 +9,78 @@ title: less
|
|
|
9
9
|
|
|
10
10
|
```js
|
|
11
11
|
const defaultOptions = {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
lessLoaderOptions: {
|
|
13
|
+
lessOptions: {
|
|
14
|
+
javascriptEnabled: true,
|
|
15
|
+
},
|
|
16
|
+
// CSS Source Map enabled by default in development environment
|
|
17
|
+
sourceMap: isDev,
|
|
14
18
|
},
|
|
15
|
-
// CSS Source Map enabled by default in development environment
|
|
16
|
-
sourceMap: isDev,
|
|
17
19
|
};
|
|
18
20
|
```
|
|
19
21
|
|
|
20
|
-
|
|
22
|
+
`tools.less` modifies the options of [@rsbuild/plugin-less](https://rsbuild.rs/plugins/list/plugin-less). It accepts the full plugin options:
|
|
23
|
+
|
|
24
|
+
| Option | Description |
|
|
25
|
+
| ------------------- | --------------------------------------------------------------------------------------------------- |
|
|
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` |
|
|
30
|
+
|
|
31
|
+
### Modifying less-loader options
|
|
21
32
|
|
|
22
|
-
|
|
33
|
+
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:
|
|
34
|
+
|
|
35
|
+
```js
|
|
36
|
+
export default {
|
|
37
|
+
tools: {
|
|
38
|
+
less: {
|
|
39
|
+
lessLoaderOptions: {
|
|
40
|
+
lessOptions: {
|
|
41
|
+
javascriptEnabled: false,
|
|
42
|
+
},
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
```
|
|
23
48
|
|
|
24
|
-
When `
|
|
49
|
+
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:
|
|
25
50
|
|
|
26
51
|
```js
|
|
27
52
|
export default {
|
|
28
53
|
tools: {
|
|
29
54
|
less: {
|
|
30
|
-
|
|
31
|
-
|
|
55
|
+
lessLoaderOptions(config) {
|
|
56
|
+
// Modify the config of lessOptions
|
|
57
|
+
config.lessOptions = {
|
|
58
|
+
javascriptEnabled: false,
|
|
59
|
+
};
|
|
32
60
|
},
|
|
33
61
|
},
|
|
34
62
|
},
|
|
35
63
|
};
|
|
36
64
|
```
|
|
37
65
|
|
|
38
|
-
###
|
|
66
|
+
### Parallel compilation
|
|
39
67
|
|
|
40
|
-
|
|
68
|
+
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.
|
|
41
69
|
|
|
42
70
|
```js
|
|
43
71
|
export default {
|
|
44
72
|
tools: {
|
|
45
|
-
less
|
|
46
|
-
|
|
47
|
-
config.lessOptions = {
|
|
48
|
-
javascriptEnabled: false,
|
|
49
|
-
};
|
|
73
|
+
less: {
|
|
74
|
+
parallel: true,
|
|
50
75
|
},
|
|
51
76
|
},
|
|
52
77
|
};
|
|
53
78
|
```
|
|
54
79
|
|
|
80
|
+
:::tip
|
|
81
|
+
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`.
|
|
82
|
+
:::
|
|
83
|
+
|
|
55
84
|
### Modifying Less Version
|
|
56
85
|
|
|
57
86
|
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`.
|
|
@@ -60,7 +89,9 @@ In some scenarios, if you need to use a specific version of Less instead of the
|
|
|
60
89
|
export default {
|
|
61
90
|
tools: {
|
|
62
91
|
less: {
|
|
63
|
-
|
|
92
|
+
lessLoaderOptions: {
|
|
93
|
+
implementation: require('less'),
|
|
94
|
+
},
|
|
64
95
|
},
|
|
65
96
|
},
|
|
66
97
|
};
|
|
@@ -77,8 +108,52 @@ Used to specify which files `less-loader` does not compile, You can pass in one
|
|
|
77
108
|
```js
|
|
78
109
|
export default {
|
|
79
110
|
tools: {
|
|
80
|
-
less
|
|
81
|
-
addExcludes
|
|
111
|
+
less: {
|
|
112
|
+
lessLoaderOptions(config, { addExcludes }) {
|
|
113
|
+
addExcludes(/node_modules/);
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
};
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
The plugin's `exclude` option is the recommended equivalent:
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
export default {
|
|
124
|
+
tools: {
|
|
125
|
+
less: {
|
|
126
|
+
exclude: /node_modules/,
|
|
127
|
+
},
|
|
128
|
+
},
|
|
129
|
+
};
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### Legacy form
|
|
133
|
+
|
|
134
|
+
:::warning Do not mix the two layers
|
|
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
|
+
:::
|
|
137
|
+
|
|
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.
|
|
139
|
+
|
|
140
|
+
```js
|
|
141
|
+
// legacy
|
|
142
|
+
export default {
|
|
143
|
+
tools: {
|
|
144
|
+
less: {
|
|
145
|
+
lessOptions: { javascriptEnabled: false },
|
|
146
|
+
},
|
|
147
|
+
},
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
// current
|
|
151
|
+
export default {
|
|
152
|
+
tools: {
|
|
153
|
+
less: {
|
|
154
|
+
lessLoaderOptions: {
|
|
155
|
+
lessOptions: { javascriptEnabled: false },
|
|
156
|
+
},
|
|
82
157
|
},
|
|
83
158
|
},
|
|
84
159
|
};
|
|
@@ -9,41 +9,64 @@ title: sass
|
|
|
9
9
|
|
|
10
10
|
```js
|
|
11
11
|
const defaultOptions = {
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
sassLoaderOptions: {
|
|
13
|
+
// CSS Source Map enabled by default in development environment
|
|
14
|
+
sourceMap: isDev,
|
|
15
|
+
},
|
|
14
16
|
};
|
|
15
17
|
```
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
`tools.sass` modifies the options of [@rsbuild/plugin-sass](https://rsbuild.rs/plugins/list/plugin-sass). It accepts the full plugin options:
|
|
18
20
|
|
|
19
|
-
|
|
21
|
+
| Option | Description |
|
|
22
|
+
| ------------------- | --------------------------------------------------------------------------------------------------- |
|
|
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\|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` |
|
|
20
27
|
|
|
21
|
-
|
|
28
|
+
### Modifying sass-loader options
|
|
22
29
|
|
|
23
|
-
For example:
|
|
30
|
+
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:
|
|
24
31
|
|
|
25
32
|
```js
|
|
26
33
|
export default {
|
|
27
34
|
tools: {
|
|
28
35
|
sass: {
|
|
29
|
-
|
|
36
|
+
sassLoaderOptions: {
|
|
37
|
+
sourceMap: true,
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
};
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
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:
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
export default {
|
|
48
|
+
tools: {
|
|
49
|
+
sass: {
|
|
50
|
+
sassLoaderOptions(config) {
|
|
51
|
+
// Modify the additionalData config
|
|
52
|
+
config.additionalData = async (content, loaderContext) => {
|
|
53
|
+
// ...
|
|
54
|
+
};
|
|
55
|
+
},
|
|
30
56
|
},
|
|
31
57
|
},
|
|
32
58
|
};
|
|
33
59
|
```
|
|
34
60
|
|
|
35
|
-
###
|
|
61
|
+
### Disabling URL rewriting
|
|
36
62
|
|
|
37
|
-
|
|
63
|
+
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:
|
|
38
64
|
|
|
39
65
|
```js
|
|
40
66
|
export default {
|
|
41
67
|
tools: {
|
|
42
|
-
sass
|
|
43
|
-
|
|
44
|
-
config.additionalData = async (content, loaderContext) => {
|
|
45
|
-
// ...
|
|
46
|
-
};
|
|
68
|
+
sass: {
|
|
69
|
+
rewriteUrls: false,
|
|
47
70
|
},
|
|
48
71
|
},
|
|
49
72
|
};
|
|
@@ -57,13 +80,15 @@ In some scenarios, if you need to use a specific version of Sass instead of the
|
|
|
57
80
|
export default {
|
|
58
81
|
tools: {
|
|
59
82
|
sass: {
|
|
60
|
-
|
|
83
|
+
sassLoaderOptions: {
|
|
84
|
+
implementation: require('sass'),
|
|
85
|
+
},
|
|
61
86
|
},
|
|
62
87
|
},
|
|
63
88
|
};
|
|
64
89
|
```
|
|
65
90
|
|
|
66
|
-
###
|
|
91
|
+
### Util Function
|
|
67
92
|
|
|
68
93
|
#### addExcludes
|
|
69
94
|
|
|
@@ -74,8 +99,52 @@ Used to specify which files `sass-loader` does not compile, You can pass in one
|
|
|
74
99
|
```js
|
|
75
100
|
export default {
|
|
76
101
|
tools: {
|
|
77
|
-
sass
|
|
78
|
-
addExcludes
|
|
102
|
+
sass: {
|
|
103
|
+
sassLoaderOptions(config, { addExcludes }) {
|
|
104
|
+
addExcludes(/node_modules/);
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
The plugin's `exclude` option is the recommended equivalent:
|
|
112
|
+
|
|
113
|
+
```js
|
|
114
|
+
export default {
|
|
115
|
+
tools: {
|
|
116
|
+
sass: {
|
|
117
|
+
exclude: /node_modules/,
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
};
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
### Legacy form
|
|
124
|
+
|
|
125
|
+
:::warning Do not mix the two layers
|
|
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
|
+
:::
|
|
128
|
+
|
|
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.
|
|
130
|
+
|
|
131
|
+
```js
|
|
132
|
+
// legacy
|
|
133
|
+
export default {
|
|
134
|
+
tools: {
|
|
135
|
+
sass: {
|
|
136
|
+
sourceMap: true,
|
|
137
|
+
},
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
// current
|
|
142
|
+
export default {
|
|
143
|
+
tools: {
|
|
144
|
+
sass: {
|
|
145
|
+
sassLoaderOptions: {
|
|
146
|
+
sourceMap: true,
|
|
147
|
+
},
|
|
79
148
|
},
|
|
80
149
|
},
|
|
81
150
|
};
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: svgr
|
|
3
|
+
---
|
|
4
|
+
|
|
5
|
+
# tools.svgr
|
|
6
|
+
|
|
7
|
+
- **Type:** `Object | Function | false`
|
|
8
|
+
- **Default:**
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
const defaultOptions = {
|
|
12
|
+
mixedImport: true,
|
|
13
|
+
svgrOptions: {
|
|
14
|
+
exportType: 'named',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
```
|
|
18
|
+
|
|
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
|
+
|
|
21
|
+
| Option | Description |
|
|
22
|
+
| ----------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
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` |
|
|
29
|
+
|
|
30
|
+
### Merge rules
|
|
31
|
+
|
|
32
|
+
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`.
|
|
33
|
+
|
|
34
|
+
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.
|
|
35
|
+
|
|
36
|
+
### Parallel transform
|
|
37
|
+
|
|
38
|
+
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:
|
|
39
|
+
|
|
40
|
+
```js
|
|
41
|
+
export default {
|
|
42
|
+
tools: {
|
|
43
|
+
svgr: {
|
|
44
|
+
parallel: true,
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
:::tip
|
|
51
|
+
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.
|
|
52
|
+
:::
|
|
53
|
+
|
|
54
|
+
### Changing the default export
|
|
55
|
+
|
|
56
|
+
`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.
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
export default {
|
|
60
|
+
tools: {
|
|
61
|
+
svgr: {
|
|
62
|
+
svgrOptions: {
|
|
63
|
+
exportType: 'default',
|
|
64
|
+
},
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
};
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### Disabling SVGR
|
|
71
|
+
|
|
72
|
+
If you are sure that no SVG asset in your project is used as a React component, disable SVGR to improve build performance:
|
|
73
|
+
|
|
74
|
+
```js
|
|
75
|
+
export default {
|
|
76
|
+
tools: {
|
|
77
|
+
svgr: false,
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
### Relation to the legacy options
|
|
83
|
+
|
|
84
|
+
`tools.svgr` replaces the two deprecated options below. They still work today and will be removed in the next major version:
|
|
85
|
+
|
|
86
|
+
| Legacy option | Replacement |
|
|
87
|
+
| -------------------------------------- | -------------------------------------------------------- |
|
|
88
|
+
| `output.svgDefaultExport: 'component'` | `tools.svgr: { svgrOptions: { exportType: 'default' } }` |
|
|
89
|
+
| `output.svgDefaultExport: 'url'` | `tools.svgr: { svgrOptions: { exportType: 'named' } }` |
|
|
90
|
+
| `output.disableSvgr: true` | `tools.svgr: false` |
|
|
91
|
+
| `output.disableSvgr: false` | Default behavior, just remove it |
|
|
92
|
+
|
|
93
|
+
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`.
|