GithubHelp home page GithubHelp logo

belgattitude / vite-tsconfig-paths Goto Github PK

View Code? Open in Web Editor NEW

This project forked from aleclarson/vite-tsconfig-paths

0.0 2.0 0.0 321 KB

Support for TypeScript's path mapping in Vite

License: MIT License

JavaScript 1.56% TypeScript 98.44%

vite-tsconfig-paths's Introduction

vite-tsconfig-paths

npm codecov Code style: Prettier Donate

Give vite the ability to resolve imports using TypeScript's path mapping.

Usage

  1. Install as dev dependency

  2. Inject vite-tsconfig-paths using the vite.config.ts module

    import { defineConfig } from 'vite'
    import tsconfigPaths from 'vite-tsconfig-paths'
    
    export default defineConfig({
      plugins: [tsconfigPaths()],
    })

Note: You need to restart Vite when you update your paths mappings.

Options

  • root: string
    The directory to crawl for tsconfig.json files.
    Defaults to viteConfig.root

  • projects: string[]
    An array of tsconfig.json paths (relative to viteConfig.root) and/or directories that contain a tsconfig.json file.
    This overrides the root option.

  • extensions: string[]
    File extensions to search for.
    Defaults to .ts | .tsx | .js | .jsx | .mjs

  • loose: boolean
    Disable strictness that limits path resolution to TypeScript and JavaScript modules.
    Useful if you want asset URLs in Vue templates to be resolved.

 

allowJs

If your tsconfig.json file has "allowJs": true in it, path resolution will be expanded beyond TypeScript modules. The following extensions will have their imports resolved by this plugin: .vue, .svelte, .mdx, .mjs, .js, .jsx

 

baseUrl

If the baseUrl is defined, it gets prepended to all bare imports, and its resolution will take precedence over node_modules. This is also how TypeScript does it.

Say the baseUrl is ../root and you import react. This plugin will use ../root/react if it exists. If not found, then react is resolved normally. The baseUrl is relative to the project root (where tsconfig.json lives).

 

include/exclude

The include and exclude compiler options are respected.

Internally, globrex is used for glob matching.

 

Troubleshooting

The DEBUG environment variable can be used to figure out why this plugin isn't working as you may have expected.

DEBUG=vite-tsconfig-paths yarn vite

Also, check out the Troubleshooting wiki page for more guidance.

 

Donate

If this package helps you, please donate! Any amount is greatly appreciated. 🥰

  • ETH: 0xa446626195bbe4d0697e729c1433a86fB6Cf66cF
  • BTC: 17vYtAUPKXzubMEnNcN8SiuFgicrd5Rp9A
  • KIN: GBU7RDRD7VDVT254RR6PGMBJESXQVDHJ5CGGODZKRXM2P4MP3G5QSAMH

vite-tsconfig-paths's People

Contributors

aleclarson avatar thebuilder avatar jamesknelson avatar jeremy-coleman avatar lanthaler avatar naranjamecanica avatar monkatraz avatar trixterthetux avatar josh-hemphill avatar

Watchers

James Cloos avatar  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.