The `typescript-declaration-webpack-plugin` is a Webpack plugin designed to consolidate all TypeScript declaration files (`.d.ts`) generated by the TypeScript compiler and its loaders during a Webpack build into a single, unified `.d.ts` file. This functionality is particularly beneficial for library authors who distribute their compiled JavaScript alongside their type definitions, providing a single, coherent type entry point for consumers. The plugin intelligently sorts and deduplicates module imports within the bundled declaration file. The current stable version is `0.3.0`, which introduced named exports for the plugin class and configuration, alongside enhanced declaration emission. While the project doesn't follow a strict release cadence, it shows active development with recent patches addressing critical issues and adding new features like comment removal from declarations.
npm install typescript-declaration-webpack-pluginVerified import paths — ran on the pinned version, not inferred.
This Webpack configuration demonstrates how to set up `typescript-declaration-webpack-plugin` to bundle a TypeScript library, using `ts-loader` for compilation and emitting a single `index.d.ts` file alongside the bundled JavaScript output.
Add `"declaration": true` to your `compilerOptions` in `tsconfig.json`.
Review your Webpack configuration and `tsconfig.json` after upgrading to these versions, and test your build output thoroughly. Consult the project's GitHub issues for more context if problems arise.
For ESM projects, use `import { TypescriptDeclarationPlugin } from 'typescript-declaration-webpack-plugin';` in your `webpack.config.js` (if it supports ESM). For CommonJS, stick to `const TypescriptDeclarationPlugin = require('typescript-declaration-webpack-plugin');`.Ensure your Webpack setup includes a TypeScript loader configured to emit declaration files, and that your `tsconfig.json` specifies `"declaration": true`.
Run `npm install --save-dev typescript-declaration-webpack-plugin` or `yarn add --dev typescript-declaration-webpack-plugin`.
Verify `"declaration": true` is present in `compilerOptions` of your `tsconfig.json`. Also, ensure `ts-loader` or similar is correctly configured in your Webpack rules to process TypeScript files and produce declarations.
Check your `tsconfig.json` for `"declaration": true`. Ensure your `ts-loader` setup is generating `.d.ts` files in your build output before the plugin attempts to process them. You might temporarily disable `removeMergedDeclarations: true` to inspect intermediate `.d.ts` files.