You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: website/docs/en/config/lib/redirect.mdx
+55-9Lines changed: 55 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -72,9 +72,21 @@ In bundleless mode, there are often needs such as using aliases or automatically
72
72
73
73
Controls the redirect of the import paths of output JavaScript files.
74
74
75
+
-**Example:**
76
+
77
+
By default, when set `compilerOptions.paths` to `{ "@/*": ["src/*"] }` in `tsconfig.json`, the import path for the JavaScript output file will be redirected to the correct relative path and the corresponding file extension will be added:
import { foo } from'../foo.mjs'; // expected output of './dist/utils/index.mjs'
85
+
```
86
+
75
87
:::warning
76
88
77
-
When [output.externals](/config/rsbuild/output#outputexternals) is configured and a request is matched, neither `redirect.js.path` nor `redirect.js.extension` will take effect, and the final rewritten request path will be entirely controlled by [output.externals](/config/rsbuild/output#outputexternals).
89
+
When [output.externals](/config/rsbuild/output#outputexternals) is configured and a request is matched, neither `redirect.js.path` nor `redirect.js.extension` will take effect, and the final redirected request path will be entirely controlled by [output.externals](/config/rsbuild/output#outputexternals).
78
90
79
91
:::
80
92
@@ -85,20 +97,20 @@ Whether to automatically redirect the import paths of JavaScript output files.
85
97
-**Type:**`boolean`
86
98
-**Default:**`true`
87
99
88
-
When set to `true`, [resolve.alias](/config/rsbuild/resolve#resolvealias) and [resolve.aliasStrategy](/config/rsbuild/resolve#aliasstrategy) will take effect in the output file, and the import path of the output file will be rewritten. For TypeScript projects, just configure [compilerOptions.paths](https://typescriptlang.org/tsconfig#paths) in the `tsconfig.json` file.
100
+
When set to `true`, [resolve.alias](/config/rsbuild/resolve#resolvealias) and [resolve.aliasStrategy](/config/rsbuild/resolve#aliasstrategy) will take effect in the output file, and the import path of the output file will be redirected. For TypeScript projects, just configure [compilerOptions.paths](https://typescriptlang.org/tsconfig#paths) in the `tsconfig.json` file.
89
101
90
102
When set to `false`, the import path will not be effected by [resolve.alias](/config/rsbuild/resolve#resolvealias), [resolve.aliasStrategy](/config/rsbuild/resolve#aliasstrategy) and `tsconfig.json`.
91
103
92
104
-**Example:**
93
105
94
-
When set `compilerOptions.paths` to `{ "@/*": ["src/*"] }` in `tsconfig.json`, the output file will be redirected to the correct relative path:
106
+
When set `compilerOptions.paths` to `{ "@/*": ["src/*"] }` in `tsconfig.json`, the import path for the JavaScript output file will be redirected to the correct relative path:
Controls the redirect of the import paths of output style files.
134
146
147
+
-**Example:**
148
+
149
+
By default, when `compilerOptions.paths` is set to `{ "@/*": ["src/*"] }` in `tsconfig.json`, the import paths of style output files will be redirected to the correct relative paths. Additionally, when importing [CSS Modules](/config/rsbuild/output#outputcssmodules), the file extension will be rewritten to the corresponding JavaScript output file extension.
150
+
151
+
```ts
152
+
import'@/foo.css'; // source code of './src/bar.ts' ↓
153
+
import'./foo.css'; // expected output of './dist/bar.js'
154
+
155
+
importstylesfrom'@/foo.module.less'; // source code of './src/baz.ts' ↓
156
+
importstylesfrom'./foo.module.mjs'; // expected output of './dist/baz.mjs'
157
+
```
158
+
135
159
### redirect.style.path
136
160
137
161
Whether to automatically redirect the import paths of style output files.
@@ -145,6 +169,8 @@ When set to `false`, the original import path will remain unchanged.
145
169
146
170
-**Example:**
147
171
172
+
When set `compilerOptions.paths` to `{ "@/*": ["src/*"] }` in `tsconfig.json`, the import path for the style output file will be redirected to the correct relative path.
173
+
148
174
When importing normal style files:
149
175
150
176
```ts
@@ -174,8 +200,8 @@ Whether to automatically redirect the file extension of import paths based on th
174
200
175
201
When set to `true`:
176
202
177
-
- When importing a normal style file, the path will be rewritten to `.css`.
178
-
- When importing [CSS Modules](/config/rsbuild/output#outputcssmodules), the path will be rewritten to the corresponding JavaScript output file.
203
+
- When importing a normal style file, the path will be redirected to `.css`.
204
+
- When importing [CSS Modules](/config/rsbuild/output#outputcssmodules), the file extension will be redirected to the corresponding JavaScript output file extension.
179
205
180
206
When set to `false`, the file extension will remain unchanged from the original import path.
Controls the redirect of the import paths of output asset files.
197
223
224
+
-**Example:**
225
+
226
+
By default, when `compilerOptions.paths` is set to `{ "@/*": ["src/*"] }` in `tsconfig.json`, the import paths of asset files will be redirected to the correct relative paths, and the file extensions will be rewritten to the corresponding JavaScript output file extensions.
227
+
228
+
```ts
229
+
importurlfrom'@/assets/logo.svg'; // source code of './src/foo.ts' ↓
230
+
importurlfrom'./assets/logo.mjs'; // expected output of './dist/foo.mjs'
231
+
```
232
+
198
233
### redirect.asset.path
199
234
200
235
Whether to automatically redirect the import paths of asset output files.
@@ -208,6 +243,8 @@ When set to `false`, the original import path will remain unchanged.
208
243
209
244
-**Example:**
210
245
246
+
When set `compilerOptions.paths` to `{ "@/*": ["src/*"] }` in `tsconfig.json`, the import path for the asset file will be redirected to the correct relative path:
247
+
211
248
```ts
212
249
importurlfrom'@/assets/logo.svg'; // source code of './src/foo.ts' ↓
213
250
importurlfrom'./assets/logo.svg'; // expected output of './dist/foo.js'
@@ -220,7 +257,7 @@ Whether to automatically redirect the file extension of import paths based on th
220
257
-**Type:**`boolean`
221
258
-**Default:**`true`
222
259
223
-
When set to `true`, the paths of imported asset files will be redirected to the corresponding JavaScript output file.
260
+
When set to `true`, the file extension of imported asset files will be redirected to the corresponding JavaScript output file extension.
224
261
225
262
When set to `false`, the file extension will remain unchanged from the original import path.
226
263
@@ -241,6 +278,15 @@ The way to import static assets in a JavaScript file and the corresponding outpu
241
278
242
279
Controls the redirect of the import paths of output TypeScript declaration files.
243
280
281
+
-**Example:**
282
+
283
+
By default, when `compilerOptions.paths` is set to `{ "@/*": ["src/*"] }` in `tsconfig.json`, the import path in the declaration output file will be redirected to the correct relative path:
import { foo } from'./foo'; // expected output of './dist/bar.d.ts'
288
+
```
289
+
244
290
### redirect.dts.path
245
291
246
292
Whether to automatically redirect the import paths of TypeScript declaration output files.
@@ -254,7 +300,7 @@ When set to `false`, the original import path will remain unchanged.
254
300
255
301
-**Example:**
256
302
257
-
When `compilerOptions.paths` is set to `{ "@/*": ["src/*"] }` in `tsconfig.json`, the declaration output file will be redirected to the correct relative path:
303
+
When `compilerOptions.paths` is set to `{ "@/*": ["src/*"] }` in `tsconfig.json`, the import path in the declaration output file will be redirected to the correct relative path:
0 commit comments