简体   繁体   English

如何在不构建的情况下为库(Angular MonoRepo)使用 tsconfig 路径别名

[英]How to use tsconfig path aliases for libraries (Angular MonoRepo) without build

I have an Angular MonoRepo.我有一个 Angular MonoRepo。 Within this is the main App project, which is supported by several libraries.其中是主要的 App 项目,它由多个库支持。

Currently, the above are using tsconfig paths dist/{library_name} for references.目前,以上使用 tsconfig 路径dist/{library_name}作为参考。 This setup requires building libraries when changes to their code occurs.此设置需要在代码发生更改时构建库。 For distribution, I appreciate this is needed.对于分发,我很欣赏这是需要的。

For development, I would prefer to change tsconfig paths to the library source files, so that when changes are made the application ( ng serve ) auto-rebuilds.对于开发,我更愿意将 tsconfig 路径更改为库源文件,以便在进行更改时应用程序( ng serve )自动重建。 This would allow changes to be made more quickly.这将允许更快地进行更改。

I have tried to change the path to the library src files as follows:我尝试将库 src 文件的路径更改如下:

"./projects/module-system/src"
"projects/module-system/src"
"../projects/module-system/src"
"../../projects/module-system/src"

The base URL is set to:基础 URL 设置为:

"baseUrl": "./"

All of these lead to "module not found" errors.所有这些都会导致“找不到模块”错误。

Is this possible in Angular?这在 Angular 中可行吗? If so, what is the correct tsconfig setup?如果是这样,正确的 tsconfig 设置是什么?

Yes it is possible in Angular, on your tsconfig.json update your lib alias to:是的,可以在 Angular 中,在您的 tsconfig.json 上将您的 lib 别名更新为:

      "module-system": [
        "projects/module-system/src/public-api.ts"
      ],

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM