rollup-plugin-dts
An experiment to generate .d.ts rollup files
Last updated 7 years ago by swatinem .
LGPL-3.0 · Repository · Bugs · Original npm · Tarball · package.json
$ npm install rollup-plugin-dts 
SYNC missed versions from official npm registry.

rollup-plugin-dts

Build Status Coverage Status

This is an EXPERIMENT to generate roll-upd .d.ts definition files from your .ts files.

It is complete enough to generate its own definition file, and it is used successfully for intl-codegen as well.

Usage

Install the package from npm:

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

Create your rollup.config.js:

import resolve from "rollup-plugin-node-resolve";
// NOTE: The plugin has two different modes:
// * one to transpile `.ts -> .js`
// * one to create `.ts -> .d.ts` bundles
import { ts, dts } from "rollup-plugin-dts";

const config = [
  {
    input: "./src/index.ts",
    // NOTE: The first output is your transpiled typescript
    output: [{ file: "dist/my-library.js", format: "cjs" }, { file: "dist/my-library.mjs", format: "es" }],

    plugins: [
      resolve({
        jsnext: true,
        extensions: [".ts"],
      }),
      ts(),
    ],
  },
  {
    input: "./src/index.ts",
    // NOTE: The second output is your bundled `.d.ts` file
    output: [{ file: "dist/my-library.d.ts", format: "es" }],

    plugins: [dts()],
  },
];

export default config;

And then instruct node or other bundles where to find your code

  "main": "dist/my-library.js",
  "module": "dist/my-library.mjs",
  "types": "dist/my-library.d.ts",

Limitations / Known Bugs

Exporting namespaces currently does not work and will create invalid .d.ts files.

import * as ns from "./namespace";

export { ns };

Using import * as itself is not a problem and works fine on its own. It is the re-export that breaks.


Using inline imports either as namespace or with external modules.

interface Foo {
  namespace: import("./namespace");
  external: import("external").Foo;
}

Using specific items from a local inline import, such as import("./local").Item, works fine however.

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 all three of these projects and their tradeoffs.

Surprisingly, all three projects struggle with similar edge-cases around namespaces and inline imports, as documented above.

How does it work

Current Tags

  • 6.5.1                                ...           latest (4 months ago)
  • 1.0.0-alpha.0                                ...           next (7 years ago)

82 Versions

  • 6.5.1                                ...           4 months ago
  • 6.5.0                                ...           4 months ago
  • 6.4.1                                ...           8 months ago
  • 6.4.0                                ...           9 months ago
  • 6.3.0                                ...           a year ago
  • 6.2.3                                ...           a year ago
  • 6.2.1                                ...           2 years ago
  • 6.2.0                                ...           2 years ago
  • 6.1.1                                ...           3 years ago
  • 6.1.0                                ...           3 years ago
  • 6.0.2                                ...           3 years ago
  • 6.0.1                                ...           3 years ago
  • 6.0.0                                ...           3 years ago
  • 5.3.1                                ...           3 years ago
  • 5.3.0                                ...           4 years ago
  • 5.2.0                                ...           4 years ago
  • 5.1.1                                ...           4 years ago
  • 5.1.0                                ...           4 years ago
  • 5.0.0                                ...           4 years ago
  • 4.2.3                                ...           4 years ago
  • 4.2.2                                ...           5 years ago
  • 4.2.1                                ...           5 years ago
  • 4.2.0                                ...           5 years ago
  • 4.1.0                                ...           5 years ago
  • 4.0.1                                ...           5 years ago
  • 4.0.0                                ...           5 years ago
  • 3.0.2                                ...           6 years ago
  • 3.0.1                                ...           6 years ago
  • 3.0.0                                ...           6 years ago
  • 2.0.1                                ...           6 years ago
  • 2.0.0                                ...           6 years ago
  • 1.4.14                                ...           6 years ago
  • 1.4.13                                ...           6 years ago
  • 1.4.12                                ...           6 years ago
  • 1.4.11                                ...           6 years ago
  • 1.4.10                                ...           6 years ago
  • 1.4.9                                ...           6 years ago
  • 1.4.8                                ...           6 years ago
  • 1.4.7                                ...           7 years ago
  • 1.4.6                                ...           7 years ago
  • 1.4.5                                ...           7 years ago
  • 1.4.4                                ...           7 years ago
  • 1.4.3                                ...           7 years ago
  • 1.4.2                                ...           7 years ago
  • 1.4.1                                ...           7 years ago
  • 1.4.0                                ...           7 years ago
  • 1.3.0                                ...           7 years ago
  • 1.2.1                                ...           7 years ago
  • 1.2.0                                ...           7 years ago
  • 1.1.13                                ...           7 years ago
  • 1.1.12                                ...           7 years ago
  • 1.1.11                                ...           7 years ago
  • 1.1.10                                ...           7 years ago
  • 1.1.9                                ...           7 years ago
  • 1.1.8                                ...           7 years ago
  • 1.1.7                                ...           7 years ago
  • 1.1.6                                ...           7 years ago
  • 1.1.5                                ...           7 years ago
  • 1.1.4                                ...           7 years ago
  • 1.1.3                                ...           7 years ago
  • 1.1.2                                ...           7 years ago
  • 1.1.1                                ...           7 years ago
  • 1.1.0                                ...           7 years ago
  • 1.0.0                                ...           7 years ago
  • 1.0.0-alpha.0                                ...           7 years ago
  • 0.15.1                                ...           8 years ago
  • 0.15.0                                ...           8 years ago
  • 0.14.0                                ...           8 years ago
  • 0.13.0                                ...           8 years ago
  • 0.12.0                                ...           8 years ago
  • 0.11.0                                ...           8 years ago
  • 0.10.0                                ...           8 years ago
  • 0.9.0                                ...           8 years ago
  • 0.8.0                                ...           8 years ago
  • 0.7.0                                ...           8 years ago
  • 0.6.0                                ...           8 years ago
  • 0.5.0                                ...           8 years ago
  • 0.4.0                                ...           8 years ago
  • 0.3.0                                ...           8 years ago
  • 0.2.0                                ...           8 years ago
  • 0.1.1                                ...           8 years ago
  • 0.1.0                                ...           8 years ago
Maintainers (1)
Downloads
Total 340
Today 0
This Week 0
This Month 104
Last Day 0
Last Week 51
Last Month 162
Dependencies (1)
Dev Dependencies (13)

© 2010 - cnpmjs.org x YWFE | Home | YWFE