vite-plugin-isolated-decl
A Vite plugin to generate isolated declaration files for TypeScript sources.
It uses the TypeScript compiler API to generate declaration files for each source file, without bundling them together. Output declaration files are emitted in the output directory, with the same structure as the source files.
INFO
Isolated declarations must be enabled in the TypeScript configuration (tsconfig.json) by setting the compilerOptions.isolatedDeclarations option to true.
Install
npm i -D @chialab/vite-plugin-isolated-declyarn add -D @chialab/vite-plugin-isolated-declpnpm add -D @chialab/vite-plugin-isolated-declConfiguration
Add the plugin to your Vite config:
import isolatedDeclPlugin from '@chialab/vite-plugin-isolated-decl';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
isolatedDeclPlugin(),
],
});{
"compilerOptions": {
"isolatedDeclarations": true,
}
}Other plugins
✅ As any other "unplugin", it works with multiple bundlers and supports multiple declaration generators.
❌ It requires entryFileNames option to be a pattern string, which does not work well with Vite's lib mode fileName option.
✅ Uses native Rolldown support to transpile and bundle declaration files, which is faster than using the TypeScript compiler API.
❌ Bundling declarations files sometimes fails with edge cases.