All Projects → LeDDGroup → Typescript Transform Paths

LeDDGroup / Typescript Transform Paths

Licence: mit
Transforms absolute imports to relative

Programming Languages

typescript
32286 projects

Projects that are alternatives of or similar to Typescript Transform Paths

React Bnb Gallery
Simple react-based photo gallery inspired by Airbnb image gallery.
Stars: ✭ 145 (-12.65%)
Mutual labels:  npm-package
React Native Sass Transformer
Use Sass to style your React Native apps.
Stars: ✭ 151 (-9.04%)
Mutual labels:  transform
React Render In Browser
React library to render browser specific content
Stars: ✭ 157 (-5.42%)
Mutual labels:  npm-package
Tsconfig
Shared TypeScript config for my projects
Stars: ✭ 146 (-12.05%)
Mutual labels:  npm-package
Inspirational Quotes
💡 A simple NPM Package which returns random Inspirational Quotes. Get your daily quote and stay motivated! ✌️ 🌸
Stars: ✭ 150 (-9.64%)
Mutual labels:  npm-package
Gloria
Gloria is a static website generator, based on NodeJS.
Stars: ✭ 153 (-7.83%)
Mutual labels:  npm-package
Csv Writer
Convert objects/arrays into a CSV string or write them into a CSV file
Stars: ✭ 140 (-15.66%)
Mutual labels:  npm-package
Alfred Dark Mode
Alfred 3 workflow to toggle the system dark mode
Stars: ✭ 165 (-0.6%)
Mutual labels:  npm-package
Wechart
Create all the [ch]arts by cax or three.js - Cax 和 three.js 创造一切图[表]
Stars: ✭ 152 (-8.43%)
Mutual labels:  path
Gh Got
Convenience wrapper for Got to interact with the GitHub API
Stars: ✭ 156 (-6.02%)
Mutual labels:  npm-package
Omniparser
omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.
Stars: ✭ 148 (-10.84%)
Mutual labels:  transform
Homebridge Wol
A Wake on Lan plugin for Homebridge
Stars: ✭ 150 (-9.64%)
Mutual labels:  npm-package
Do Not Disturb
Control the macOS `Do Not Disturb` feature
Stars: ✭ 155 (-6.63%)
Mutual labels:  npm-package
Aws Lambda Libreoffice
85 MB LibreOffice to fit inside AWS Lambda compressed with Brotli
Stars: ✭ 145 (-12.65%)
Mutual labels:  npm-package
Magic Iterable
Call a method on all items in an iterable by calling it on the iterable itself
Stars: ✭ 159 (-4.22%)
Mutual labels:  npm-package
Ngx Cache
Cache utility for Angular
Stars: ✭ 144 (-13.25%)
Mutual labels:  npm-package
Transliterate
Convert Unicode characters to Latin characters using transliteration
Stars: ✭ 152 (-8.43%)
Mutual labels:  npm-package
Into Stream
Convert a string/promise/array/iterable/asynciterable/buffer/typedarray/arraybuffer/object into a stream
Stars: ✭ 167 (+0.6%)
Mutual labels:  npm-package
Mav active 3d planning
Modular framework for online informative path planning.
Stars: ✭ 164 (-1.2%)
Mutual labels:  path
Watermark
Add watermark on images use HTML5 and Javascript.
Stars: ✭ 154 (-7.23%)
Mutual labels:  npm-package

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/*"]
    },
    // Note: In order to transform *both* js and d.ts files, you need to add both of the below lines to plugins
    "plugins": [
      // Transform paths in output .js files
      { "transform": "typescript-transform-paths" },

      // Transform paths in output .d.ts files (Include this line if you output declarations 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'

Custom Control

Exclusion patterns

You can disable transformation for paths based on the resolved file path. The exclude option allows specifying glob patterns to match against resolved file path.

For an example context in which this would be useful, see Issue #83

Example:

{
  "compilerOptions": {
    "paths": {
      "sub-module1/*": [ "../../node_modules/sub-module1/*" ],
      "sub-module2/*": [ "../../node_modules/sub-module2/*" ],
    },
    "plugins": [
      { 
        "transform": "typescript-transform-paths", 
        "exclude": [ "**/node_modules/**" ]
      }
    ]
  }
}
// This path will not be transformed
import * as sm1 from 'sub-module1/index'

@transform-path tag

Use the @transform-path tag to explicitly specify the output path for a single statement.

// @transform-path https://cdnjs.cloudflare.com/ajax/libs/react/17.0.1/umd/react.production.min.js
import react from 'react' // Output path will be the url above

@no-transform-path

Use the @no-transform-path tag to explicitly disable transformation for a single statement.

// @no-transform-path
import 'normally-transformed' // This will remain 'normally-transformed', even though it has a different value in paths config

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):

🚧 ⚠️
Михайлов Антон

💻 🐛 ⚠️
📦
Robert Laverty

🐛 ⚠️
📝
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!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].