typescript-transform-path-rewrite
v1.4.0
Published
Transform generated javascript import/require paths using typescript standard config
Downloads
128
Maintainers
Readme
typescript-transform-path-rewrite
Transform generated javascript import/require paths using typescript standard config. Support typescript version 5.
Quick start
Installation
npm install --save-dev typescript-transform-path-rewrite
Example tsconfig.json
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"@SRC/*": ["*"],
},
"plugins": [
// Transform javascript file
{
"transform": "typescript-transform-path-rewrite",
},
// Transform .d.ts file
{
"transform": "typescript-transform-path-rewrite",
"afterDeclarations": true,
},
],
},
}
The result javascript files will have all @SRC/*
import transformed to proper paths.
Run with ts-patch
Use ts-patch's tspc
instead of tsc
Run with ts-node
ts-node must be used with ts-patch
{
"ts-node": {
"compiler": "ts-patch/compiler",
},
}
Note:
ts-node
has issue with Node.js 20 and ESM, to runts-node
in this scenario, use this command
node --loader ts-node/esm <YOUR_TS_FILE>
ECMAScript Module
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
Custom rules can be added using regular expression, for example
{
"compilerOptions": {
"baseUrl": "src",
"paths": {
"@SRC/*": ["*"]
},
"plugins": [
{
"transform": "typescript-transform-path-rewrite",
"alias": [
"@SRC/custom/(.+)$": "./my-custom/$1.js"
]
},
]
},
}