From d8f16909041907b636cd209b5963bf9d9491c5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9mie=20Astori?= Date: Sat, 7 Jan 2017 18:04:46 -0500 Subject: [PATCH] Use Webpack configuration based on NODE_ENV instead of watch/no-watch Also, move the `DedupePlugin` to the prod-specific section. [Webpack doc](https://webpack.github.io/docs/list-of-plugins.html#dedupeplugin) itself recommends to not run this outside of production. Note that this currently breaks cross-OS support of `npm run build`. This will be fixed in a latter commit. --- package.json | 6 +++--- webpack.config.js | 15 +++++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 699254c9..cdd0706f 100644 --- a/package.json +++ b/package.json @@ -17,14 +17,14 @@ "start-dev": "npm-run-all --parallel watch start", "build": "npm-run-all build:*", "build:font-awesome": "node scripts/build-fontawesome.js", - "build:webpack": "webpack -p", - "watch": "webpack -d --watch", + "build:webpack": "webpack", + "watch": "webpack --watch", "test": "npm-run-all -c test:* lint", "test:mocha": "mocha", "lint": "npm-run-all -c lint:*", "lint:js": "eslint .", "lint:css": "stylelint \"**/*.css\"", - "prepublish": "npm run build" + "prepublish": "NODE_ENV=production npm run build" }, "keywords": [ "lounge", diff --git a/webpack.config.js b/webpack.config.js index 55f820d2..e2f4b094 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -2,7 +2,10 @@ const webpack = require("webpack"); const path = require("path"); -const isWatch = process.argv.includes("--watch"); + +// ******************** +// Common configuration +// ******************** let config = { entry: { @@ -54,12 +57,16 @@ let config = { ] }, plugins: [ - new webpack.optimize.DedupePlugin(), - new webpack.optimize.CommonsChunkPlugin("js/bundle.vendor.js"), + new webpack.optimize.CommonsChunkPlugin("js/bundle.vendor.js") ] }; -if (!isWatch) { +// ********************************* +// Production-specific configuration +// ********************************* + +if (process.env.NODE_ENV === "production") { + config.plugins.push(new webpack.optimize.DedupePlugin()); config.plugins.push(new webpack.optimize.UglifyJsPlugin({ comments: false, compress: {