tsc-alias
    TypeScript icon, indicating that this package has built-in type declarations

    1.5.0 • Public • Published

    tsc-alias

    Replace alias paths with relative paths after typescript compilation. You can add aliases that reference other projects outside your tsconfig.json project by providing a relative path to the baseUrl.

    npm version License

    Comparison to tsconfig-paths

    + Compile time (no runtime dependencies)

    Getting Started

    First, install tsc-alias as devDependency using npm.

    npm install -g tsc-alias
    npm install --save-dev tsc-alias
    

    Add it to your build scripts in package.json

    "scripts": {
      "build": "tsc --project tsconfig.json && tsc-alias -p tsconfig.json",
    }
    
    ================ OR ===================
    
    "scripts": {
      "build": "tsc && tsc-alias",
      "build:watch": "tsc -w & tsc-alias -w"
    }

    API

    Installation

    npm install tsc-alias

    Usage

    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
    declarationDir Works the same as outDir but for declarationDir tsconfig.compilerOptions.declarationDir
    resolveFullPaths Attempt to replace incomplete import paths (those not ending in .js) with fully resolved paths (for ECMAScript Modules compatibility) false
    silent Reduced terminal output. This is a deprecated option and no longer has any effect. true
    verbose Additional information is output to the terminal false
    replacers Files to import as extra replacers More info []
    output The output object tsc-alias will send logs to. new Output(options.verbose)

    Configuration via tsconfig.json Example

    {
      "compilerOptions": {
        ...
      },
      "tsc-alias": {
        "verbose": false,
        "resolveFullPaths": true,
        "replacers": {
          "exampleReplacer": {
            "enabled": true,
            "file": "./exampleReplacer.js"
          },
          "otherReplacer": {
            "enabled": true,
            "file": "./otherReplacer.js"
          }
        }
      }
    }

    Install

    npm i tsc-alias

    DownloadsWeekly Downloads

    136,845

    Version

    1.5.0

    License

    MIT

    Unpacked Size

    98.9 kB

    Total Files

    45

    Last publish

    Collaborators

    • justkey