Webpack 4 Declaration Bundler Plugin

1.0.6-beta.2 · abandoned · verified Tue Apr 21

This library, `declaration-bundler-webpack4-plugin`, bundles individual TypeScript declaration files (`.d.ts`) generated during the Webpack build process into a single, combined declaration file. It achieves this by re-composing the declarations as if all classes and interfaces were defined as internal modules within a specified `moduleName`. This makes the plugin particularly relevant for niche scenarios where classes and interfaces are deliberately exposed to a global module space, allowing for runtime access patterns that mimic internal TypeScript modules, often mapping prefixed URIs (like `foaf:Image`) back to module paths (e.g., `my.modules.rdfs.Image`). The current version is 1.0.6-beta.2. Given its beta status, the last commit dating back to early 2020, and its explicit tie to Webpack 4 (which is no longer the current major version of Webpack), its release cadence is effectively stalled, indicating it is no longer actively maintained. Its key differentiator is this unique, somewhat opinionated, approach to declaration bundling for a very specific internal module emulation pattern, which the documentation explicitly states makes it unsuitable for standard internal or external module usage. It primarily functions as an extension of `ts-loader`, requiring `ts-loader` to generate the initial individual declaration files for each source file, which this plugin then processes into a single output.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates a basic Webpack 4 configuration using `ts-loader` to compile TypeScript and `DeclarationBundlerPlugin` to consolidate generated `.d.ts` files into a single, internal-module-like declaration file, `bundle.d.ts`.

const path = require('path');
const DeclarationBundlerPlugin = require('declaration-bundler-webpack-plugin');

module.exports = {
    entry: './src/init.ts', // Assumes entry files like src/init.ts, src/foo.ts, src/foo2.ts as per README
    output: {
        filename: './builds/bundle.js',
        path: path.resolve(__dirname, 'dist') // Using path.resolve for output directory
    },
    resolve: {
        extensions: ['.ts', '.tsx', '.js'] // Modern usage, simplified from README for clarity
    },
    module: {
        rules: [ // 'loaders' is deprecated, 'rules' is current for Webpack 4+
            { test: /\.ts(x?)$/, loader: 'ts-loader' }
        ]
    },
    watch: false, // Set to false for a typical build, README shows true
    plugins: [
        new DeclarationBundlerPlugin({
            moduleName:'some.path.moduleName',
            out:'./builds/bundle.d.ts'
        })
    ]
};

view raw JSON →