This morning has been dedicated to exploring ts-paths in order to shorten my import paths.
After some experimentation, I have found that custom paths do work IF you set up barreling (having an index file that exports your modules)
root
├── client
│ ├──tsconfig.json
│ ├── src
│ ├──app
│ ├── shared
│ ├── services
│ ├── some.service.ts
├── common
│ ├── index.ts // exports * from each file
The tsconfig.ts for my NG8 looks like:
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@common": ["../common"], // functional with barreling
"@services": ["./src/app/shared/services"] // only works with barreling
},
The usage of @services
does not work... unless barreling is set up
(by including an index.ts
file in the shared
folder with export * from './some.service';
)
@common
functions as intended because of the barrel setup mentioned above.
Am I overlooking something or are the resources I've consulted omitting a step to export modules in this manner?
References:
https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping
How to use paths in tsconfig.json?
and many more...