webpack-config-assign

1.0.0 • Public • Published

webpack-config-assign

Build status Coverage Status NPM Version

A utility to "smartly" merge/assign a series of webpack configs, typically a "base" config then merged with one to many environment configs (e.g. development, test, production, etc.). Think of it like an intelligent Object.assign, but tailored specifically for Webpack configs

Install

npm install webpack-config-assign --save-dev

or

yarn add webpack-config-assign --dev

Usage

webpackConfigAssign(baseConfig, ...extendConfigs)

The utility assumes that the first argument passed in is the "base," and any subsequent configs are smartly merged with this base config.

const webpackConfigAssign = require('webpack-config-assign');
 
const baseConfig = require('./webpack.config.base');
const devConfig = process.env.NODE_ENV === 'development' ? require('./webpack.config.development') : {};
 
module.exports = webpackConfigAssign(baseConfig, devConfig);

Usage with Webpack 2

This utility also works with webpack 2, and in particular, works particularly well with webpack 2's ability to pass in environment from the CLI.

Additionally, this utility works seamlessly with module.loaders (webpack 1) or module.rules (webpack 2), and interops with both (although it's recommended to choose one style, if possible)

given: webpack --env.development=true

const webpackConfigAssign = require('webpack-config-assign');
 
module.exports = function(env) {
  const baseConfig = require('./webpack.config.base');
  const developmentConfig = env.development ? require('./webpack.config.development') : {};
 
  return webpackConfigAssign(baseConfig, developmentConfig);
};

Package Sidebar

Install

npm i webpack-config-assign

Weekly Downloads

2

Version

1.0.0

License

MIT

Last publish

Collaborators

  • dschau