• Stars
    star
    1,027
  • Rank 44,827 (Top 0.9 %)
  • Language
    TypeScript
  • License
    MIT License
  • Created about 4 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Support for TypeScript's path mapping in Vite

๐Ÿ‘‹ Do you like Postgres ๐Ÿ˜? I'm making a 100% type-safe query builder (not an ORM), and I want your help fleshing it out.
Btw, it generates the types and client from your database schema, so it's never out-of-date and you have access to every native Postgres function!
I want to add a powerful plugin system soon, and eventually all functionality will be pluggable.

Learn more


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 search for tsconfig.json files.

    The default value of this option depends on whether projects is defined. If it is, then the Vite project root is used. Otherwise, Vite's searchForWorkspaceRoot function is used.

  • projects: string[]
    If you have an esoteric setup, you might need this option to specify where your tsconfig files are located. The paths within are relative to the root option.

    If defined, the root directory won't be searched for tsconfig files. You should always try using just the root option first, because this option is more brittle.

  • loose: boolean
    Disable strictness that limits path resolution to TypeScript and JavaScript importers.

    Useful if you want imports in Vue templates to be resolved, but don't want to use allowJs in your tsconfig, for example.

    In other words, when loose: true is used, any file that gets transpiled into JavaScript will have its imports resolved by this plugin.

  • parseNative: boolean
    Enable use of the tsconfck.parseNative function, which delegates the loading of tsconfig files to the TypeScript compiler. You'll probably never need this, but I added it just in case.

    โš ๏ธ This option can slow down Vite's startup time by as much as 600ms, due to the size of the TypeScript compiler. Only use it when necessary.

  • ignoreConfigErrors: boolean
    When true, parsing errors encountered while loading tsconfig files will be ignored. This is useful if you have a monorepo with multiple tsconfig files, and you don't want to see errors for the ones that aren't relevant to the current project.

ย 

allowJs

If your tsconfig file has "allowJs": true in it, path resolution will be expanded beyond TypeScript importers. 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 tsconfig 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.

More Repositories

1

emitter-kit

Type-safe event handling for Swift
Swift
571
star
2

ee-ts

Type-safe, isomorphic event emitters
TypeScript
123
star
3

hex-kit

Convert hex triplets into UIColors and CGColors!
Swift
68
star
4

spec.ts

Write tests for your types!
JavaScript
50
star
5

markdown-ast

Tiny markdown parser
JavaScript
39
star
6

module-extractor

Extract a JS/TS module and its dependencies into a new package
TypeScript
14
star
7

esbuild-extra

Extra features for esbuild plugins (like onTransform hook)
TypeScript
13
star
8

grunt-then

Anonymous tasks and targets in Grunt.
CoffeeScript
13
star
9

meteor-client

The client-side core of Meteor
JavaScript
12
star
10

rethinkdb-mock

In-memory RethinkDB
CoffeeScript
7
star
11

glob-regex

Tiny glob-to-RegExp converter
JavaScript
7
star
12

sql-ast

MySQL parser
JavaScript
7
star
13

get-dev-paths

Search node_modules for locally developed packages
CoffeeScript
7
star
14

immer-undo

Generate inverse Immer patches on-the-fly
TypeScript
6
star
15

uvu-watch

Watch mode for uvu test runner
JavaScript
6
star
16

mini-hb

Tiny handlebars engine (made with TypeScript)
TypeScript
6
star
17

babel-register

JavaScript
5
star
18

vs-auto-typings

Managed @types/* packages for VS Code
TypeScript
5
star
19

nitro-lang

Minimal scripting language that embraces immutability and reactivity (concept)
TypeScript
5
star
20

rafz

Coordinate `requestAnimationFrame` calls across your app and/or libraries
TypeScript
5
star
21

vite-plugin-template

JavaScript
4
star
22

443

Automated SSL certificates using Let's Encrypt
JavaScript
4
star
23

ddp

Meteor's latency-compensated distributed data client
JavaScript
4
star
24

vite-plugin-react-lazy

Seamless conditional imports with React Suspense
TypeScript
4
star
25

nomatter

Remove YAML front matter from a string. No dependencies.
JavaScript
3
star
26

mixpa

Tiny, isomorphic client for Mixpanel
TypeScript
3
star
27

cush-shell

Throwaway shell scripts
TypeScript
3
star
28

check-git-patch

Find errors and conflicts in a git patch
TypeScript
2
star
29

typescript-rewrite-paths

Rewrite import paths in TypeScript code
TypeScript
2
star
30

vscode-lsp-template

TypeScript
2
star
31

is-node-env

Know when your code is running in a NodeJS environment.
JavaScript
2
star
32

lotus-runner

A framework-agnostic test runner for Node.
CoffeeScript
2
star
33

changed-lines

Compare strings just like `git diff` does
JavaScript
2
star
34

steal

Array.prototype.pop for objects
CoffeeScript
2
star
35

yender

Yield for render props
TypeScript
2
star
36

with-scope

Expose the properties of a given `Object` as local variables to a given `Function`.
CoffeeScript
2
star
37

repro

Bug reproductions
1
star
38

tslint-mango

Opinionated TSLint preset -- Prettier compatible, JSX ready, no semicolons
TypeScript
1
star
39

isNodeJS

Returns true when in NodeJS
JavaScript
1
star
40

lodge

Isomorphic console w/ inspection, colors, namespaces, and configuration
CoffeeScript
1
star
41

measureText

Measure text without rendering it (for React Native)
CoffeeScript
1
star
42

mongo

Adaptor for using MongoDB and Minimongo over DDP
JavaScript
1
star
43

vscode-seoul-dark

1
star
44

lua-emitter

Event emitters for Lua
MoonScript
1
star
45

ReactiveVar

Reactive variables for Javascript
CoffeeScript
1
star
46

keymirror

A flexible key mirror. { key1: "key1", key2: "key2" }
CoffeeScript
1
star
47

spy-on

TypeScript
1
star
48

save-heap

Save heap snapshots with ease.
CoffeeScript
1
star
49

vocus

Memory-conscious, real-time audio manipulator in Node.js
1
star
50

StatusBar

StatusBar singleton for React Native
CoffeeScript
1
star
51

is-open-comment

Returns true if a string has an unclosed comment
JavaScript
1
star
52

bocks

JavaScript
1
star
53

fsx

User-friendly file operations for NodeJS
CoffeeScript
1
star
54

recrawl

Filesystem crawler
TypeScript
1
star
55

lotus-log

An extensible, platform-agnostic logging library
JavaScript
1
star
56

resolve-symlink

Follow a trail of symlinks
JavaScript
1
star
57

relative

Ultra fast relative path resolver
TypeScript
1
star
58

lotus-jasmine

Use the Jasmine testing framework with lotus-runner
CoffeeScript
1
star
59

react-dev-ssr

JSX runtime + Babel transform โ€“ Step through React component trees with a synchronous stack trace
TypeScript
1
star
60

parse-bool

Convert a string to a boolean
JavaScript
1
star
61

fsx-mock

JavaScript
1
star
62

shrink-array

Shrink an array with a subset reducer
JavaScript
1
star
63

slurm

CLI argument parser
JavaScript
1
star
64

lotus-coffee

CoffeeScript
1
star
65

combine

Combine multiple objects into an existing object
CoffeeScript
1
star
66

telegram-tl-node

JavaScript
1
star
67

alien-dom-todoist

Created with StackBlitz โšก๏ธ
TypeScript
1
star
68

json-stream

Fork of @streamparser/json-whatwg
TypeScript
1
star
69

Property

A class for property descriptors
CoffeeScript
1
star
70

lotus-lab

CoffeeScript
1
star
71

journey

Client-side routing
JavaScript
1
star
72

key-bindings

Bind keystrokes to functions in NodeJS
CoffeeScript
1
star
73

define

The better Object.defineProperty
CoffeeScript
1
star
74

process

A simple, configurable Process type for Javascript
CoffeeScript
1
star
75

valido

Fast and flexible validation engine (13kb unminified)
CoffeeScript
1
star
76

package-live-reload

Atom service that reloads Atom packages on file changes
CoffeeScript
1
star
77

round

Robust fraction rounding
JavaScript
1
star
78

dough

๐Ÿ’ธ Rich, modern, imperative DOM wrappers
JavaScript
1
star
79

umd-cli

Generate UMD bundles from NPM packages (using https://packd.now.sh)
JavaScript
1
star
80

weak-map

A weak map for the browser and Node.
CoffeeScript
1
star
81

diff-sequence

An implementation of a diff algorithm on arrays and objects
JavaScript
1
star
82

gesture

A gesture library for React & React Native
CoffeeScript
1
star
83

minimongo

Meteor's client-side datastore: a port of MongoDB to Javascript
JavaScript
1
star
84

condo

Simple, event-based state wrappers with optional validation
JavaScript
1
star
85

hasKeys

Know if Object.keys() would return an empty array
JavaScript
1
star
86

sortObject

Sort an object by its keys and/or values
CoffeeScript
1
star
87

map-filter-ts

Map an iterable, filter out undefined results
JavaScript
1
star
88

telegram-mt-node

JavaScript
1
star
89

lotus-git

UNMAINTAINED - Check out https://github.com/aleclarson/scripts
CoffeeScript
1
star
90

slush

Basic HTTP server for NodeJS
JavaScript
1
star