DTS Webpack Bundler

raw JSON →
1.0.3 verified Thu Apr 23 auth: no javascript abandoned

This Webpack plugin is designed to generate TypeScript declaration (`.d.ts`) files for each entry point (chunk) within a Webpack build process. It leverages the `dts-bundle` library to consolidate individual TypeScript declaration files into bundled outputs. The package, currently at version 1.0.3, was last updated in October 2017 and explicitly supports only Webpack v3.x. Given the subsequent major releases of Webpack (v4, v5, etc.), this plugin is not compatible with modern Webpack environments. Its release cadence is non-existent, as it has been unmaintained for over six years. Key differentiators at the time of its release included chunk-specific `.d.ts` bundling, a feature now handled by more contemporary and actively maintained plugins that support current Webpack versions. Users seeking to bundle TypeScript declarations in modern Webpack projects should consider alternative solutions.

error TypeError: DtsWebpackBundler is not a constructor
cause Attempting to use `import` syntax (ESM) with a CommonJS-only package, or incorrect capitalization.
fix
Use const DtsWebpackBundler = require('dts-webpack-bundler'); for CommonJS environments.
error Error: Typings directory not found or no .d.ts files found for bundling.
cause The `typingsDir` option in the plugin configuration does not correctly point to the directory specified in `tsconfig.json`'s `declarationDir`, or the TypeScript compiler did not generate any .d.ts files.
fix
Verify that tsconfig.json has "declaration": true and "declarationDir": "./path/to/typings", and that typingsDir in DtsWebpackBundler options matches this path exactly. Also, ensure TypeScript is correctly compiling your source files.
breaking This plugin explicitly supports only Webpack v3.x. It will not function correctly with Webpack v4, v5, or later versions due to significant API changes in Webpack.
fix Migrate to a modern d.ts bundling solution for Webpack, such as `npm-dts-webpack-plugin`, `bundle-declarations-webpack-plugin`, or `types-webpack-bundler` (a Webpack 5 compatible fork).
gotcha The plugin requires `declaration` to be `true` and `declarationDir` to be properly configured in `tsconfig.json`. All generated declaration files must be gathered into this single directory for the plugin to process them correctly.
fix Ensure your `tsconfig.json` includes `"declaration": true` and `"declarationDir": "./some-typings-folder/"`. The `typingsDir` option in the plugin configuration must point to this exact folder.
breaking The package is no longer maintained, with the last publish over six years ago. This means there will be no updates for new Webpack versions, TypeScript features, or bug fixes.
fix It is highly recommended to use an actively maintained alternative for d.ts bundling in Webpack projects.
npm install dts-webpack-bundler
yarn add dts-webpack-bundler
pnpm add dts-webpack-bundler

Demonstrates how to configure `dts-webpack-bundler` in a `webpack.config.js` file, including necessary `tsconfig.json` settings.

const path = require('path');
const DtsWebpackBundler = require('dts-webpack-bundler');

// tsconfig.json excerpt (required for this plugin):
// {
//     "compilerOptions": {
//         "declaration": true,
//         "declarationDir": "./typings/"
//     }
// }

module.exports = {
    entry: './src/main.ts',
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: 'index.js'
    },
    plugins: [
        new DtsWebpackBundler({
			libName: 'my-library',
			typingsDir: path.resolve(process.cwd(), 'typings'),
			outputDir: path.resolve(process.cwd(), 'build'),
			deleteSource: true // Deletes the typings folder after bundling.
        })
    ]
};