webpack config add production code example

Example 1: set env production webpack build

// webpack.config.js
module.exports = env => {
	const isProduction = env.NODE_ENV === 'production'
    // ...
    return {
      // ...
    }
}

// package.json
{
	...
    "scripts": {
    	"build": "webpack --env.NODE_ENV=production"
    },
    ...
}

Example 2: running webpack application on production server

new webpack.optimize.CommonsChunkPlugin('common.js'),
  new webpack.optimize.DedupePlugin(),
  new webpack.optimize.UglifyJsPlugin(),
  new webpack.optimize.AggressiveMergingPlugin()