TypeScript Declaration Webpack Plugin

1.2.3 · active · verified Tue Apr 21

This Webpack plugin streamlines the generation of TypeScript declaration files (`.d.ts`) by producing a single, bundled declaration file for each entry point configured in Webpack. It targets `ts` and `tsx` files by default and automatically places the generated `.d.ts` files alongside their corresponding compiled JavaScript outputs. The current stable version is 1.2.3. As a Webpack plugin, its release cycle is typically driven by maintenance, bug fixes, or compatibility updates with new Webpack or TypeScript versions rather than a fixed schedule. Its primary differentiator is simplifying the output of declaration files for complex projects with multiple Webpack entry points, contrasting with manual `tsc` commands or more complex bundlers.

Common errors

Warnings

Install

Imports

Quickstart

This Webpack configuration demonstrates how to integrate `ts-declaration-webpack-plugin` to generate bundled `.d.ts` files for 'app' and 'component' entries, alongside their compiled JavaScript.

const path = require('path');
const TsDeclarationWebpackPlugin = require('ts-declaration-webpack-plugin');

module.exports = {
    mode: 'production',
    entry: {
        app: './src/main.ts',
        component: './src/component.tsx',
    },
    output: {
        path: path.resolve(__dirname, 'dist'),
        filename: '[name].js',
        libraryTarget: 'umd'
    },
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                use: 'ts-loader',
                exclude: /node_modules/,
            },
        ],
    },
    resolve: {
        extensions: ['.tsx', '.ts', '.js'],
    },
    plugins: [
        new TsDeclarationWebpackPlugin({
            name: '[name].d.ts', // Optional: customize declaration file name
            test: /\.(ts|tsx)$/, // Optional: customize file types to process
        }),
    ]
};

view raw JSON →