Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

tsconfig-replace-paths

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tsconfig-replace-paths

Replace absolute paths to relative paths for package compilation

  • 0.0.14
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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

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

Inspired by

tsconfig-paths and tscpaths

Keywords

FAQs

Package last updated on 09 Mar 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc