Skip to content

Commit fb05d47

Browse files
committed
chore: update
1 parent 541931c commit fb05d47

File tree

2 files changed

+110
-18
lines changed

2 files changed

+110
-18
lines changed

website/docs/en/config/lib/redirect.mdx

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,21 @@ In bundleless mode, there are often needs such as using aliases or automatically
7272

7373
Controls the redirect of the import paths of output JavaScript files.
7474

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:
78+
79+
```ts
80+
import { foo } from '@/foo'; // source code of './src/bar.ts' ↓
81+
import { foo } from './foo.mjs'; // expected output of './dist/bar.mjs'
82+
83+
import { foo } from '@/foo'; // source code of './src/utils/index.ts' ↓
84+
import { foo } from '../foo.mjs'; // expected output of './dist/utils/index.mjs'
85+
```
86+
7587
:::warning
7688

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).
7890

7991
:::
8092

@@ -85,20 +97,20 @@ Whether to automatically redirect the import paths of JavaScript output files.
8597
- **Type:** `boolean`
8698
- **Default:** `true`
8799

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.
89101

90102
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`.
91103

92104
- **Example:**
93105

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:
95107

96108
```ts
97109
import { foo } from '@/foo'; // source code of './src/bar.ts' ↓
98-
import { foo } from './foo.js'; // expected output of './dist/bar.js'
110+
import { foo } from './foo'; // expected output of './dist/bar.js'
99111

100112
import { foo } from '@/foo'; // source code of './src/utils/index.ts' ↓
101-
import { foo } from '../foo.js'; // expected output './dist/utils/index.js'
113+
import { foo } from '../foo'; // expected output './dist/utils/index.js'
102114
```
103115

104116
### redirect.js.extension
@@ -132,6 +144,18 @@ import { foo } from './foo.mjs'; // expected output './dist/utils/index.mjs'
132144

133145
Controls the redirect of the import paths of output style files.
134146

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+
import styles from '@/foo.module.less'; // source code of './src/baz.ts' ↓
156+
import styles from './foo.module.mjs'; // expected output of './dist/baz.mjs'
157+
```
158+
135159
### redirect.style.path
136160

137161
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.
145169

146170
- **Example:**
147171

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+
148174
When importing normal style files:
149175

150176
```ts
@@ -174,8 +200,8 @@ Whether to automatically redirect the file extension of import paths based on th
174200

175201
When set to `true`:
176202

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.
179205

180206
When set to `false`, the file extension will remain unchanged from the original import path.
181207

@@ -195,6 +221,15 @@ import styles from './index.module.mjs'; // expected output
195221

196222
Controls the redirect of the import paths of output asset files.
197223

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+
import url from '@/assets/logo.svg'; // source code of './src/foo.ts' ↓
230+
import url from './assets/logo.mjs'; // expected output of './dist/foo.mjs'
231+
```
232+
198233
### redirect.asset.path
199234

200235
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.
208243

209244
- **Example:**
210245

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+
211248
```ts
212249
import url from '@/assets/logo.svg'; // source code of './src/foo.ts' ↓
213250
import url from './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
220257
- **Type:** `boolean`
221258
- **Default:** `true`
222259

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.
224261

225262
When set to `false`, the file extension will remain unchanged from the original import path.
226263

@@ -241,6 +278,15 @@ The way to import static assets in a JavaScript file and the corresponding outpu
241278

242279
Controls the redirect of the import paths of output TypeScript declaration files.
243280

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:
284+
285+
```ts
286+
import { foo } from '@/foo'; // source code of './src/bar.ts' ↓
287+
import { foo } from './foo'; // expected output of './dist/bar.d.ts'
288+
```
289+
244290
### redirect.dts.path
245291

246292
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.
254300

255301
- **Example:**
256302

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:
258304

259305
```ts
260306
import { foo } from '@/foo'; // source code of './src/bar.ts' ↓

website/docs/zh/config/lib/redirect.mdx

Lines changed: 55 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,21 @@ const defaultRedirect = {
7272

7373
控制 JavaScript 产物文件导入路径的重定向。
7474

75+
- **示例:**
76+
77+
默认情况下,在 `tsconfig.json` 中将 `compilerOptions.paths` 设置为 `{ "@/*": ["src/*"] }` 时,JavaScript 产物文件的导入路径将被重定向到正确的相对路径并添加对应的文件扩展名。
78+
79+
```ts
80+
import { foo } from '@/foo'; // './src/bar.ts' 的源码 ↓
81+
import { foo } from './foo.mjs'; // './dist/bar.mjs' 预期生成的代码
82+
83+
import { foo } from '@/foo'; // './src/utils/index.ts' 的源码 ↓
84+
import { foo } from '../foo.mjs'; // './dist/utils/index.mjs' 预期生成的代码
85+
```
86+
7587
:::warning
7688

77-
[output.externals](/config/rsbuild/output#outputexternals) 被配置且请求被匹配时,`redirect.js.path``redirect.js.extension` 都不会生效,最终重写的请求路径将完全由 [output.externals](/config/rsbuild/output#outputexternals) 控制。
89+
[output.externals](/config/rsbuild/output#outputexternals) 被配置且请求被匹配时,`redirect.js.path``redirect.js.extension` 都不会生效,最终重定向的请求路径将完全由 [output.externals](/config/rsbuild/output#outputexternals) 控制。
7890

7991
:::
8092

@@ -89,16 +101,16 @@ const defaultRedirect = {
89101

90102
当设置为 `false` 时,导入路径将不受 [resolve.alias](/config/rsbuild/resolve#resolvealias)[resolve.aliasStrategy](/config/rsbuild/resolve#aliasstrategy)`tsconfig.json` 的影响。
91103

92-
- 示例:
104+
- **示例:**
93105

94-
`tsconfig.json` 中将 `compilerOptions.paths` 设置为 `{ "@/*": ["src/*"] }` 时,产物文件将被重定向到正确的相对路径
106+
`tsconfig.json` 中将 `compilerOptions.paths` 设置为 `{ "@/*": ["src/*"] }` 时,JavaScript 产物文件的导入路径将被重定向到正确的相对路径
95107

96108
```ts
97109
import { foo } from '@/foo'; // './src/bar.ts' 的源码 ↓
98-
import { foo } from './foo.js'; // './dist/bar.js' 预期生成的代码
110+
import { foo } from './foo'; // './dist/bar.js' 预期生成的代码
99111

100112
import { foo } from '@/foo'; // './src/utils/index.ts' 的源码 ↓
101-
import { foo } from '../foo.js'; // './dist/utils/index.js' 预期生成的代码
113+
import { foo } from '../foo'; // './dist/utils/index.js' 预期生成的代码
102114
```
103115

104116
### redirect.js.extension
@@ -132,6 +144,18 @@ import { foo } from './foo.mjs'; // './dist/utils/index.mjs' 预期生成的代
132144

133145
控制样式产物文件导入路径的重定向。
134146

147+
- **示例:**
148+
149+
默认情况下,在 `tsconfig.json` 中将 `compilerOptions.paths` 设置为 `{ "@/*": ["src/*"] }` 时,样式产物文件的导入路径将被重定向到正确的相对路径。此外,在导入 [CSS Modules](/config/rsbuild/output#outputcssmodules) 时,文件扩展名将被重写为对应的 JavaScript 产物文件扩展名。
150+
151+
```ts
152+
import '@/foo.css'; // './src/bar.ts' 的源码 ↓
153+
import './foo.css'; // './dist/bar.js' 预期生成的代码
154+
155+
import styles from '@/foo.module.less'; // './src/baz.ts' 的源码 ↓
156+
import styles from './foo.module.mjs'; // './dist/baz.mjs' 预期生成的代码
157+
```
158+
135159
### redirect.style.path
136160

137161
是否自动重定向样式产物文件的导入路径。
@@ -145,6 +169,8 @@ import { foo } from './foo.mjs'; // './dist/utils/index.mjs' 预期生成的代
145169

146170
- **示例:**
147171

172+
`tsconfig.json` 中将 `compilerOptions.paths` 设置为 `{ "@/*": ["src/*"] }` 时,样式产物文件的导入路径将被重定向到正确的相对路径。
173+
148174
导入普通样式文件时:
149175

150176
```ts
@@ -155,7 +181,7 @@ import '@/foo.css'; // './src/utils/index.ts' 的源码 ↓
155181
import '../foo.css'; // './dist/utils/index.js' 预期生成的代码
156182
```
157183

158-
导入 [CSS Modules](/zh/config/rsbuild/output#outputcssmodules) 时:
184+
导入 [CSS Modules](/config/rsbuild/output#outputcssmodules) 时:
159185

160186
```ts
161187
import styles from '@/foo.css'; // './src/bar.ts' 的源码 ↓
@@ -175,7 +201,7 @@ import styles from '../foo.css'; // './dist/utils/index.js' 预期生成的代
175201
当设置为 `true` 时:
176202

177203
- 导入普通样式文件的文件扩展名将被重写为 `.css`
178-
- 导入 [CSS Modules](/config/rsbuild/output#outputcssmodules) 时,路径将被重写为到对应的 JavaScript 产物文件
204+
- 导入 [CSS Modules](/config/rsbuild/output#outputcssmodules) 时,文件扩展名将被重写为对应的 JavaScript 产物文件扩展名
179205

180206
当设置为 `false` 时,文件扩展名将保持原始导入路径。
181207

@@ -195,6 +221,15 @@ import styles from './index.module.mjs'; // 预期生成的代码
195221

196222
控制资源文件导入路径的重定向。
197223

224+
- **示例:**
225+
226+
默认情况下,在 `tsconfig.json` 中将 `compilerOptions.paths` 设置为 `{ "@/*": ["src/*"] }` 时,资源文件的导入路径将被重定向到正确的相对路径,扩展名将被重写为对应的 JavaScript 产物文件扩展名。
227+
228+
```ts
229+
import url from '@/assets/logo.svg'; // './src/foo.ts' 的源码 ↓
230+
import url from './assets/logo.mjs'; // './dist/foo.mjs' 预期生成的代码
231+
```
232+
198233
### redirect.asset.path
199234

200235
是否自动重定向资源文件的导入路径。
@@ -208,6 +243,8 @@ import styles from './index.module.mjs'; // 预期生成的代码
208243

209244
- **示例:**
210245

246+
`tsconfig.json` 中将 `compilerOptions.paths` 设置为 `{ "@/*": ["src/*"] }` 时,资源文件的导入路径将被重定向到正确的相对路径并
247+
211248
```ts
212249
import url from '@/assets/logo.svg'; // './src/foo.ts' 的源码 ↓
213250
import url from './assets/logo.svg'; // './dist/foo.js' 预期生成的代码
@@ -220,7 +257,7 @@ import url from './assets/logo.svg'; // './dist/foo.js' 预期生成的代码
220257
- **类型:** `boolean`
221258
- **默认值:** `true`
222259

223-
当设置为 `true` 时,导入资源文件的路径将被重写到对应的 JavaScript 产物文件
260+
当设置为 `true` 时,导入资源文件的扩展名将被重写为对应的 JavaScript 产物文件扩展名
224261

225262
当设置为 `false` 时,文件扩展名将保持原始导入路径。
226263

@@ -241,6 +278,15 @@ import url from './assets/logo.mjs'; // './dist/foo.mjs' 预期生成的代码
241278

242279
控制 TypeScript 类型文件中导入路径的重定向。
243280

281+
- **示例:**
282+
283+
默认情况下,在 `tsconfig.json` 中将 `compilerOptions.paths` 设置为 `{ "@/*": ["src/*"] }` 时,类型声明产物文件的导入路径将被重定向到正确的相对路径。
284+
285+
```ts
286+
import { foo } from '@/foo'; // './src/bar.ts' 的源码 ↓
287+
import { foo } from './foo'; // './dist/bar.d.ts' 预期生成的代码
288+
```
289+
244290
### redirect.dts.path
245291

246292
是否自动重定向 TypeScript 类型文件中的导入路径。
@@ -254,7 +300,7 @@ import url from './assets/logo.mjs'; // './dist/foo.mjs' 预期生成的代码
254300

255301
- **示例:**
256302

257-
`tsconfig.json` 中将 `compilerOptions.paths` 设置为 `{ "@/*": ["src/*"] }` 时,类型声明产物文件将被重定向到正确的相对路径
303+
`tsconfig.json` 中将 `compilerOptions.paths` 设置为 `{ "@/*": ["src/*"] }` 时,类型声明产物文件中的导入路径将被重定向到正确的相对路径
258304

259305
```ts
260306
import { foo } from '@/foo'; // './src/bar.ts' 的源码 ↓

0 commit comments

Comments
 (0)