Skip to content

A rollup plugin to generate .d.ts rollup files for your typescript project

License

Notifications You must be signed in to change notification settings

btea/rollup-plugin-dts

This branch is 100 commits behind Swatinem/rollup-plugin-dts:master.

Folders and files

NameName
Last commit message
Last commit date
Aug 25, 2023
May 23, 2021
Jan 31, 2023
Aug 4, 2023
Aug 4, 2023
Nov 22, 2020
Nov 15, 2018
Oct 3, 2019
Dec 1, 2022
Jan 6, 2021
Aug 17, 2023
Sep 5, 2022
Sep 5, 2022
Jul 31, 2023
Aug 28, 2023
Aug 28, 2023
Mar 22, 2021
Jul 4, 2023
Jul 4, 2023

Repository files navigation

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

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.

License

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

Footnotes

  1. StackOverflow thread of issue

  2. Github issue

About

A rollup plugin to generate .d.ts rollup files for your typescript project

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 95.2%
  • JavaScript 4.8%