JSPM

  • Created
  • Published
  • Downloads 267904
  • Score
    100M100P100Q178790F
  • License MIT

Transforms module resolution paths using TypeScript path mapping

Package Exports

  • typescript-transform-paths

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (typescript-transform-paths) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

typescript-transform-paths

npm version Build Status Appveyor Build status Conventional Commits code style: prettier All Contributors

Transform module resolution paths in compiled output source to conform with TypeScript internal resolution via tsconfig.json settings (paths, rootDirs, baseUrl)

Install

# NPM
npm i -D typescript-transform-paths

# Yarn
yarn add -D typescript-transform-paths

Usage with ttypescript or ts-patch

Add it to plugins in your tsconfig.json

Example Config

{
  "compilerOptions": {
    "baseUrl": "./",
    "paths": {
      "@utils/*": ["utils/*"]
    },
    "plugins": [
      // Tranform paths in output .js files
      { "transform": "typescript-transform-paths" },

      // Tranform paths in output .d.ts files
      { "transform": "typescript-transform-paths", "afterDeclarations": true }
    ]
  }
}

core/index.ts

import { sum } from "@utils/sum";
sum(2, 3);

core/index.js (compiled output)

// core/index.js
var sum_1 = require("../utils/sum");
sum_1.sum(2, 3);

Virtual Directories

TS allows defining virtual directories via the rootDirs compiler option.
To enable virtual directory mapping, use the useRootDirs plugin option.

{
  "compilerOptions": {
    "rootDirs": [ "src", "generated" ],
    "baseUrl": ".",
    "paths": {
      "#root/*": [ "./src/*", "./generated/*" ]
    },
    "plugins": [
      { "transform": "typescript-transform-paths", "useRootDirs": true },
      { "transform": "typescript-transform-paths", "useRootDirs": true, "afterDeclarations": true }
    ]
  }
}

Example

- src/
    - subdir/
      - sub-file.ts
    - file1.ts
- generated/
    - file2.ts

src/file1.ts

import '#root/file2.ts' // resolves to './file2'

src/subdir/sub-file.ts

import '#root/file2.ts' // resolves to '../file2'
import '#root/file1.ts' // resolves to '../file1'

Articles

Project Guidelines for Contributors

  • Package Manager: yarn (yarn install)
  • Commit messages: Conventional Commit Specs
  • Format before commit: prettier (yarn run format)
  • Releases: standard-version (yarn run release)

Maintainers


Ron S.

Daniel Perez Alvarez

Contributors

Thanks goes to these wonderful people (emoji key):


Daniel Perez Alvarez

πŸ’» 🚧 ⚠️

ΠœΠΈΡ…Π°ΠΉΠ»ΠΎΠ² Антон

πŸ’» πŸ› ⚠️

Joshua Avalon

πŸ› πŸ“¦

Robert Laverty

πŸ› ⚠️

Ole Ersoy

πŸ› πŸ“

sbmw

πŸ›

richardspence

πŸ›

Vitaly Pinchuk

πŸ›

laij84

πŸ›

dko-slapdash

πŸ›

hedwiggggg

πŸ› ⚠️ πŸ’»

kuskoman

πŸ“–

alex weidner

πŸ›

Ron S.

πŸ› ⚠️ πŸ’»

Vladimir Yakovlev

πŸ›

vwpo

πŸ›

This project follows the all-contributors specification. Contributions of any kind welcome!