Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

unplugin/unplugin-isolated-decl

Open more actions menu

Repository files navigation

unplugin-isolated-decl

npm version npm downloads JSR Unit Test

⚡️ A blazing-fast tool for generating isolated declarations.

Features

  • 🚀 Fast: Generates .d.ts files significantly faster than tsc.
  • 🎨 Transformer: Support Oxc, SWC, and TypeScript transformer.
  • 📦 Zero Config: No configuration required, works out of the box.
  • Bundler Support: Works with Vite, Rollup, esbuild and Farm.

Tip

For Rolldown users, you can use the rolldown-plugin-dts for a more powerful and flexible solution.

Installation

# npm
npm i -D unplugin-isolated-decl

# jsr
npx jsr add -D @unplugin/isolated-decl

Usage

Vite
// vite.config.ts
import UnpluginIsolatedDecl from 'unplugin-isolated-decl/vite'

export default defineConfig({
  plugins: [UnpluginIsolatedDecl()],
})


Rollup
// rollup.config.js
import UnpluginIsolatedDecl from 'unplugin-isolated-decl/rollup'

export default {
  plugins: [UnpluginIsolatedDecl()],
}


Rolldown
// rolldown.config.js
import UnpluginIsolatedDecl from 'unplugin-isolated-decl/rolldown'

export default {
  plugins: [UnpluginIsolatedDecl()],
}


esbuild
// esbuild.config.js
import { build } from 'esbuild'

build({
  plugins: [require('unplugin-isolated-decl/esbuild')()],
})


Farm
// farm.config.ts
import UnpluginIsolatedDecl from 'unplugin-isolated-decl/farm'

export default defineConfig({
  plugins: [UnpluginIsolatedDecl()],
})


Options

export interface Options {
  include?: FilterPattern
  exclude?: FilterPattern
  enforce?: 'pre' | 'post' | undefined
  /**
   * You should install the transformer manually if you are not using oxc.
   * swc: @swc/core
   * typescript: typescript
   *
   * @default oxc
   */
  transformer?: 'oxc' | 'swc' | 'typescript'
  /**
   * Whether to generate declaration source maps.
   *
   * Supported by `typescript` and `oxc` transformer only.
   *
   * @link https://www.typescriptlang.org/tsconfig/#declarationMap
   */
  sourceMap?: boolean

  transformOptions?: TranspileOptions
  ignoreErrors?: boolean
  /** An extra directory layer for output files. */
  extraOutdir?: string

  rewriteImports?: (
    id: string,
    importer: string,
  ) => string | void | null | undefined
}

rewriteImports

Rewrite imports in .d.ts files. (esbuild support is not available)

Here is an example of rewriting imports on Rollup:

// rollup.config.js
import alias from '@rollup/plugin-alias'

export default {
  // ...
  plugins: [
    alias({ entries: [{ find: '~', replacement: '.' }] }),
    UnpluginIsolatedDecl({
      rewriteImports(id, importer) {
        if (id[0] === '~') return `.${id.slice(1)}`
      },
    }),
    // ...
  ],
}

patchCjsDefaultExport

Patch export default in .d.cts to export =


Note

For the exhaustive set of options check options

Sponsors

License

MIT License © 2024-PRESENT Kevin Deng

About

⚡️ A blazing-fast tool for generating isolated declarations.

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.