From 14c23f13873d25c16c610f20fa45f4826d550d17 Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 19 Apr 2021 15:45:16 +0100 Subject: [PATCH 1/2] Remove old `-d` argument when packaging on CI This `-d` argument was removed from `package.sh` ages ago (ec66069e96ac8534999782aac65f12a6a4ecfcf0), but we seem to have missed removing it here. --- scripts/ci_package.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/ci_package.sh b/scripts/ci_package.sh index 2b82db737..41d82016e 100755 --- a/scripts/ci_package.sh +++ b/scripts/ci_package.sh @@ -14,4 +14,4 @@ JSSDK_SHA=$(cd node_modules/matrix-js-sdk; git rev-parse --short=12 HEAD) VECTOR_SHA=$(git rev-parse --short=12 HEAD) # use the ACTUAL SHA rather than assume develop -CI_PACKAGE=true DIST_VERSION=$VECTOR_SHA-react-$REACT_SHA-js-$JSSDK_SHA scripts/package.sh -d +CI_PACKAGE=true DIST_VERSION=$VECTOR_SHA-react-$REACT_SHA-js-$JSSDK_SHA scripts/package.sh From 53f9895901fb6b2777e8bafa9332174fadcbe7be Mon Sep 17 00:00:00 2001 From: "J. Ryan Stinnett" Date: Mon, 19 Apr 2021 15:49:05 +0100 Subject: [PATCH 2/2] Set `NODE_ENV` in a different way With the approach in https://github.com/vector-im/element-web/pull/16969, Webpack seems to sometimes do what we want, sometimes not... I haven't quite worked out why. Perhaps there's some conflict or race in Webpack's defaults...? This new approach seems to work as expected when running `./scripts/ci_package.sh`, which matches what development deployments are doing. --- webpack.config.js | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/webpack.config.js b/webpack.config.js index 7bb3e696a..57b1e4d28 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -13,6 +13,7 @@ const additionalPlugins = [ ]; module.exports = (env, argv) => { + let nodeEnv = argv.mode; if (process.env.CI_PACKAGE) { // Don't run minification for CI builds (this is only set for runs on develop) // We override this via environment variable to avoid duplicating the scripts @@ -24,14 +25,7 @@ module.exports = (env, argv) => { // when working on the app but adds significant runtime overhead // We want to use the React production build but not compile the whole // application to productions standards - additionalPlugins.concat([ - new webpack.EnvironmentPlugin({ - "NODE_ENV": "production", - }), - new webpack.DefinePlugin({ - "process.env.NODE_ENV": "production", - }), - ]); + nodeEnv = "production"; } const development = {}; @@ -94,6 +88,10 @@ module.exports = (env, argv) => { // we use a CSS optimizer too and need to manage it ourselves. minimize: argv.mode === 'production', minimizer: argv.mode === 'production' ? [new TerserPlugin({}), new OptimizeCSSAssetsPlugin({})] : [], + + // Set the value of `process.env.NODE_ENV` for libraries like React + // See also https://v4.webpack.js.org/configuration/optimization/#optimizationnodeenv + nodeEnv, }, resolve: {