Vite TypeScript Path Resolver

6.1.1 · active · verified Sun Apr 19

vite-tsconfig-paths is a Vite plugin designed to automatically resolve TypeScript `compilerOptions.paths` aliases within a Vite project. It simplifies development by allowing developers to use absolute or aliased paths defined in their `tsconfig.json` (or `jsconfig.json`) without requiring additional manual configuration in Vite's resolver. The current stable version is 6.1.1, with an active development branch leading to v7.0.0-alpha.1, which introduces a significant architectural shift towards the OXC and Rolldown ecosystem for enhanced performance and a reduced dependency footprint. The plugin offers features like on-demand `tsconfig` discovery, automatic watching and reloading of `tsconfig` files, and fine-grained control over resolution via options such as `importerFilter`. Its primary differentiator is its robust and performant solution for directly integrating with and resolving `tsconfig.paths` in Vite.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to install `vite-tsconfig-paths` and integrate it into `vite.config.ts`, enabling TypeScript path alias resolution.

import { defineConfig } from 'vite';
import { viteTsconfigPaths } from 'vite-tsconfig-paths';

export default defineConfig({
  plugins: [viteTsconfigPaths({
    // Optional: Specify configuration file names (defaults to ['tsconfig.json', 'jsconfig.json'])
    configNames: ['tsconfig.json'],
    // Optional: 'eager' (default) or 'lazy'. 'lazy' loads tsconfig on demand.
    projectDiscovery: 'eager',
    // Optional: Enable logging of resolution traces to a file.
    // logFile: true 
  })],
});

// Example tsconfig.json structure that this plugin resolves:
/*
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@components/*": ["src/components/*"],
      "@utils/*": ["src/utils/*"]
    }
  },
  "include": ["src"]
}
*/

view raw JSON →