1.3.0 • Published 7 months ago

typescript-transform-path-rewrite v1.3.0

Weekly downloads
-
License
MIT
Repository
github
Last release
7 months ago

typescript-transform-path-rewrite

Build Status Publish Status

npm Conventional Commits code style: prettier

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 run ts-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"
               ]
           },
       ]
   },
}
1.3.0

7 months ago

1.2.3

7 months ago

1.2.2

7 months ago

1.2.1

7 months ago

1.2.0

7 months ago

1.1.0

11 months ago

1.0.0

11 months ago

0.0.1

11 months ago