npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

bundle-declarations-webpack-plugin

v5.1.1

Published

Webpack plugin which wraps https://www.npmjs.com/package/dts-bundle-generator/

Downloads

11,262

Readme

bundle-declarations-webpack-plugin

NPM version release tests XO code style

Example usage

Simplest scenario

As of version 3.1.0, it's possible to omit the configuration overrides; when you do this, the plugin will fallback on webpack's entrypoints and other defaults.

import BundleDeclarationsWebpackPlugin from "bundle-declarations-webpack-plugin";
import { resolve } from "path";
import type { Configuration } from "webpack";

export default <Configuration> {
    entry: "./src/main.ts",
    output: {
        filename: "index.js",
        path: resolve("./dist"),
    },
    plugins: [
        `...`,
        new BundleDeclarationsWebpackPlugin(),
    ],
};

The configuration above adds the plugin with default options. All typescript included/imported by the ./src/main.ts file is transpiled to ./dist/index.js and all exported types for the bundle are added to the output directory with the default name index.d.ts.
Just to be clear, currently the output filename is defaulted to this value, but the key in webpack's entry is not considered/applied if set as it is with the webpack bundle.

Most common scenario

Usually you will want to include all types which are visible on the surface of a library, but the entry and outFile may not necessarily match with your webpack bundle.

import BundleDeclarationsWebpackPlugin from "bundle-declarations-webpack-plugin";
import type { Configuration } from "webpack";

export default <Configuration> {
    plugins: [
        `...`,
        new BundleDeclarationsWebpackPlugin({
            entry: ["./src/index.ts", "./src/globals.ts"],
            outFile: "main.d.ts",
        }),
    ]
}

In the above example, the exports of index.ts and globals.ts are combined into webpack's output as main.d.ts.

When you need control of dts-bundle-generator

import BundleDeclarationsWebpackPlugin from "bundle-declarations-webpack-plugin";
import type { Configuration } from "webpack";

export default <Configuration> {
    plugins: [
        `...`,
        new BundleDeclarationsWebpackPlugin({
            entry: {
                filePath: "./src/index.ts",
                libraries: {
                    inlinedLibraries: [
                        "tsyringe",
                    ],
                },
                output: {
                    sortNodes: false,
                    // dts-bundle-generator comments in output
                    noBanner: false, 
                }
            },
            outFile: "index.d.ts",

            compilationOptions: {
                followSymlinks: true,
                preferredConfigPath: "./some/tsconfig.json",
            },
            
            // setting these will mean no post-processing
            removeEmptyLines: false,
            removeEmptyExports: false,
            removeRelativeReExport: false,
        }),
    ]
}

Multiple entrypoints with different config

Assuming you want to combine into 1 .d.ts bundle, this can be achieved by providing an array of EntryPointConfigs to a single plugin instance's entry option.

Multiple bundles

This is expected, it should be completely safe to use multiple instances of the plugin as part of webpack's parallel builds; in fact the only thing stopping you from reusing the same instance is that the options are shared (which might be fine in some cases).

Watch mode

As of version 4.0.0, .d.ts bundling runs as a background process while webpack is in watch mode; this means that it will no longer delay incremental builds, but consequently the declarations may become out of sync with the webpack compilations.
Also note that the plugin will output to the file system even when shouldEmit returns false.