# rolldown-plugin-dts

> A Rolldown plugin to generate and bundle dts files.

Latest version **0.28.6** (published 2026-09-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install rolldown-plugin-dts
pnpm add rolldown-plugin-dts
yarn add rolldown-plugin-dts
bun add rolldown-plugin-dts
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.28.6 |
| Published | 2026-09-16 |
| First published | 2025-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Node | ^22.18.0 \|\| ^24.11.0 \|\| >=26.0.0 |
| Dependencies | 6 |
| Unpacked size | 107.3 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 248 |
| Author | Kevin Deng <sxzz@sxzz.moe> |
| Maintainers | sxzz |
| Keywords | rolldown, plugin, rolldown-plugin, vite-plugin, dts, typescript, vue, jsdoc, volar |

## Links

- npm: https://www.npmjs.com/package/rolldown-plugin-dts
- Repository: https://github.com/sxzz/rolldown-plugin-dts
- Homepage: https://github.com/sxzz/rolldown-plugin-dts#readme
- Issues: https://github.com/sxzz/rolldown-plugin-dts/issues
- Funding: https://github.com/sponsors/sxzz
- npm.io page: https://npm.io/package/rolldown-plugin-dts

## Dependencies (6)

- [obug](https://npm.io/package/obug.md) ^3.0.0
- [yuku-ast](https://npm.io/package/yuku-ast.md) ^0.10.1
- [yuku-parser](https://npm.io/package/yuku-parser.md) ^0.10.1
- [dts-resolver](https://npm.io/package/dts-resolver.md) ^3.0.0
- [get-tsconfig](https://npm.io/package/get-tsconfig.md) 5.0.0-beta.6
- [yuku-codegen](https://npm.io/package/yuku-codegen.md) ^0.10.1

## Alternatives

- [@openai/codex-sdk](https://npm.io/package/@openai/codex-sdk.md) — 731.4K weekly downloads
- [babel-plugin-transform-react-jsx](https://npm.io/package/babel-plugin-transform-react-jsx.md) — 565.0K weekly downloads
- [babel-helper-remove-or-void](https://npm.io/package/babel-helper-remove-or-void.md) — 508.5K weekly downloads
- [@pnpm/store-controller-types](https://npm.io/package/@pnpm/store-controller-types.md) — 186.9K weekly downloads
- [react-native-signature-canvas](https://npm.io/package/react-native-signature-canvas.md) — 155.6K weekly downloads

## Recent versions

- 0.28.6 (latest) — 2026-09-16
- 0.27.0-beta.1 (beta) — 2026-07-05
- 0.28.5 — 2026-09-03
- 0.28.4 — 2026-08-31
- 0.28.3 — 2026-08-28
- 0.28.2 — 2026-08-12
- 0.28.1 — 2026-08-10
- 0.28.0 — 2026-07-30
- 0.27.14 — 2026-07-24
- 0.27.13 — 2026-07-22
- 0.27.12 — 2026-07-19
- 0.27.11 — 2026-07-17
- 0.27.10 — 2026-07-16
- 0.27.9 — 2026-07-13
- 0.27.8 — 2026-07-13
- … 148 more at https://npm.io/package/rolldown-plugin-dts/versions

## README

# rolldown-plugin-dts

[![npm version][npm-version-src]][npm-version-href]
[![npm downloads][npm-downloads-src]][npm-downloads-href]
[![Unit Test][unit-test-src]][unit-test-href]

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

```bash
npm i -D rolldown-plugin-dts
```

Install the compiler required by your generator:

```bash
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

```ts
// 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](./rolldown.config.ts) for the project's own setup.

## Generators

| Generator | Use it for                                              | Requirement                                  |
| --------- | ------------------------------------------------------- | -------------------------------------------- |
| `tsc`     | Full TypeScript compatibility, Vue, and Volar languages | TypeScript 5.x or 6.x                        |
| `oxc`     | Fast generation for isolated declarations               | Code compatible with `isolatedDeclarations`  |
| `tsgo`    | Experimental TypeScript 7 builds                        | TypeScript 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.

```ts
dts({
  generator: 'oxc',
})
```

## Options

### General

| Option            | Description                                                                               | Default                 |
| ----------------- | ----------------------------------------------------------------------------------------- | ----------------------- |
| `generator`       | Declaration generator: `tsc`, `oxc`, or `tsgo`.                                           | Inferred                |
| `entry`           | Glob or globs selecting files to emit. Supports `!` negation and paths relative to `cwd`. | Rolldown entries        |
| `cwd`             | Base directory for config discovery, globs, and relative paths.                           | `process.cwd()`         |
| `dtsInput`        | Treat entry files as existing declarations.                                               | `false`                 |
| `emitDtsOnly`     | Remove non-declaration chunks from the output.                                            | `false`                 |
| `tsconfig`        | Config path; `true` discovers one and `false` disables loading.                           | Nearest `tsconfig.json` |
| `tsconfigRaw`     | Raw config values merged over the loaded config.                                          | `{}`                    |
| `compilerOptions` | Compiler options merged over the loaded config.                                           | `{}`                    |
| `sourcemap`       | Emit `.d.ts.map` files.                                                                   | `declarationMap`        |
| `resolver`        | Resolve declaration imports with `oxc` or `tsc`.                                          | `oxc`                   |
| `cjsDefault`      | Convert a single default export to `export =`.                                            | `false`                 |
| `sideEffects`     | Mark declaration modules as having side effects.                                          | `false`                 |
| `logger`          | Logger implementing `info`, `warn`, and `error`.                                          | `console`               |

`entry` may include files that are not Rolldown entry points:

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

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

### TypeScript (`tsc`)

| Option        | Description                                                   | Default                                  |
| ------------- | ------------------------------------------------------------- | ---------------------------------------- |
| `build`       | Use TypeScript build mode and follow project references.      | `false`                                  |
| `incremental` | Persist build outputs, including `.tsbuildinfo`, to disk.     | Enabled by the matching tsconfig options |
| `vue`         | Register the built-in Vue integration using `vue-tsc`.        | `false`                                  |
| `parallel`    | Run `tsc` or `vue-tsc` in a separate process.                 | `false`                                  |
| `eager`       | Load every file listed by `tsconfig.json`.                    | `false`                                  |
| `newContext`  | Use an isolated compiler cache instead of the shared context. | `false`                                  |
| `emitJs`      | Generate 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:

```ts
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`](https://oxc.rs/docs/guide/usage/transformer.html).
Use the top-level `sourcemap` option for declaration maps.

```ts
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.

```ts
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:

```ts
// 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`:

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

## Limitations

Declaration bundling requires an ESM Rolldown output. The `cjs` output format is
not supported. For CommonJS packages, build the JavaScript output separately
and use `emitDtsOnly` for a second declaration-only build.

The following declaration input cannot be bundled:

- CommonJS export assignments such as `export = value`.
- CommonJS import aliases such as `import value = require('package')`.
- Script-style ambient declarations, such as `declare module 'package' { ... }`
  or unexported top-level `declare` statements. Bundled declaration chunks are
  always modules, which would change the meaning of these declarations.

Mark dependencies that use unsupported declaration syntax as external.

## Credits

Inspired by
[rollup-plugin-dts](https://github.com/Swatinem/rollup-plugin-dts), with an
independent implementation. Its MIT-licensed test suite is used with
permission.

## Sponsors

<p align="center">
  <a href="https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg">
    <img src='https://cdn.jsdelivr.net/gh/sxzz/sponsors/sponsors.svg'/>
  </a>
</p>

## License

[MIT](./LICENSE) License © 2025-PRESENT [Kevin Deng](https://github.com/sxzz)

<!-- Badges -->

[npm-version-src]: https://img.shields.io/npm/v/rolldown-plugin-dts.svg
[npm-version-href]: https://npmjs.com/package/rolldown-plugin-dts
[npm-downloads-src]: https://img.shields.io/npm/dm/rolldown-plugin-dts
[npm-downloads-href]: https://www.npmcharts.com/compare/rolldown-plugin-dts?interval=30
[unit-test-src]: https://github.com/sxzz/rolldown-plugin-dts/actions/workflows/unit-test.yml/badge.svg
[unit-test-href]: https://github.com/sxzz/rolldown-plugin-dts/actions/workflows/unit-test.yml

---
_Source: https://npm.io/package/rolldown-plugin-dts · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
