0.0.9 • Published 5 years ago

@halkeye/tscpaths v0.0.9

Weekly downloads
2
License
MIT
Repository
github
Last release
5 years ago

tscpaths

Replace absolute paths to relative paths after typescript compilation (tsc) during compile-time.

npm version Dependency Status License

Comparison to tsconfig-paths

+ Compile time (no runtime dependencies)

Getting Started

First, install tscpaths as devDependency using npm or yarn.

npm install --save-dev tscpaths
# or
yarn add -D tscpaths

Add it to your build scripts in package.json

"scripts": {
  "build": "tsc --project tsconfig.json && tscpaths --project tsconfig.json",
}

Building only the types

You can also setup a seperate tsconfig file just for types like tsconfig.types.json if you are also compiling with Babel.

// tsconfig.types.json
{
  "extends": "./tsconfig",
  "compilerOptions": {
    "module": "amd",
    "outDir": "dist",
    "rootDir": "./src",
    "declaration": true,
    "declarationMap": false,
    "isolatedModules": false,
    "noEmit": false,
    "allowJs": false,
    "emitDeclarationOnly": true
  },
  "exclude": ["**/*.test.ts"]
}

And then target that

"scripts": {
  "build:types": "tsc --project tsconfig.types.json && tscpaths -project tsconfig.types.json",
}

Your final build script might look like

"scripts": {
  "build": "yarn build:commonjs && yarn build:types",
}

Options

flagdescription
-p --projectproject configuration file (tsconfig.json)
-s --srcsource code root directory (overrides the tsconfig provided)
-o --outoutput directory of transpiled code (tsc --outDir) (overrides the tsconfig provided)
-v --verboseconsole.log all the events

Disclaimer

This is not a mature project yet. Pull Requests are welcome!

It works for my setup so far.

It may not work correctly if your setup is too complicated, so please do some testing before pushing it to production!!!

Changelog

You need to provide -s (--src) and -o (--out), because it's hard to predict source and output paths based on tsconfig.json.

I've tried a little and failed. :(

The above is no longer neccesary <-- got you fam: @jonkwheeler