JavaScript
Conditional Webpack Plugins

by Benny Neugebauer

const isProduction = (process.env.NODE_ENV === 'production');
const webpack = require('webpack');

const config = {
  plugins: [
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify(process.env.NODE_ENV),
      },
    }),
  ],
};

if (isProduction) {
  config.push(new webpack.optimize.UglifyJsPlugin());
}

module.exports = config;

const webpack = require('webpack');

module.exports = {
  plugins: [
    new webpack.DefinePlugin({
      'process.env': {
        NODE_ENV: JSON.stringify(process.env.NODE_ENV),
      },
    }),
    ... (process.env.NODE_ENV === 'production') ? [new webpack.optimize.UglifyJsPlugin()] : [],
  ],
};