MCPcopy Index your code
hub / github.com/Swatinem/rollup-plugin-dts

github.com/Swatinem/rollup-plugin-dts @v6.4.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release v6.4.1 ↗ · + Follow
886 symbols 1,209 edges 531 files 8 documented · 1% 97 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

rollup-plugin-dts

Build Status Coverage Status

This is a plugin that lets you roll-up your .d.ts definition files.

Usage

Install the package from npm:

$ npm install --save-dev rollup-plugin-dts

Add it to your rollup.config.js:

import { dts } from "rollup-plugin-dts";

const config = [
  // …
  {
    input: "./my-input/index.d.ts",
    output: [{ file: "dist/my-library.d.ts", format: "es" }],
    plugins: [dts()],
  },
];

export default config;

NOTE A default import of the plugin using import dts from "rollup-plugin-dts"; is still supported for existing implementations of this package. However, a named import is suggested to avoid the error [!] TypeError: dts is not a function[^1][^2] in certain rollup config file implementations.

And then instruct typescript where to find your definitions inside your package.json:

  "types": "dist/my-library.d.ts",

NOTE that the plugin will automatically mark any external library (@types for example) as external, so those will be excluded from bundling.

Options

plugins: [dts({
  // Enable detailed sourcemaps for Go-to-Definition support.
  // When true: loads .d.ts.map files and captures TypeScript's declarationMap
  // for .ts inputs, enabling navigation to original source files.
  // NOTE: Also requires `output.sourcemap: true` in your Rollup config.
  sourcemap: true,

  // Path to tsconfig.json (default: finds nearest tsconfig.json)
  tsconfig: "./tsconfig.json",

  // TypeScript compiler options (e.g., for path mapping)
  compilerOptions: { baseUrl: ".", paths: { "~/*": ["src/*"] } },

  // Don't auto-externalize node_modules (default: false)
  respectExternal: true,

  // Bundle types from specific external packages (default: [])
  includeExternal: ["some-package"],
})]

Maintenance Mode

This project is in maintenance mode. That means there will be no more active feature development. There will still be occasional releases to maintain compatibility with future TypeScript releases. Pull Requests are always welcome, however reaction time on both Issues and PRs can be slow.

What to expect

While this plugin is fairly complete, it does not support all imaginable use-cases. In particular, the plugin works best with already existing .d.ts files generated by the typescript compiler from idiomatic code.

Working with .ts(x) or even .js(x) (when setting allowJs: true) does work, but is not recommended.

The plugin does its own import resolution through the typescript compiler, and usage together with other resolution plugins, such as node-resolve can lead to errors and is not recommended.

All external dependencies from node_modules are automatically excluded from bundling. This can be overridden using the respectExternal setting, but it is generally not recommended. While rollup of external @types generally works, it is not recommended.

Why?

Well, ideally TypeScript should just do all this itself, and it even has a proposal to do that. But there hasn’t been any progress in ~3 years.

Some projects, like rollup itself go the route of completely separating their public interfaces in a separate file.

Alternatives

See some discussions about some of these projects and their tradeoffs.

How does it work

License

The code is licensed under the copyleft LGPL-3.0. I have no intention to license this under any non-copyleft license.

[^1]: StackOverflow thread of issue [^2]: Github issue

Extension points exported contracts — how you extend this code

Export (Interface)
* The reason we need this here as a post-processing step is that rollup will * generate special objects for things like
src/transform/NamespaceFixer.ts
Iface (Interface)
(no doc) [1 implementers]
tests/testcases/using-namespace-import-multiple/expected.d.ts
DtsPluginContext (Interface)
(no doc)
src/index.ts
Options (Interface)
(no doc)
src/options.ts
Meta (Interface)
(no doc)
tests/testcases.ts
Direct (Interface)
(no doc)
tests/preprocess/inline-imports/expected.d.ts
DeclarationScopeOptions (Interface)
(no doc)
src/transform/DeclarationScope.ts
Bar (Interface)
(no doc)
tests/testcases/keep-extended-interface/expected.d.ts

Core symbols most depended-on inside this repo

withStartEnd
called by 21
src/transform/astHelpers.ts
createIdentifier
called by 20
src/transform/astHelpers.ts
bundleWithSourcemap
called by 18
tests/sourcemap.ts
convertTypeNode
called by 10
src/transform/DeclarationScope.ts
pushTypeVariable
called by 9
src/transform/DeclarationScope.ts
pushReference
called by 9
src/transform/DeclarationScope.ts
pushStatement
called by 9
src/transform/Transformer.ts
popScope
called by 8
src/transform/DeclarationScope.ts

Shape

Interface 490
Class 226
Function 88
Method 58
Enum 24

Languages

TypeScript100%

Modules by API surface

tests/testcases/renaming/expected.d.ts22 symbols
src/transform/Transformer.ts22 symbols
tests/testcases/generics/index.d.ts19 symbols
tests/testcases/generics/expected.d.ts19 symbols
src/transform/DeclarationScope.ts19 symbols
tests/testcases/shadowing/exports.d.ts18 symbols
src/transform/preprocess.ts18 symbols
tests/testcases/type-nodes/index.d.ts16 symbols
tests/testcases/type-nodes/expected.d.ts16 symbols
src/transform/TypeOnlyFixer.ts14 symbols
src/transform/index.ts12 symbols
tests/testcases/renaming/b.d.ts11 symbols

For agents

$ claude mcp add rollup-plugin-dts \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact