DTS Webpack Bundler
raw JSON →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.
Common errors
error TypeError: DtsWebpackBundler is not a constructor ↓
const DtsWebpackBundler = require('dts-webpack-bundler'); for CommonJS environments. error Error: Typings directory not found or no .d.ts files found for bundling. ↓
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. Warnings
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. ↓
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. ↓
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. ↓
Install
npm install dts-webpack-bundler yarn add dts-webpack-bundler pnpm add dts-webpack-bundler Imports
- DtsWebpackBundler wrong
import DtsWebpackBundler from 'dts-webpack-bundler';correctconst DtsWebpackBundler = require('dts-webpack-bundler');
Quickstart
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.
})
]
};