dts-bundle-webpack

raw JSON →
1.0.2 verified Sat Apr 25 auth: no javascript deprecated

A webpack plugin that wraps the dts-bundle library to generate a single bundled .d.ts declaration file from TypeScript compiler output. Version 1.0.2, last updated in 2017. It merges all generated declaration files into one, supporting options like externals, exclude, removeSource, and verbose. However, the underlying dts-bundle is unmaintained, and the plugin relies on CommonJS require(). No longer recommended for modern webpack 5+ TypeScript projects.

error TypeError: DtsBundleWebpack is not a constructor
cause Using ES6 import without default interop or incorrect require() path.
fix
Use const DtsBundleWebpack = require('dts-bundle-webpack');
error Error: Cannot find module 'dts-bundle'
cause Missing peer dependency dts-bundle.
fix
Run npm install dts-bundle --save-dev
deprecated dts-bundle is unmaintained since 2017; alternative tools like api-extractor or tsc --declaration are recommended.
fix Use @microsoft/api-extractor or tsc's built-in declaration output.
gotcha Plugin only works with webpack 4 and earlier; not compatible with webpack 5 without modifications.
fix Check compatibility or migrate to webpack 4 or use an alternative.
gotcha Options must match dts-bundle's schema exactly; no validation is performed by the plugin.
fix Refer to dts-bundle documentation for valid options.
npm install dts-bundle-webpack
yarn add dts-bundle-webpack
pnpm add dts-bundle-webpack

Configures webpack with ts-loader and dts-bundle-webpack plugin to generate a single .d.ts bundle from index.d.ts output.

const path = require('path');
const DtsBundleWebpack = require('dts-bundle-webpack');

module.exports = {
  entry: './src/index.ts',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'bundle.js',
  },
  resolve: {
    extensions: ['.ts', '.js'],
  },
  module: {
    rules: [
      { test: /\.ts$/, loader: 'ts-loader' },
    ],
  },
  plugins: [
    new DtsBundleWebpack({
      name: 'myLib',
      main: 'build/index.d.ts',
      out: 'dist/myLib.d.ts',
      removeSource: false,
      outputAsModuleFolder: true,
    }),
  ],
};