[英]Path aliases for Angular library project not wokring
我正在嘗試使用 ui 元素實現 Angular 庫。 該庫是一個monorepo,然后像這樣發布
@lib/core
@lib/i18n
@lib/ui
開發是在 Storybook 下完成的。
這是我的結構。
projects
lib
core
i18n
ui
tsconfig.json
ui 目錄下的組件依賴於 core 和 i18n 目錄。
父 tsconfig.json
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "es2015",
"module": "esnext",
"lib": [
"es2018",
"dom"
],
"paths": {
"@lib/core": ["projects/lib/core/src/*"],
"@lib/i18n": ["projects/lib/i18n"]
}
},
"angularCompilerOptions": {
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
i18n 目錄中的文件已正確解析,我可以 ctrl+單擊它們(使用 phpstorm)移動到文件。
來自@lib/core 的文件在編譯期間拋出這些錯誤
ERROR in /path/to/project/projects/lib/ui/src/lib/widgets/help/components/widget-button/cl-widget-button.component.ts
TS2307: Cannot find module '@lib/core' or its corresponding type declarations.
還有核心目錄的結構
public-api.ts 是我的入口點,包括所有出口
// index.ts
export * from './public-api.ts';
我使用類型別名的原因是模擬生產,如導入,其中所有軟件包都將通過 npm 分別安裝。
如果我使用相對路徑(../../../../path/to/core),那么一切都會按應有的方式構建和運行,但在生產中,這條路徑當然不存在。
我嘗試了什么:
我開始相信我不能為這樣的結構做別名。
我在這里想念什么?
我可以提供我的解決方案
tsconfig.json
中輸入: "paths": {
"@lib/core": [
"dist/lib/core", // it depends on your library name
"dist/core"
],
...
}
package.json
中添加命令"start:storybook": "ng build lib && ng serve storybook"
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.