Transform generated javascript import/require paths using typescript standard config. Support typescript version 5.
npm install --save-dev typescript-transform-path-rewriteThe result javascript files will have all @SRC/* import transformed to proper paths.
Use ts-patch's tspc instead of tsc
ts-node must be used with ts-patch
{
"ts-node": {
"compiler": "ts-patch/compiler",
},
}Note:
ts-nodehas issue with Node.js 20 and ESM, to runts-nodein this scenario, use this command
node --loader ts-node/esm <YOUR_TS_FILE>
The transformer will make sure javascript files that are compiled with tsconfig.json's module configured for ECMAScript Module will have full extension (either .js or .mjs) as required by Node.js
Custom rules can be added using regular expression, for example
{
"compilerOptions": {
"paths": {
"@SRC/*": ["./src/*"]
},
"plugins": [
{
"transform": "typescript-transform-path-rewrite",
"alias": [
"@SRC/custom/(.+)$": "./my-custom/$1.js"
]
},
]
},
}
{ "compilerOptions": { "paths": { "@SRC/*": ["./src/*"], }, "plugins": [ // Transform javascript file { "transform": "typescript-transform-path-rewrite", }, // Transform .d.ts file { "transform": "typescript-transform-path-rewrite", "afterDeclarations": true, }, ], }, }