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 = ;
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;
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;
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 = ; var webpackDefine = Config;
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 = ; var plugins = Configplugins plugin: WebpackDefinePlugin parameters: VERSION: JSON plugin: WebpackUglifyJsPlugin 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" ; moduleexports = Config;
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; moduleexports = entry: "./base.entry.js" output: filename: "bundle.js" module: loaders: Config ;
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;
Property specific example:
babel;
Function example:
babel;
Resolve merge example:
babel;
Define merge behaviour example:
babel;
loader.set([property], changes)
Basic example:
babel;
Property specific example:
babel;
Resolve set example:
var Config = ;var ExtractTextPlugin = ; var sass = Config; sass;
loader.resolve()
Plugin
plugin.merge([index], changes)
Basic example:
webpackDefine;
Property specific example:
webpackDefine;
Another property specific example:
webpackDefine;
plugin.set([index], changes)
Basic example:
webpackDefine;
Property specific example:
webpackDefine;
Another property specific example:
webpackDefine;
plugin.resolve()
Helpers
concatMerge
By default, merges will overwrite arrays. This helper provides a simple implementation that overrides said behaviour.
Basic example:
var Config = ; var helpers = Confighelpers;var sass = Config; sass;
Prepend example:
var Config = ; var helpers = Confighelpers;var base = entry: "./main.js" output: filename: "bundle.js" ; moduleexports = Config;