Skip to content

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

sh
npm i -D @chialab/vite-plugin-isolated-decl
sh
yarn add -D @chialab/vite-plugin-isolated-decl
sh
pnpm add -D @chialab/vite-plugin-isolated-decl

Configuration

Add the plugin to your Vite config:

ts
import isolatedDeclPlugin from '@chialab/vite-plugin-isolated-decl';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    isolatedDeclPlugin(),
  ],
});
ts
{
  "compilerOptions": {
    "isolatedDeclarations": true,
  }
}

Other plugins

unplugin-isolated-decl

✅ 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.

rolldown-plugin-dts

✅ 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.

Released under the MIT License.