justkey007 / tsc-alias

Replace alias paths with relative paths after typescript compilation
MIT License
876 stars 63 forks source link

Is it possible to only use my own replacer? #226

Closed UchihaYuki closed 1 month ago

UchihaYuki commented 1 month ago

I found even if I define my own replacer, the imports have already been transformed by some built-in replacers.

The main problem I want to resolve:

I found tsc-alias not work as I expected, for example:

// redis.ts
import { createClient, RedisClientType } from 'redis'; 
import { config } from './config';

will become

// redis.ts my
import { createClient, RedisClientType } from './redis.js';
import { config } from './config';

Although I only define the following in tsconfig.json:

  "compilerOptions": {
    "outDir": "./dist",
    "rootDir": "./src",
    "baseUrl": "./",
    "paths": {
      "src/*": ["./src/*"],
      "test/*": ["./test/*"]
    },
...
  },
  "include": ["src/**/*.ts"]

I hope it can only replace modules starting with src/ or test/.

UchihaYuki commented 1 month ago
  "tsc-alias": {    
    "replacers": {
      "default": {
        "enabled": false
      },
      "base-url": {
        "enabled": false
      },
      "mine": {
        "enabled": true,
        "file": "./tsc-alias-replacer.cjs"
      }
    }
  }

I solved it!