From 2a6eabf0f4747144376a7692f0ccae0d8320d684 Mon Sep 17 00:00:00 2001 From: Marshall Quander <marshall@quander.me> Date: Fri, 20 Jul 2018 17:13:57 -0700 Subject: [PATCH] Simplify prod/dev build configuration --- package.json | 5 ++--- webpack.config.js | 19 ++++++------------- yarn.lock | 9 +-------- 3 files changed, 9 insertions(+), 24 deletions(-) diff --git a/package.json b/package.json index 5f8651d43..048717a82 100644 --- a/package.json +++ b/package.json @@ -14,8 +14,8 @@ }, "scripts": { "postinstall": "node ./scripts/postinstall.js", - "start": "cross-env NODE_ENV=development webpack-dev-server", - "build": "rimraf ./public && cross-env NODE_ENV=production webpack --mode=production", + "start": "webpack-dev-server --mode=development", + "build": "rimraf ./public && webpack --mode=production", "doc": "node ./scripts/doc/build.js", "prettier": "prettier --write '*.js' 'src/**/*.js'", "lint:js": "eslint '*.js' 'scripts/**/*.js' 'src/**/*.js'", @@ -67,7 +67,6 @@ "babel-preset-env": "^1.6.1", "babel-preset-react": "^6.24.1", "copy-webpack-plugin": "^4.5.1", - "cross-env": "^5.1.3", "css-loader": "^1.0.0", "dotenv": "^5.0.1", "eslint": "^5.2.0", diff --git a/webpack.config.js b/webpack.config.js index d799bd2df..b4de849de 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -12,10 +12,6 @@ const UglifyJsPlugin = require("uglifyjs-webpack-plugin"); const _ = require("lodash"); function createHTTPSConfig() { - if (process.env.NODE_ENV === "production") { - return false; - } - // Generate certs for the local webpack-dev-server. if (fs.existsSync(path.join(__dirname, "certs"))) { const key = fs.readFileSync(path.join(__dirname, "certs", "key.pem")); @@ -77,7 +73,7 @@ class LodashTemplatePlugin { } } -const config = { +module.exports = (env, argv) => ({ entry: { index: path.join(__dirname, "src", "index.js"), hub: path.join(__dirname, "src", "hub.js"), @@ -89,8 +85,7 @@ const config = { filename: "assets/js/[name]-[chunkhash].js", publicPath: process.env.BASE_ASSETS_PATH || "" }, - mode: "development", - devtool: process.env.NODE_ENV === "production" ? "source-map" : "inline-source-map", + devtool: argv.mode === "production" ? "source-map" : "inline-source-map", devServer: { open: false, https: createHTTPSConfig(), @@ -249,7 +244,7 @@ const config = { // Extract required css and add a content hash. new ExtractTextPlugin({ filename: "assets/stylesheets/[name]-[md5:contenthash:hex:20].css", - disable: process.env.NODE_ENV !== "production" + disable: argv.mode !== "production" }), // Transform the output of the html-loader using _.template // before passing the result to html-webpack-plugin @@ -257,7 +252,7 @@ const config = { // expose these variables to the lodash template // ex: <%= ORIGIN_TRIAL_TOKEN %> imports: { - NODE_ENV: process.env.NODE_ENV, + NODE_ENV: argv.mode, ORIGIN_TRIAL_EXPIRES: process.env.ORIGIN_TRIAL_EXPIRES, ORIGIN_TRIAL_TOKEN: process.env.ORIGIN_TRIAL_TOKEN } @@ -265,7 +260,7 @@ const config = { // Define process.env variables in the browser context. new webpack.DefinePlugin({ "process.env": JSON.stringify({ - NODE_ENV: process.env.NODE_ENV, + NODE_ENV: argv.mode, JANUS_SERVER: process.env.JANUS_SERVER, DEV_RETICULUM_SERVER: process.env.DEV_RETICULUM_SERVER, ASSET_BUNDLE_SERVER: process.env.ASSET_BUNDLE_SERVER, @@ -273,6 +268,4 @@ const config = { }) }) ] -}; - -module.exports = config; +}); diff --git a/yarn.lock b/yarn.lock index 9d6efd300..e22104c37 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2060,13 +2060,6 @@ create-hmac@^1.1.0, create-hmac@^1.1.2, create-hmac@^1.1.4: safe-buffer "^5.0.1" sha.js "^2.4.8" -cross-env@^5.1.3: - version "5.2.0" - resolved "https://registry.yarnpkg.com/cross-env/-/cross-env-5.2.0.tgz#6ecd4c015d5773e614039ee529076669b9d126f2" - dependencies: - cross-spawn "^6.0.5" - is-windows "^1.0.0" - cross-spawn@^3.0.0: version "3.0.1" resolved "https://registry.yarnpkg.com/cross-spawn/-/cross-spawn-3.0.1.tgz#1256037ecb9f0c5f79e3d6ef135e30770184b982" @@ -4202,7 +4195,7 @@ is-utf8@^0.2.0: version "0.2.1" resolved "https://registry.yarnpkg.com/is-utf8/-/is-utf8-0.2.1.tgz#4b0da1442104d1b336340e80797e865cf39f7d72" -is-windows@^1.0.0, is-windows@^1.0.1, is-windows@^1.0.2: +is-windows@^1.0.1, is-windows@^1.0.2: version "1.0.2" resolved "https://registry.yarnpkg.com/is-windows/-/is-windows-1.0.2.tgz#d1850eb9791ecd18e6182ce12a30f396634bb19d" -- GitLab