@halkeye/tscpaths
TypeScript icon, indicating that this package has built-in type declarations

0.0.9 • Public • Published

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

flag description
-p --project project configuration file (tsconfig.json)
-s --src source code root directory (overrides the tsconfig provided)
-o --out output directory of transpiled code (tsc --outDir) (overrides the tsconfig provided)
-v --verbose console.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

Package Sidebar

Install

npm i @halkeye/tscpaths

Weekly Downloads

2

Version

0.0.9

License

MIT

Unpacked Size

51.2 kB

Total Files

24

Last publish

Collaborators

  • halkeye