简体   繁体   中英

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

I have an Angular MonoRepo. Within this is the main App project, which is supported by several libraries.

Currently, the above are using tsconfig paths dist/{library_name} for references. 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. This would allow changes to be made more quickly.

I have tried to change the path to the library src files as follows:

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

The base URL is set to:

"baseUrl": "./"

All of these lead to "module not found" errors.

Is this possible in Angular? If so, what is the correct tsconfig setup?

Yes it is possible in Angular, on your tsconfig.json update your lib alias to:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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