Skip to content

Commit c130a93

Browse files
authored
docs: improve documentation for dts.alias (#1391)
1 parent 4dc582e commit c130a93

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

packages/plugin-dts/README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ pluginDts({
147147

148148
Configure the path alias for declaration files.
149149

150-
`alias` will be merged with `compilerOptions.paths` configured in `tsconfig.json` and `alias` has a higher priority.
150+
The path aliases configured in `alias` should be resolved relative to the directory specified by `compilerOptions.baseUrl` in `tsconfig.json`. These aliases will be merged with `compilerOptions.paths`, and `alias` takes higher precedence.
151151

152152
In most cases, you don't need to use `alias`, but consider using it when you need to use path alias only in declaration files without wanting to affect JavaScript outputs. For example, map the declaration file of `foo` to `./compiled/foo`.
153153

@@ -159,6 +159,13 @@ pluginDts({
159159
});
160160
```
161161

162+
At this time, when [redirect.path](#redirectpath) is enabled, the import path of `foo` in the declaration file will be redirected to `./compiled/foo`.
163+
164+
```diff
165+
- export * from 'foo';
166+
+ export * from './compiled/foo';
167+
```
168+
162169
### autoExternal
163170

164171
- **Type:** `boolean`

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ When `dts.autoExtension` is set to `true`, the declaration file extension will b
235235

236236
Configure the path alias for declaration files.
237237

238-
`dts.alias` will be merged with `compilerOptions.paths` configured in `tsconfig.json` and `dts.alias` has a higher priority.
238+
The path aliases configured in `dts.alias` should be resolved relative to the directory specified by `compilerOptions.baseUrl` in `tsconfig.json`. These aliases will be merged with `compilerOptions.paths`, and `dts.alias` takes higher precedence.
239239

240240
In most cases, you don't need to use `dts.alias`, but consider using it when you need to use path alias only in declaration files without wanting to affect JavaScript outputs. For example, map the declaration file of `foo` to `./compiled/foo`.
241241

@@ -254,6 +254,13 @@ export default {
254254
};
255255
```
256256

257+
At this time, when [redirect.dts.path](/config/lib/redirect#redirectdtspath) is enabled, the import path of `foo` in the declaration file will be redirected to `./compiled/foo`.
258+
259+
```diff title="index.d.ts"
260+
- export * from 'foo';
261+
+ export * from './compiled/foo';
262+
```
263+
257264
### dts.tsgo
258265

259266
- **Type:** `boolean`

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ export default {
235235

236236
用于配置类型声明文件的路径别名。
237237

238-
`dts.alias` 会与 `tsconfig.json` 中配置的 `compilerOptions.paths` 合并,且 `dts.alias` 具有更高的优先级
238+
`dts.alias` 中配置的路径别名,其相对路径应基于 `tsconfig.json` `compilerOptions.baseUrl` 所指定的目录。这些别名会与 `compilerOptions.paths` 进行合并,且 `dts.alias` 的优先级更高
239239

240240
大部分情况下,你不需要使用 `dts.alias`,但当你需要在类型声明文件中使用路径别名却不希望影响 JavaScript 产物时,可以考虑使用它。比如,将 `foo` 的类型声明文件指向 `./compiled/foo`
241241

@@ -254,6 +254,13 @@ export default {
254254
};
255255
```
256256

257+
此时,当 [redirect.dts.path](/config/lib/redirect#redirectdtspath) 开启时,类型声明文件中对 `foo` 的导入路径将会被重定向为 `./compiled/foo`
258+
259+
```diff title="index.d.ts"
260+
- export * from 'foo';
261+
+ export * from './compiled/foo';
262+
```
263+
257264
### dts.tsgo
258265

259266
- **类型:** `boolean`

0 commit comments

Comments
 (0)