[英]Using tsconfig paths with Angular libraries?
我正在創建一個 Angular 庫,並在tsconfig.lib.json
添加了以下paths
配置:
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"declaration": true,
"inlineSources": true,
"types": [],
"lib": [
"dom",
"es2018"
],
"paths": {
"@fs/*": ["src/lib/*"]
}
}
但是嘗試導入以下內容:
import { Test } from '@fs/Test'
不起作用。 任何人都知道 Angular 庫是否支持tsconfig.lib.json
hte paths
配置選項?
通常我使用typescript-transform-paths
對編譯結果執行路徑轉換,我希望 Angular 已經為庫烘焙了這樣的東西?
嘗試在tsconfig.json文件中使用以下模式:
"paths": {
"@services/*": ["app/path/to/services/*"],
"@components/*": ["app/path/to/some/deeply/nested/component/*"],
"@environments/*": ["environments/*"]
},
然后在導入時:
import { yourServiceClass } from "@services/yourServiceClass";
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.