Giter Site home page Giter Site logo

xunnamius / tsconfig-replace-paths Goto Github PK

View Code? Open in Web Editor NEW

This project forked from jonkwheeler/tsconfig-replace-paths

1.0 2.0 0.0 237 KB

Replace absolute paths to relative paths for package compilation

License: MIT License

JavaScript 78.98% TypeScript 21.02%

tsconfig-replace-paths's Introduction

tsconfig-replace-paths

Replace absolute paths to relative paths for package compilation.

I'll add to this over time. Submit PR's if you like. Tag me on them.

Getting Started

First, install tsconfig-replace-paths as devDependency using yarn or npm.

yarn add -D tsconfig-replace-paths

or

npm install --save-dev tsconfig-replace-paths

Add it to your build scripts in package.json

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

What if you want to build only the types?

You can also setup a seperate tsconfig file just for types if you are also compiling with Babel. Assuming you're compiling CommonJs, make a tsconfig.types.cjs.json. See examples of both CommonJs and ESM in the examples folder within repo.

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

And then target that. Your final build script might look like this. You first compile to CommonJs using Babel, and then build the types using the Typescript Compiler, tsc, followed by fixing the paths them with tsconfig-replace-paths. If only tsc did this for you.

"config": {
  "dirBuild": "./dist",
  "dirSrc": "./src",
},
"scripts": {
  "build:commonjs": "yarn nuke:build && cross-env BABEL_ENV=commonjs babel $npm_package_config_dirSrc --out-dir $npm_package_config_dirBuild --extensions \".ts,.tsx,.js,.jsx\" --source-maps inline",
  "build:types:commonjs": "tsc --project tsconfig.types.cjs.json && tsconfig-replace-paths --project tsconfig.types.cjs.json",
  "build:types": "yarn build:types:commonjs",
  "build": "yarn build:commonjs && yarn build:types",
  "nuke:build": "rm -rf $npm_package_config_dirBuild",
}

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

Inspired by

tsconfig-paths and tscpaths

tsconfig-replace-paths's People

Contributors

jonkwheeler avatar dependabot[bot] avatar xunnamius avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.