Skip to content

Commit ff21cd7

Browse files
committed
feat: paths mapping relative to baseUrl. PR541
1 parent b6d9ec4 commit ff21cd7

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

doc/handbook/Module Resolution.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,12 +215,16 @@ TypeScript编译器通过使用`tsconfig.json`文件里的`"paths"`来支持这
215215
"compilerOptions": {
216216
"baseUrl": ".", // This must be specified if "paths" is.
217217
"paths": {
218-
"jquery": ["node_modules/jquery/dist/jquery"]
218+
"jquery": ["node_modules/jquery/dist/jquery"] // 此处映射是相对于"baseUrl"
219219
}
220220
}
221221
}
222222
```
223223

224+
请注意`"paths"`是相对于`"baseUrl"`进行解析。
225+
如果`"baseUrl"`被设置成了除`"."`外的其它值,比如`tsconfig.json`所在的目录,那么映射必须要做相应的改变。
226+
如果你在上例中设置了`"baseUrl": "./src"`,那么jquery应该映射到`"../node_modules/jquery/dist/jquery"`
227+
224228
通过`"paths"`我们还可以指定复杂的映射,包括指定多个回退位置。
225229
假设在一个工程配置里,有一些模块位于一处,而其它的则在另个的位置。
226230
构建过程会将它们集中至一处。

0 commit comments

Comments
 (0)