Skip to content

Commit 53f9895

Browse files
committed
Set NODE_ENV in a different way
With the approach in element-hq#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.
1 parent 14c23f1 commit 53f9895

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

webpack.config.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ const additionalPlugins = [
1313
];
1414

1515
module.exports = (env, argv) => {
16+
let nodeEnv = argv.mode;
1617
if (process.env.CI_PACKAGE) {
1718
// Don't run minification for CI builds (this is only set for runs on develop)
1819
// We override this via environment variable to avoid duplicating the scripts
@@ -24,14 +25,7 @@ module.exports = (env, argv) => {
2425
// when working on the app but adds significant runtime overhead
2526
// We want to use the React production build but not compile the whole
2627
// application to productions standards
27-
additionalPlugins.concat([
28-
new webpack.EnvironmentPlugin({
29-
"NODE_ENV": "production",
30-
}),
31-
new webpack.DefinePlugin({
32-
"process.env.NODE_ENV": "production",
33-
}),
34-
]);
28+
nodeEnv = "production";
3529
}
3630

3731
const development = {};
@@ -94,6 +88,10 @@ module.exports = (env, argv) => {
9488
// we use a CSS optimizer too and need to manage it ourselves.
9589
minimize: argv.mode === 'production',
9690
minimizer: argv.mode === 'production' ? [new TerserPlugin({}), new OptimizeCSSAssetsPlugin({})] : [],
91+
92+
// Set the value of `process.env.NODE_ENV` for libraries like React
93+
// See also https://v4.webpack.js.org/configuration/optimization/#optimizationnodeenv
94+
nodeEnv,
9795
},
9896

9997
resolve: {

0 commit comments

Comments
 (0)