JSPM

  • Created
  • Published
  • Downloads 1367132
  • Score
    100M100P100Q265179F
  • License MIT

Package Exports

  • vite-plugin-dts
  • vite-plugin-dts/package.json

Readme

vite-plugin-dts

(Do not recommend anymore, please use unplugin-dts instead)

version license

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:

{
  plugins: [dts({ bundleTypes: true })]
}

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

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

Example

A real project using this plugin: Vexip UI.

License

MIT License.