我正在尝试使用 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),那么一切都会按原样构建和运行,但在生产中,这条路径当然不存在。>
我尝试了什么:
我开始相信我不能为这样的结构取别名。
我在这里遗漏了什么?