@bleedingdev/modern-js-main-doc 3.9.0-ultramodern.9 → 3.9.3-ultramodern.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/components/deploy-command.mdx +1 -0
- package/docs/en/components/prerequisites.mdx +1 -1
- package/docs/en/configure/app/bff/effect.mdx +5 -12
- package/docs/en/configure/app/output/disable-svgr.mdx +4 -0
- package/docs/en/configure/app/output/svg-default-export.mdx +4 -0
- package/docs/en/configure/app/source/react-compiler.mdx +2 -0
- package/docs/en/configure/app/tools/less.mdx +95 -19
- package/docs/en/configure/app/tools/sass.mdx +88 -18
- package/docs/en/configure/app/tools/svgr.mdx +93 -0
- package/docs/en/configure/app/tools/ts-checker.mdx +3 -17
- package/docs/en/guides/basic-features/render/ssr-cache.mdx +14 -1
- package/docs/en/guides/basic-features/static-assets/svg-assets.mdx +29 -17
- package/docs/en/guides/get-started/ultramodern.mdx +45 -14
- package/docs/en/plugin/introduction.mdx +1 -1
- package/docs/en/plugin/server-plugins/api.mdx +1 -0
- package/docs/zh/components/deploy-command.mdx +1 -0
- package/docs/zh/components/prerequisites.mdx +1 -1
- package/docs/zh/configure/app/bff/effect.mdx +4 -11
- package/docs/zh/configure/app/output/disable-svgr.mdx +4 -0
- package/docs/zh/configure/app/output/svg-default-export.mdx +4 -0
- package/docs/zh/configure/app/source/react-compiler.mdx +2 -0
- package/docs/zh/configure/app/tools/less.mdx +94 -19
- package/docs/zh/configure/app/tools/sass.mdx +88 -16
- package/docs/zh/configure/app/tools/svgr.mdx +93 -0
- package/docs/zh/configure/app/tools/ts-checker.mdx +3 -17
- package/docs/zh/guides/basic-features/render/ssr-cache.mdx +14 -1
- package/docs/zh/guides/basic-features/static-assets/svg-assets.mdx +29 -17
- package/docs/zh/guides/get-started/ultramodern.mdx +42 -14
- package/docs/zh/plugin/introduction.mdx +1 -1
- package/docs/zh/plugin/server-plugins/api.mdx +1 -0
- package/package.json +19 -17
- package/ultramodern-preset/package.json +3 -3
|
@@ -8,6 +8,7 @@ Usage: modern deploy [options]
|
|
|
8
8
|
Options:
|
|
9
9
|
-c --config <config> Specify configuration file path, either relative or absolute
|
|
10
10
|
-s --skip-build Skip the build stage
|
|
11
|
+
--deploy-target <target> Deploy target (node, vercel, netlify, ghPages, cloudflare); overrides deploy.target and MODERNJS_DEPLOY
|
|
11
12
|
-h, --help Display command help
|
|
12
13
|
```
|
|
13
14
|
|
|
@@ -53,7 +53,7 @@ the framework use the same Effect instance. Before setting
|
|
|
53
53
|
`/effect-edge` or `/effect-client`, install the exact cohort:
|
|
54
54
|
|
|
55
55
|
```bash
|
|
56
|
-
pnpm add effect@4.0.0-rc.
|
|
56
|
+
pnpm add effect@4.0.0-rc.117 @effect/opentelemetry@4.0.0-rc.117
|
|
57
57
|
```
|
|
58
58
|
|
|
59
59
|
The pin is exact because UltraModern ships Effect as one lockstep cohort. Apps
|
|
@@ -229,14 +229,10 @@ through `pnpm-workspace.yaml` overrides. For the current UltraModern cohort,
|
|
|
229
229
|
generated apps use:
|
|
230
230
|
|
|
231
231
|
```yaml
|
|
232
|
-
trustPolicyExclude:
|
|
233
|
-
- 'effect@4.0.0-rc.112'
|
|
234
|
-
- '@effect/opentelemetry@4.0.0-rc.112'
|
|
235
|
-
|
|
236
232
|
overrides:
|
|
237
|
-
'@effect/opentelemetry': 4.0.0-rc.
|
|
238
|
-
'@effect/vitest': 4.0.0-rc.
|
|
239
|
-
effect: 4.0.0-rc.
|
|
233
|
+
'@effect/opentelemetry': 4.0.0-rc.117
|
|
234
|
+
'@effect/vitest': 4.0.0-rc.117
|
|
235
|
+
effect: 4.0.0-rc.117
|
|
240
236
|
```
|
|
241
237
|
|
|
242
238
|
Do not add a different direct `effect` version in an app package. A mismatched
|
|
@@ -244,10 +240,7 @@ Effect prerelease can fail while building layers or HTTP middleware because runt
|
|
|
244
240
|
services come from different package instances. The strict 24-hour release-age
|
|
245
241
|
gate applies to installed packages; the current cohort has no Effect age
|
|
246
242
|
exemption, and override-only `@effect/vitest` is not an installed approval
|
|
247
|
-
target.
|
|
248
|
-
its exact `effect` and `@effect/opentelemetry` exceptions cover their
|
|
249
|
-
trusted-publisher to provenance metadata transition and are not release-age
|
|
250
|
-
approvals.
|
|
243
|
+
target.
|
|
251
244
|
|
|
252
245
|
## Contract tests
|
|
253
246
|
|
|
@@ -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.
|
|
@@ -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:
|
|
@@ -11,6 +11,8 @@ Whether to enable [React Compiler](https://react.dev/learn/react-compiler). Reac
|
|
|
11
11
|
|
|
12
12
|
Modern.js implements this capability based on the Rust-based React Compiler built into Rspack's `builtin:swc-loader` (equivalent to setting SWC's `jsc.transform.reactCompiler`), reusing Rspack's built-in SWC transform chain without introducing Babel.
|
|
13
13
|
|
|
14
|
+
The compiler only runs for browser environments (`output.target: 'web'`). Server environments (`node`, the `web-worker` SSR worker and BFF code) render once per request and gain nothing from memoization, so they are never compiled.
|
|
15
|
+
|
|
14
16
|
:::tip
|
|
15
17
|
This option is disabled by default. It must be enabled explicitly for any React version, including React 19.
|
|
16
18
|
:::
|
|
@@ -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
|
|
32
|
+
|
|
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:
|
|
21
34
|
|
|
22
|
-
|
|
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,53 @@ 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
|
+
|
|
139
|
+
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
|
+
|
|
141
|
+
```js
|
|
142
|
+
// legacy
|
|
143
|
+
export default {
|
|
144
|
+
tools: {
|
|
145
|
+
less: {
|
|
146
|
+
lessOptions: { javascriptEnabled: false },
|
|
147
|
+
},
|
|
148
|
+
},
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
// current
|
|
152
|
+
export default {
|
|
153
|
+
tools: {
|
|
154
|
+
less: {
|
|
155
|
+
lessLoaderOptions: {
|
|
156
|
+
lessOptions: { javascriptEnabled: false },
|
|
157
|
+
},
|
|
82
158
|
},
|
|
83
159
|
},
|
|
84
160
|
};
|
|
@@ -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,53 @@ 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
|
+
|
|
130
|
+
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
|
+
|
|
132
|
+
```js
|
|
133
|
+
// legacy
|
|
134
|
+
export default {
|
|
135
|
+
tools: {
|
|
136
|
+
sass: {
|
|
137
|
+
sourceMap: true,
|
|
138
|
+
},
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
// current
|
|
143
|
+
export default {
|
|
144
|
+
tools: {
|
|
145
|
+
sass: {
|
|
146
|
+
sassLoaderOptions: {
|
|
147
|
+
sourceMap: true,
|
|
148
|
+
},
|
|
79
149
|
},
|
|
80
150
|
},
|
|
81
151
|
};
|
|
@@ -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`.
|
|
@@ -80,24 +80,10 @@ export default {
|
|
|
80
80
|
|
|
81
81
|
Type checking runs on [TypeScript Go](https://github.com/microsoft/typescript-go) (`tsgo`) by default in this fork. The capability is provided by [`ts-checker-rspack-plugin`](https://github.com/rstackjs/ts-checker-rspack-plugin), which is integrated by [`@rsbuild/plugin-type-check`](https://github.com/rstackjs/rsbuild-plugin-type-check), and reduces type-checking time by about 5-10x.
|
|
82
82
|
|
|
83
|
-
Modern.js
|
|
83
|
+
Modern.js uses the native Go compiler from stable `typescript@7.0.2`. It resolves the project's package first, then the builder's declared dependency, and rejects incompatible versions. To install the supported compiler in your project:
|
|
84
84
|
|
|
85
|
-
<PackageManagerTabs command="install typescript -D" />
|
|
85
|
+
<PackageManagerTabs command="install typescript@7.0.2 -D" />
|
|
86
86
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
To fall back to the classic TypeScript checker, set `typescript.tsgo` to `false` and make sure `typescript` is installed in your project:
|
|
90
|
-
|
|
91
|
-
```ts
|
|
92
|
-
export default {
|
|
93
|
-
tools: {
|
|
94
|
-
tsChecker: {
|
|
95
|
-
typescript: {
|
|
96
|
-
tsgo: false,
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
},
|
|
100
|
-
};
|
|
101
|
-
```
|
|
87
|
+
The default `typescript.typescriptPath` resolves to the absolute path of `typescript/package.json` for that stable compiler.
|
|
102
88
|
|
|
103
89
|
For supported options and limitations, please refer to [ts-checker-rspack-plugin - TypeScript Go support](https://github.com/rstackjs/ts-checker-rspack-plugin#typescript-go-support).
|
|
@@ -35,7 +35,7 @@ export interface CacheControl {
|
|
|
35
35
|
}
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
Here, `customKey` is the custom cache key. By default,
|
|
38
|
+
Here, `customKey` is the custom cache key. By default, the cache key is derived from the request's origin, normalized pathname (trailing slash removed), and query string. When `customKey` is set, it fully replaces the default key: the `customKey` callback receives the normalized pathname (not the `CacheOptionProvider`'s `req`) and is responsible for the whole partition (e.g. by tenant, host, or query) — it must not embed raw cookies or other credentials into the returned key.
|
|
39
39
|
|
|
40
40
|
**Function Type**
|
|
41
41
|
|
|
@@ -106,6 +106,19 @@ export const cacheOption: CacheOption = {
|
|
|
106
106
|
|
|
107
107
|
The above `/home` and `/about` are patterns, meaning `/home/abc` will also match. You can use regex in these patterns, such as `/home/.+`.
|
|
108
108
|
|
|
109
|
+
### Cache Policy
|
|
110
|
+
|
|
111
|
+
The following policy is enforced automatically and cannot be overridden by the returned `CacheControl`:
|
|
112
|
+
|
|
113
|
+
- Only `GET` requests are cached.
|
|
114
|
+
- A request carrying a `Cookie` or `Authorization` header skips the cache unless `customKey` is set, since a custom key is treated as an explicit partitioning contract.
|
|
115
|
+
- A request with `Cache-Control: private`, `no-cache`, or `no-store` skips the cache.
|
|
116
|
+
- A response is only stored when it is `200`, has no `private`/`no-cache`/`no-store` in `Cache-Control`, has no `Set-Cookie`, and has no nonempty `Vary` header; otherwise any existing cache entry for that key is deleted instead of being written.
|
|
117
|
+
- If a `stale` revalidation produces a response that is no longer cacheable (for example, it became per-user), that already-served stale response is unaffected, but the cache entry is evicted so subsequent requests no longer hit it.
|
|
118
|
+
- A `CacheOptionProvider` returning `false` still disables caching entirely for that request, independent of the policy above.
|
|
119
|
+
|
|
120
|
+
Cache keys are namespaced (`__ssr__cache:v2:...`). Older un-namespaced entries — including ones already stored in a custom `Container` — are never read back; they simply age out under the container's own eviction/TTL. There is no global cache flush.
|
|
121
|
+
|
|
109
122
|
### Cache Container
|
|
110
123
|
|
|
111
124
|
By default, the server uses memory for caching. Typically, services are deployed in a Serverless container, creating a new process for each access, making it impossible to use the previous cache.
|
|
@@ -42,16 +42,22 @@ export default () => <Logo />;
|
|
|
42
42
|
|
|
43
43
|
## Modify the Default Export
|
|
44
44
|
|
|
45
|
-
You can modify the default export of SVG files through
|
|
45
|
+
You can modify the default export of SVG files through `svgrOptions.exportType` of [tools.svgr](/configure/app/tools/svgr). For example, set the default export as a React component:
|
|
46
46
|
|
|
47
47
|
```ts
|
|
48
48
|
export default {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
tools: {
|
|
50
|
+
svgr: {
|
|
51
|
+
svgrOptions: {
|
|
52
|
+
exportType: 'default',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
51
55
|
},
|
|
52
56
|
};
|
|
53
57
|
```
|
|
54
58
|
|
|
59
|
+
The legacy [output.svgDefaultExport](/configure/app/output/svg-default-export) config still works but is deprecated.
|
|
60
|
+
|
|
55
61
|
Then import the SVG, you'll get a React component instead of a URL:
|
|
56
62
|
|
|
57
63
|
```tsx title="src/component/Logo.tsx"
|
|
@@ -78,12 +84,12 @@ Please read the [Import Static Assets](/guides/basic-features/static-assets) sec
|
|
|
78
84
|
|
|
79
85
|
## Disable SVGR Processing
|
|
80
86
|
|
|
81
|
-
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 [
|
|
87
|
+
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 [tools.svgr](/configure/app/tools/svgr) to `false` to improve build performance.
|
|
82
88
|
|
|
83
89
|
```js
|
|
84
90
|
export default {
|
|
85
|
-
|
|
86
|
-
|
|
91
|
+
tools: {
|
|
92
|
+
svgr: false,
|
|
87
93
|
},
|
|
88
94
|
};
|
|
89
95
|
```
|
|
@@ -151,21 +157,27 @@ When SVGR is enabled, its default configuration is as follows:
|
|
|
151
157
|
}
|
|
152
158
|
```
|
|
153
159
|
|
|
154
|
-
|
|
160
|
+
To modify the SVGR configuration, use `svgrOptions` of [tools.svgr](/configure/app/tools/svgr). The `svgoConfig.plugins` you pass are deep merged with the defaults by plugin name, so only the changed part needs to be written:
|
|
155
161
|
|
|
156
162
|
```js
|
|
157
163
|
export default {
|
|
158
164
|
tools: {
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
165
|
+
svgr: {
|
|
166
|
+
svgrOptions: {
|
|
167
|
+
svgoConfig: {
|
|
168
|
+
plugins: [
|
|
169
|
+
{
|
|
170
|
+
name: 'preset-default',
|
|
171
|
+
params: {
|
|
172
|
+
overrides: {
|
|
173
|
+
// add one more override on top of the default preset-default
|
|
174
|
+
removeUselessDefs: false,
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
],
|
|
179
|
+
},
|
|
180
|
+
},
|
|
169
181
|
},
|
|
170
182
|
},
|
|
171
183
|
};
|