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

dtsbundler-webpack-plugin

v1.0.0

Published

Generates a single module declaration file from separate generated declaration files from an EXTERNAL module

Downloads

543

Readme

Description

This library takes separate declaration asset files generated by the webpack build process and bundles them into one single declaration file. Inspired by @floyon

When to use this

This plugin, with a setup as below, flattens class hierarchies in a module to a single d.ts file used by the entry point (usually index.ts) The usecase allows a module to have a single d.ts file at the root or dist/ level rather than many d.ts files scattered throughout the source folder

Options:

  • out: the path where the combined declaration file should be saved.

Requirements:

This plugin was developed as an extention to the ts-loader which - when declaration is set to true in tsconfig.json - generates separate declaration files for each source file. In theory though, it should work with any loader which generates declaration files as output.

Here is an example setup:

//index.ts
export {default as Foo} './src/foo';
export {default as Foo2} './src/foo2';

//src/foo.ts
export default class Foo
{
    bar():boolean
    {
    	return true;
    }
}

//src/foo2.ts
import Foo './foo';

export default class Foo2 extends Foo
{
    bar():boolean
    {
    	return true;
    }
}

Which generates (when using the declaration=true flag for the typescript compiler)

//index.d.ts
export {default as Foo} './src/foo';
export {default as Foo2} './src/foo2';

//foo.d.ts
declare class Foo {
    bar():boolean;
}
export default Foo;

//foo2.d.ts
import Foo './foo';
declare class Foo2 extends Foo {
    bar():boolean;
}
export default Foo2;

Which with the following webpack.config.js

var DtsBundlerPlugin = require('dtsbundler-webpack-plugin');
module.exports = {
    entry: './index.ts',
    output: {
        filename: './dist/index.js'
    },
    resolve: {
        extensions: ['', '.ts', '.tsx','.webpack.js', '.web.js', '.js']
    },
    module: {
        loaders: [
            { test: /\.ts(x?)$/, loader: 'ts-loader' }
        ]
    },
    watch:true,
    plugins: [
        new DtsBundlerPlugin({
            out:'./dist/index.d.ts',
        })
    ]
}

Will be turned into:

//index.d.ts
declare class Foo {
	bar():boolean;
}

declare class Foo2 extends Foo {
	bar():boolean;
}

With this setup and generated declaration file, other modules that want to use this module can add a reference to the generated index.d.ts. They can then access all classes of the module as if they are defined in the index.ts of the module