I wrote a plugin for webpack which handles the problem.
First, install my package.
npm i -D @ahrakio/witty-webpack-declaration-files
Then, make sure your tsconfig has the declaration property set to true.
{ ...
declaration: true,
...
}
Finally, in your webpack config require the package and set it up under the plugins array.
const DeclarationFilesPlugin = require("@ahrakio/witty-webpack-declaration-files");
...
module.exports = {
...
plugins: [
...
new DeclarationFilesPlugin({
// options goes here
})
]
}
The options are -
merge: boolean (default: false) - Would you like to merge the declaration files to one file.
include: string[] (default: []) - Name of the files which you would like to be included in the final bundle (Without filename extensions, for MyClass.ts you should mension "MyClass").
exclude: string[] (default: []) - Name of the files which you would like to be excluded from the final bundle.
flatten: boolean (default: false) - If you would like to put all the declaration files in the root path of your dist folder.
Ofcourse, if you leave merge as false, the plugin will generate only the files in the include array, or all the files which are not in the exclude array, according to your configuration - but will not merge them to one file.
Hope it was clear enough.
Let me know if you need more help.
Uriah.