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

wp-configurator

v1.0.1

Published

Helper for creating and extending Webpack configuration structures.

Downloads

4

Readme

Webpack Configurator

Install

$ npm install wp-configurator

API

Top-Level Exports

Below is a list of properties that are accessible at the top level of the module. Simply require the module into your script:

// Note: I use Pascal case when referencing external modules.
var Config = require("webpack-configurator");

loader(config)

Complex configurations often modify the properties of loaders. This utility helps aid composabilty by providing a number of methods that cater to common use cases. The example below shows how to construct a loader:

// The contents of 'babel' is a loader object wrapper.
var babel = Config.loader({
    test: /\.jsx?/,
    loader: "babel",
    query: {
        presets: ["es2015"]
    }
});

loaders(configs)

It's common to find configurations with multiple loaders. This utility provides a way to define several loaders at once, returning an array of loader object wrappers. Below is an example of its usage:

var loaders = Config.loaders([
    {
        test: /\.jsx?/,
        loader: "babel",
        query: {
            presets: ["es2015"]
        }
    },
    {
        test: /\.scss$/,
        loaders: ["style", "css", "sass"]
    }
]);

plugin(config)

It's sometimes difficult to customise plugins because of the way they differ from loaders. This utility makes it easier by splitting out the parameters. The plugin isn't created until the resolve method is called. Below is an example of its usage:

var Webpack = require("webpack");

var webpackDefine = Config.plugin({
    plugin: Webpack.DefinePlugin,
    parameters: [{
        VERSION: JSON.stringify("1.0.1"),
    }]
});

plugins(configs)

You may wish to define several plugins at once. This utility accepts an array of plugin configurations and returns an array of plugin object wrappers. Below is an example of its usage:

var Webpack = require("webpack");

var plugins = Config.plugins([
    {
        plugin: Webpack.DefinePlugin,
        parameters: [{
            VERSION: JSON.stringify("1.0.1")
        }]
    },
    {
        plugin: Webpack.UglifyJsPlugin,
        parameters: [{
            compress: {
                warnings: false
            }
        }]
    }
]);

merge(object, source, [customizer])

A generalised merge utility. It works in a similar way to loader.merge and plugin.merge, only this function has no validation on properties.

var base = {
    entry: "./base.entry.js",
    output: {
        filename: "bundle.js"
    }
};

module.exports = Config.merge(base, {
    devtool: "source-map",
    entry: "./dev.entry.js",
});

resolveAll(wrappers)

Useful when a configuration has several loaders or plugins. Each loader and plugin has a resolve method. This utility will call said method and return an array of resolved values.

var loaders = Config.loaders([
    {
        test: /\.jsx?$/,
        loader: "babel"
    },
    {
        test: /\.scss$/,
        loaders: ["style", "css", "sass"]
    }
]);

module.exports = {
    entry: "./base.entry.js",
    output: {
        filename: "bundle.js"
    },
    module: {
        loaders: Config.resolveAll(loaders)
    }
};

helpers

This object contains miscellaneous functions that help resolve common problems when creating Webpack configurations. Right now, there is only one helper available 'concatMerge'. However, this number will likely increase in the future.

Loader

loader.merge([property], changes, [customizer])

Basic example:

babel.merge({
    query: {
        presets: ["es2015", "react"]
    }
});

Property specific example:

babel.merge("query", {
    presets: ["es2015", "react"]
});

Function example:

babel.merge("query", function(config) {
    var presets = config.query.presets;

    return {
        presets: presets.concat(["react"])
    };
});

Resolve merge example:

babel.merge("loaders", function(config, loader) {
    var resolved = loader.resolve();

    return ExtractTextPlugin.extract(resolved.loaders);
});

Define merge behaviour example:

babel.merge("query", {
    presets: ["react"]
}, Config.helpers.concatMerge);

loader.set([property], changes)

Basic example:

babel.set({
    query: {
        presets: ["es2015", "react"]
    }
});

Property specific example:

babel.set("query", {
    presets: ["es2015", "react"]
});

Resolve set example:

var Config = require("webpack-configurator");
var ExtractTextPlugin = require("extract-text-webpack-plugin");

var sass = Config.loader({
    test: /\.scss$/,
    loaders: ["style", "css", "sass"],
    queries: {
        css: {sourceMap: true},
        sass: {sourceMap: true}
    }
});

sass.set("loaders", function(config, loader) {
    var resolved = loader.resolve();

    return ExtractTextPlugin.extract(resolved.loaders);
});

loader.resolve()

Plugin

plugin.merge([index], changes)

Basic example:

webpackDefine.merge([{
    TWO: "1+1"
}]);

Property specific example:

webpackDefine.merge(0, {
    TWO: "1+1"
});

Another property specific example:

webpackDefine.merge({
    0: {TWO: "1+1"}
});

plugin.set([index], changes)

Basic example:

webpackDefine.set([{
    TWO: "1+1"
}]);

Property specific example:

webpackDefine.set(0, {
    TWO: "1+1"
});

Another property specific example:

webpackDefine.set({
    0: {TWO: "1+1"}
});

plugin.resolve()

Helpers

concatMerge

By default, merges will overwrite arrays. This helper provides a simple implementation that overrides said behaviour.

Basic example:

var Config = require("webpack-configurator");

var helpers = Config.helpers;
var sass = Config.loader({
    test: /\.scss$/,
    loaders: ["style", "css"]
});

sass.merge({
    loaders: ["sass"]
}, helpers.concatMerge());

Prepend example:

var Config = require("webpack-configurator");

var helpers = Config.helpers;
var base = {
    entry: [
        "./main.js"
    ],
    output: {
        filename: "bundle.js"
    }
};

module.exports = Config.merge(base, {
    entry: [
        "webpack-dev-server/client?http://localhost:8080"
    ]
}, helpers.concatMerge(true));