vite-plugin-dts is a Vite plugin that generates TypeScript declaration files (.d.ts) from your source code during the build process. Current stable version is 4.5.4, with frequent releases. It integrates with both TypeScript's built-in compiler and vue-tsc for Vue SFC support. Key differentiators include support for bundling declarations via @microsoft/api-extractor, path alias resolution, and a flexible plugin system with hooks like afterBootstrap. It is the de facto standard for declaration generation in Vite projects, actively maintained with a strong focus on compatibility and performance.
npm install vite-plugin-dtsVerified import paths — ran on the pinned version, not inferred.
Shows the basic configuration of vite-plugin-dts in a Vite config file. Includes include, outDir, and optional bundleTypes.
Replace 'beforeBundle' with 'afterBootstrap' in the plugin options.
Switch to ESM imports: import dts from 'vite-plugin-dts'
Set 'tsconfigPath' to the correct tsconfig file path, e.g., 'tsconfig.json'.
Specify a more precise 'include' pattern, e.g., exclude 'test' or 'stories'.
Ensure your tsconfig has the correct 'paths' mapping and set 'tsconfigPath' option to the correct config.
Use 'import dts from 'vite-plugin-dts'' with ESM, and ensure the package is installed and not a type-only export.
Run 'npm install -D vite-plugin-dts' and ensure tsconfig 'types' includes 'vite/client' if needed.
Replace 'rollupTypes: true' with 'bundleTypes: true' in the plugin options.