sxzz/rolldown-plugin-dts

A Rolldown plugin to generate and bundle dts files.

249

stars

720

commits

TypeScript

primary language

Sep 7, 2026

updated

README

rolldown-plugin-dts

npm version npm downloads Unit Test

A Rolldown plugin that generates and bundles TypeScript declaration files.

Install

Requires Rolldown 1.2.0 or later and Node.js ^22.18.0 || ^24.11.0 || >=26.0.0.

npm i -D rolldown-plugin-dts

Install the compiler required by your generator:

npm i -D typescript@^6              # tsc
npm i -D @typescript/native-preview # tsgo, unless TypeScript 7 is installed

Oxc is provided by Rolldown and needs no additional dependency.

Usage

// rolldown.config.ts
import { defineConfig } from 'rolldown'
import { dts } from 'rolldown-plugin-dts'

export default defineConfig({
  input: 'src/index.ts',
  plugins: [dts()],
  output: {
    dir: 'dist',
    format: 'es',
  },
})

See rolldown.config.ts for the project's own setup.

Generators

GeneratorUse it forRequirement
tscFull TypeScript compatibility, Vue, and Volar languagesTypeScript 5.x or 6.x
oxcFast generation for isolated declarationsCode compatible with isolatedDeclarations
tsgoExperimental TypeScript 7 buildsTypeScript 7 or @typescript/native-preview

When generator is omitted, the plugin selects:

  1. oxc when compilerOptions.isolatedDeclarations is enabled.
  2. tsgo when TypeScript 7 is installed as typescript.
  3. tsc otherwise.

Volar-based custom languages always require tsc. The tsgo generator does not support custom languages.

dts({
  generator: 'oxc',
})

Options

General

OptionDescriptionDefault
generatorDeclaration generator: tsc, oxc, or tsgo.Inferred
entryGlob or globs selecting files to emit. Supports ! negation and paths relative to cwd.Rolldown entries
cwdBase directory for config discovery, globs, and relative paths.process.cwd()
dtsInputTreat entry files as existing declarations.false
emitDtsOnlyRemove non-declaration chunks from the output.false
tsconfigConfig path; true discovers one and false disables loading.Nearest tsconfig.json
tsconfigRawRaw config values merged over the loaded config.{}
compilerOptionsCompiler options merged over the loaded config.{}
sourcemapEmit .d.ts.map files.declarationMap
resolverResolve declaration imports with oxc or tsc.oxc
cjsDefaultConvert a single default export to export =.false
sideEffectsMark declaration modules as having side effects.false
loggerLogger implementing info, warn, and error.console

entry may include files that are not Rolldown entry points:

dts({
  entry: ['src/**/*.ts', '!src/icons/**'],
})

cjsDefault only changes the emitted export syntax. It does not enable CommonJS-style declaration input.

TypeScript (tsc)

OptionDescriptionDefault
buildUse TypeScript build mode and follow project references.false
incrementalPersist build outputs, including .tsbuildinfo, to disk.Enabled by the matching tsconfig options
vueRegister the built-in Vue integration using vue-tsc.false
parallelRun tsc or vue-tsc in a separate process.false
eagerLoad every file listed by tsconfig.json.false
newContextUse an isolated compiler cache instead of the shared context.false
emitJsGenerate declarations for JavaScript files with JSDoc types.allowJs or checkJs

incremental applies to build mode. When disabled, build outputs stay in memory.

To invalidate a file in the shared compiler cache:

import {
  globalContext,
  invalidateContextFile,
} from 'rolldown-plugin-dts/tsc-context'

invalidateContextFile(globalContext, 'src/foo.ts')

Custom languages

customLanguages registers non-standard source files such as Vue or Astro. Volar integrations must provide both volarTypeScript and createVolarPlugins; they require the tsc generator. vue: true is the preconfigured Vue shortcut.

This API is experimental and may change.

Oxc

oxc accepts IsolatedDeclarationsOptions. Use the top-level sourcemap option for declaration maps.

dts({
  generator: 'oxc',
  oxc: {
    stripInternal: true,
  },
})

TypeScript Go

tsgo is experimental and requires a tsconfig.json. It reads compiler options from that file, so tsconfigRaw and compilerOptions are ignored.

dts({
  generator: 'tsgo',
  tsgo: {
    path: '/path/to/tsgo',
  },
})

Vite

Exclude generated declarations from Oxc transformation. Because oxc.exclude replaces Vite's default exclusions, keep JavaScript files excluded as well:

// vite.config.ts
import { defineConfig } from 'vite'

export default defineConfig({
  oxc: {
    exclude: [/\.js$/, /\.d\.[cm]?ts$/],
  },
})

Code splitting

Declaration chunk names must end in .d:

export default {
  codeSplitting: {
    groups: [
      { test: /foo.*\.d\.[cm]?ts$/, name: 'shared.d' },
      { test: /foo/, name: 'shared' },
    ],
  },
}

CommonJS

Declaration bundling requires an ESM Rolldown output. For CommonJS packages, build the JavaScript output separately and use emitDtsOnly for a second declaration-only build.

The plugin expects ESM-style declaration input. Syntax such as export = or import x = require('x') may not bundle correctly. If it comes from a dependency, mark that dependency as external.

Credits

Inspired by rollup-plugin-dts, with an independent implementation. Its MIT-licensed test suite is used with permission.

Sponsors

License

MIT License © 2025-PRESENT Kevin Deng

Contributors

sxzz

607 commits

renovate[bot]

54 commits

ocavue

21 commits

shulaoda

6 commits

sxzz/rolldown-plugin-dts

A Rolldown plugin to generate and bundle dts files.

249

stars

720

commits

TypeScript

primary language

Sep 7, 2026

updated

README

rolldown-plugin-dts

npm version npm downloads Unit Test

A Rolldown plugin that generates and bundles TypeScript declaration files.

Install

Requires Rolldown 1.2.0 or later and Node.js ^22.18.0 || ^24.11.0 || >=26.0.0.

npm i -D rolldown-plugin-dts

Install the compiler required by your generator:

npm i -D typescript@^6              # tsc
npm i -D @typescript/native-preview # tsgo, unless TypeScript 7 is installed

Oxc is provided by Rolldown and needs no additional dependency.

Usage

// rolldown.config.ts
import { defineConfig } from 'rolldown'
import { dts } from 'rolldown-plugin-dts'

export default defineConfig({
  input: 'src/index.ts',
  plugins: [dts()],
  output: {
    dir: 'dist',
    format: 'es',
  },
})

See rolldown.config.ts for the project's own setup.

Generators

GeneratorUse it forRequirement
tscFull TypeScript compatibility, Vue, and Volar languagesTypeScript 5.x or 6.x
oxcFast generation for isolated declarationsCode compatible with isolatedDeclarations
tsgoExperimental TypeScript 7 buildsTypeScript 7 or @typescript/native-preview

When generator is omitted, the plugin selects:

  1. oxc when compilerOptions.isolatedDeclarations is enabled.
  2. tsgo when TypeScript 7 is installed as typescript.
  3. tsc otherwise.

Volar-based custom languages always require tsc. The tsgo generator does not support custom languages.

dts({
  generator: 'oxc',
})

Options

General

OptionDescriptionDefault
generatorDeclaration generator: tsc, oxc, or tsgo.Inferred
entryGlob or globs selecting files to emit. Supports ! negation and paths relative to cwd.Rolldown entries
cwdBase directory for config discovery, globs, and relative paths.process.cwd()
dtsInputTreat entry files as existing declarations.false
emitDtsOnlyRemove non-declaration chunks from the output.false
tsconfigConfig path; true discovers one and false disables loading.Nearest tsconfig.json
tsconfigRawRaw config values merged over the loaded config.{}
compilerOptionsCompiler options merged over the loaded config.{}
sourcemapEmit .d.ts.map files.declarationMap
resolverResolve declaration imports with oxc or tsc.oxc
cjsDefaultConvert a single default export to export =.false
sideEffectsMark declaration modules as having side effects.false
loggerLogger implementing info, warn, and error.console

entry may include files that are not Rolldown entry points:

dts({
  entry: ['src/**/*.ts', '!src/icons/**'],
})

cjsDefault only changes the emitted export syntax. It does not enable CommonJS-style declaration input.

TypeScript (tsc)

OptionDescriptionDefault
buildUse TypeScript build mode and follow project references.false
incrementalPersist build outputs, including .tsbuildinfo, to disk.Enabled by the matching tsconfig options
vueRegister the built-in Vue integration using vue-tsc.false
parallelRun tsc or vue-tsc in a separate process.false
eagerLoad every file listed by tsconfig.json.false
newContextUse an isolated compiler cache instead of the shared context.false
emitJsGenerate declarations for JavaScript files with JSDoc types.allowJs or checkJs

incremental applies to build mode. When disabled, build outputs stay in memory.

To invalidate a file in the shared compiler cache:

import {
  globalContext,
  invalidateContextFile,
} from 'rolldown-plugin-dts/tsc-context'

invalidateContextFile(globalContext, 'src/foo.ts')

Custom languages

customLanguages registers non-standard source files such as Vue or Astro. Volar integrations must provide both volarTypeScript and createVolarPlugins; they require the tsc generator. vue: true is the preconfigured Vue shortcut.

This API is experimental and may change.

Oxc

oxc accepts IsolatedDeclarationsOptions. Use the top-level sourcemap option for declaration maps.

dts({
  generator: 'oxc',
  oxc: {
    stripInternal: true,
  },
})

TypeScript Go

tsgo is experimental and requires a tsconfig.json. It reads compiler options from that file, so tsconfigRaw and compilerOptions are ignored.

dts({
  generator: 'tsgo',
  tsgo: {
    path: '/path/to/tsgo',
  },
})

Vite

Exclude generated declarations from Oxc transformation. Because oxc.exclude replaces Vite's default exclusions, keep JavaScript files excluded as well:

// vite.config.ts
import { defineConfig } from 'vite'

export default defineConfig({
  oxc: {
    exclude: [/\.js$/, /\.d\.[cm]?ts$/],
  },
})

Code splitting

Declaration chunk names must end in .d:

export default {
  codeSplitting: {
    groups: [
      { test: /foo.*\.d\.[cm]?ts$/, name: 'shared.d' },
      { test: /foo/, name: 'shared' },
    ],
  },
}

CommonJS

Declaration bundling requires an ESM Rolldown output. For CommonJS packages, build the JavaScript output separately and use emitDtsOnly for a second declaration-only build.

The plugin expects ESM-style declaration input. Syntax such as export = or import x = require('x') may not bundle correctly. If it comes from a dependency, mark that dependency as external.

Credits

Inspired by rollup-plugin-dts, with an independent implementation. Its MIT-licensed test suite is used with permission.

Sponsors

License

MIT License © 2025-PRESENT Kevin Deng

Contributors

sxzz

607 commits

renovate[bot]

54 commits

ocavue

21 commits

shulaoda

6 commits

Languages

TypeScript

99.2%