Replace absolute paths to relative paths after typescript compilation (tsc) during compile-time. You can add aliases that reference other projects outside your tsconfig.json project by providing a relative path to the baseUrl.
Comparison to tsconfig-paths
+ Compile time (no runtime dependencies)
First, install tsc-alias as devDependency using npm.
npm install -g tsc-alias
npm install --save-dev tsc-alias
"scripts": {
"build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
}
================ OR ===================
"scripts": {
"build": "tsc && tsc-alias",
"build:watch": "tsc -w && tsc-alias -w"
}
npm install tsc-alias
import { replaceTscAliasPaths } from 'tsc-alias';
replaceTscAliasPaths(options?);
Here are all the available options:
Option | Description | Default Value |
---|---|---|
configFile | path to tsconfig.json | 'tsconfig.json' |
watch | Observe file changes | false |
outDir | Run in a folder leaving the "outDir" of the tsconfig.json (relative path to tsconfig) | tsconfig.compilerOptions.outDir |