Replace import alias paths to relative paths via tsconfig-paths.
$ yarn add --dev tsconfig-paths-replace
Use &&
operator to run replace after transpile via tsc
.
{
"scripts": {
"build": "tsc && tsconfig-paths-replace -s ./src"
},
}
You can replace paths while run tsc in watch (-w, --watch
) mode. Create new tsconfig.json file with different name (for now tsconfig.watch.json
).
// tsconfig.watch.json
{
"extends": "./tsconfig.json",
"compilerOptions": {
"incremental": true,
"tsBuildInfoFile": "./buildcache/watch.tsbuildinfo"
// ...
}
}
With tsc-watch, you can use callback --onSuccess
after transpile done. Put tsconfig-paths-replace
script at success command.
{
"scripts": {
"watch": "tsc-watch -p tsconfig.watch.json --noClear --noColors --onSuccess \"tsconfig-paths-replace -p ./tsconfig.watch.json\"",
},
}
Usage: tsconfig-paths-replace [options]
Options:
-V, --version output the version number
-p, --project <file> path to tsconfig.json
-c, --cwd <path> current working directory
-r, --root <path> root path of source (or `compilerOptions.rootDir`)
-o, --out <path> path of transpiled code output directory (or `compilerOptions.outDir`)
-e, --emit <path> output dir for emitted files (use `out` path by default)
-w, --watch watch changes of output directory
-h, --help display help for command