From 77ffdc699032f9a669caa7a640cfe734da49cc5a Mon Sep 17 00:00:00 2001 From: Christopher Speller Date: Fri, 18 Mar 2016 08:48:26 -0400 Subject: Creating sepearate dev and prod webpack builds. Enabled webpack watch mode. Updated to latest master webpack to fix bug in watch mode --- webapp/webpack.config.js | 58 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 43 insertions(+), 15 deletions(-) (limited to 'webapp/webpack.config.js') diff --git a/webapp/webpack.config.js b/webapp/webpack.config.js index 5e1df9bfe..4a21d44c7 100644 --- a/webapp/webpack.config.js +++ b/webapp/webpack.config.js @@ -5,14 +5,20 @@ const CopyWebpackPlugin = require('copy-webpack-plugin'); const htmlExtract = new ExtractTextPlugin('html', 'root.html'); -module.exports = { +const NPM_TARGET = process.env.npm_lifecycle_event; //eslint-disable-line no-process-env + +var DEV = false; +if (NPM_TARGET === 'run') { + DEV = true; +} + +var config = { entry: ['babel-polyfill', './root.jsx', 'root.html'], output: { path: 'dist', publicPath: '/static/', filename: 'bundle.js' }, - devtool: 'source-map', module: { loaders: [ { @@ -22,7 +28,7 @@ module.exports = { query: { presets: ['react', 'es2015-webpack', 'stage-0'], plugins: ['transform-runtime'], - cacheDirectory: true + cacheDirectory: DEV } }, { @@ -69,19 +75,8 @@ module.exports = { new CopyWebpackPlugin([ {from: 'images/emoji', to: 'emoji'} ]), - new webpack.optimize.UglifyJsPlugin({ - 'screw-ie8': true, - mangle: { - toplevel: false - }, - compress: { - warnings: false - }, - comments: false - }), - new webpack.optimize.AggressiveMergingPlugin(), new webpack.LoaderOptionsPlugin({ - minimize: true, + minimize: !DEV, debug: false }) ], @@ -96,3 +91,36 @@ module.exports = { ] } }; + +// Development mode configuration +if (DEV) { + config.devtool = 'eval-cheap-module-source-map'; +} + +// Production mode configuration +if (!DEV) { + config.devtool = 'source-map'; + config.plugins.push( + new webpack.optimize.UglifyJsPlugin({ + 'screw-ie8': true, + mangle: { + toplevel: false + }, + compress: { + warnings: false + }, + comments: false + }) + ); + config.plugins.push( + new webpack.optimize.AggressiveMergingPlugin() + ); + config.plugins.push( + new webpack.optimize.OccurrenceOrderPlugin(true) + ); + config.plugins.push( + new webpack.optimize.DedupePlugin() + ); +} + +module.exports = config; -- cgit v1.2.3-1-g7c22