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

outputs-webpack-plugin

v1.0.1

Published

This is a plugin to diversify output path.

Downloads

12

Readme

About

With this plug-in, you can achieve multi-directory output to some extent.

Install

npm install outputs-webpack-plugin --save-dev

Usage

First, you should import the module and set filename in the output option of webpack to [name].js

// webpack.config.js
module.exports = {
    ...
    output: {
        filename: "[name].js"
    }
};

Secondly, you can add your entry files in webpack.config.js. Maybe, your config is like this:

// webpack.config.js
module.exports = {
    entry: {
        a: "./a.js",
        b: "./b.js"
    },
    output: {
        filename: "[name].js",
        path: path.reslove(__dirname, "dist")
    },
    ...
};

Be careful: the following code defaults to the configuration of webpack.config.js above.

The format for using this plug-in is:

// options is a json object.
new outputsPlugin(options);

Options

Separate rules

{
    // chunkName : path
    a: "a"
}
// This will create "a.js" in dist/a

Also, you can use [name] to represent the chunk name in path string.

{
    a: "[name]/[name]"
}
// This will create "a.js" in dist/a/a

In addition, you can use template, [path] and [name] to set the output path relative to dist.

{
    // chunkName: object
    a: {
        template: "[path][name]",
        path: "pathUrl"
    }
    // The [path] of template will be change to pathUrl, and the [name] will be change to chunkName. And they will be join by "/" to be the output path relative to dist
    // So, this will create "pathUrl/a/a.js" in dist.
}

tip: you can only use template without path property, and plugin will ignore "[path]" and regard template as the output path

Common rules

Sometimes, you need to set the common rules to output files. You can use the key of options "common".

{
    common: [
        // rule 1
        {
            // chunks applying the rule
            chunks: ["a", "b"],
            template: "[name]"
        },
        // other rules
    ]
    // also, you can use path property as before
    /*
    common: [
        {
            chunks: ["a", "b"],
            template: "[path][name]",
            path: ""
        }
    ]
    */

   // This will create "a/a.js" and "b/b.js" in dist
}

Eliminate

With "eliminate" option, you can remove some chunks or files out of output assets.

// eliminate chunk name
{
    eliminate: {
        // the extension of output file : array consists of chunk name
        js: ["a"]
    }
}
// if you don't want to remove all files in a chunk, you should use "filename"
{
    eliminate: {
        // the chunks to remove all files
        chunks: ["a"],
        // extension : chunks
        // -> remove b.js
        js: ["b"]
    }
}
// This means remove all files created by chunk "a", and remove the "b.js" in chunk "b"

Examples

Example One

// webpack.config.js
const outputsPlugin = require("outputs-webpack-plugin");
module.exports = {
    ...
    plugins: [
        new outputsPlugin({
            // chunkName : path
            // => outputPath: path + chunkName
            a: "[name]",
            b: "[name]"
        });
    ] 
};

The result of output is:
special
Now use the common option to achieve the same result.

...
module.exports = {
    ...
    plugins: [
        new outputsPlugin({
            common: [
                {
                    chunks: ["a", "b"],
                    template: "[name]"
                }
            ]
        });
    ]
};

Example Two

When you use sass-loader, you maybe only need css file, but not js file.

module.exports = {
    mode: "development",
    entry: {
        "a": "./a.scss",
        "b": "./b.scss"
    },
    output: {
        filename: "[name].js",
        path: path.resolve(__dirname, "dist")
    },
    module: {
        rules: [
            {
                test: /\.scss$/,
                use: ExtractTextPlugin.extract({
                    use: [
                        "css-loader", 
                        {
                            loader: "sass-loader",
                            options: {
                                outputStyle: "expanded",
                                chunkFilename: "[name]"
                            }                        
                        }
                    ]
                })
            }
        ]
    },
    plugins: [
        new ExtractTextPlugin({
            filename: "[name].css"
        }),
        new outputsPlugin({
            common: [
                {
                    chunks: ["a", "b"],
                    template: "[name]"
                }
            ],
            eliminate: {
                js: ["a", "b"]
            }
        })
    ]
};

The result is :
eliminate