A Vite plugin that automatically resolves TypeScript path aliases defined in tsconfig.json (paths and baseUrl). Version 1.4.1 released on npm. It eliminates the need for manual resolve.alias configuration in Vite projects using TypeScript paths. Compared to alternatives like vite-tsconfig-paths (from aleclarson), this plugin is lightweight, actively maintained by lightyen, and supports newer Vite versions. It ships TypeScript types, requires Vite as a peer dependency (works with Vite 2+), and works with both ESM and CJS module systems. The plugin automatically discovers tsconfig.json and applies path mappings to Vite's resolver.
npm install vite-plugin-tsconfig-pathsVerified import paths — ran on the pinned version, not inferred.
Shows basic usage of the plugin in a Vite configuration file, with optional 'loose' option for non-ts-node compatible paths.
Ensure this plugin is placed after custom resolver plugins in the plugins array, or remove custom resolvers.
Update config: tsConfigPaths({ loose: true }) or tsConfigPaths({ loose: 'end' })Upgrade Node.js to >=14.18 and Vite to >=3.
Install the package as dev dependency: npm install -D vite-plugin-tsconfig-paths
Use import instead of require: import tsConfigPaths from 'vite-plugin-tsconfig-paths'
Change to default import: import tsConfigPaths from 'vite-plugin-tsconfig-paths'