From 5fb6819b0b3417138eb8a56a68863022e7637813 Mon Sep 17 00:00:00 2001 From: Fabio Moyano Date: Wed, 13 Feb 2019 18:25:30 -0500 Subject: [PATCH] Fix how NODE_ENV is being handled If an specific NODE_ENV value is specified, let it pass through and set the mode accordingly. If a non-standard NODE_ENV is specified, let is pass through and set the webpack mode to none. --- lib/build.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/build.js b/lib/build.js index 2898a991..7cf4b0ee 100644 --- a/lib/build.js +++ b/lib/build.js @@ -68,8 +68,14 @@ function webpackConfig(dir, additionalConfig) { defineEnv['process.env.' + key] = JSON.stringify(envConfig[key]); }); + // Keep the same NODE_ENV if it was specified + var nodeEnv = process.env.NODE_ENV || 'production' + + // Set webpack mode based on the nodeEnv + var webpackMode = ['production', 'development'].includes(nodeEnv) ? nodeEnv : 'none' + var webpackConfig = { - mode: 'production', + mode: webpackMode, resolve: { extensions: ['.wasm', '.mjs', '.js', '.json', '.ts'] }, @@ -99,6 +105,9 @@ function webpackConfig(dir, additionalConfig) { filename: '[name].js', libraryTarget: 'commonjs' }, + optimization: { + nodeEnv + }, devtool: false }; fs.readdirSync(dirPath).forEach(function(file) {