vite-plugin-dts

vite-plugin-dts
147,380,553 1,531
Install
npm install vite-plugin-dts
Latest Version:5.1.2
Older releases:3
License:MIT
Last Updated:Oct 3, 2026
Links: GitHub  ·  npm
Maintainer: qmhc

Install

pnpm i -D vite-plugin-dts

Usage

In vite.config.ts:

import { resolve } from 'path'
import { defineConfig } from 'vite'
import dts from 'vite-plugin-dts'

export default defineConfig({
  build: {
    lib: {
      entry: resolve(__dirname, 'src/index.ts'),
      name: 'MyLib',
      formats: ['es'],
      fileName: 'my-lib',
    },
  },
  plugins: [dts()],
})

By default, the generated declaration files are following the source structure.

Fortunately, with the help of API Extractor, the plugin can bundle all types into a single file. You just need to install @microsoft/api-extractor and set bundleTypes: true:

export default defineConfig({
  plugins: [dts({ bundleTypes: true })],
})

When moduleFormat is omitted, the plugin preserves TypeScript's declaration extensions: .ts → .d.ts, .mts → .d.mts, and .cts → .d.cts, including declaration maps.

Declaration maps preserve absolute file:// source URLs, including Windows cross-drive paths, across all output directories.

When publishing both ESM and CommonJS, explicitly add outDirs entries with moduleFormat: 'esm' and moduleFormat: 'cjs'; Vite's JavaScript formats are not inferred. Each entry is bundled once and reused for both declaration formats. Configure conditional exports.types entries separately in package.json.

If you start with official Vite template, you should specify the tsconfigPath:

export default defineConfig({
  plugins: [dts({ tsconfigPath: './tsconfig.app.json' })],
})

Documentation

For full documentation, please refer to unplugin-dts.

Example

A real project using this plugin: Vexip UI.

License

MIT License.

Related Packages

unplugin-dts

unplugin-dts

18,163,029 1,531
@seepine/vue-tsc

vue-tsc 的 Node 入口:在标准 tsc 之上注入 Volar Vue 语言插件,使命令行与编辑器都...

64 0
@vitejs/plugin-vue

The official plugin for Vue SFC support in Vite.

257,315,514 686
vite-plugin-checker

Vite plugin that runs TypeScript type checker on a separate process.

133,975,562 1,242

Version History

Version Released License
5.1.2 MIT
5.1.1 MIT
5.1.0 MIT
5.0.3 MIT
5.0.2 MIT
Pre-releases (21)
Version Released License
5.0.0-beta.6 MIT
5.0.0-beta.5 MIT
5.0.0-beta.4 MIT
5.0.0-beta.3 MIT
5.0.0-beta.2 MIT