@samitouri / QOS-React / commits / ea5f310fe1

Webpack config injects a __DEV_ constant

Brian Vaughn committed Mar 26, 2019 at 13:22 UTC ea5f310fe1948ab6f50d12ff2468c5652982087e
3 files changed +23 -16
shells/browser/shared/webpack.backend.js
+11
@@ -1,8 +1,13 @@
1 const { readFileSync } = require('fs');
2 const { resolve } = require('path');
3 +const { DefinePlugin } = require('webpack');
4
5 const __DEV__ = process.env.NODE_ENV !== 'production';
6
7 +const DEVTOOLS_VERSION = JSON.parse(
8 + readFileSync(resolve(__dirname, '../../../package.json'))
9 +).version;
10 +
11 module.exports = {
12 mode: __DEV__ ? 'development' : 'production',
13 devtool: __DEV__ ? 'cheap-module-eval-source-map' : false,
@@ -18,6 +23,12 @@ module.exports = {
23 src: resolve(__dirname, '../../../src'),
24 },
25 },
26 + plugins: [
27 + new DefinePlugin({
28 + __DEV__: true,
29 + 'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
30 + }),
31 + ],
32 module: {
33 rules: [
34 {
shells/browser/shared/webpack.config.js
+9 -16
@@ -2,7 +2,8 @@ const { readFileSync } = require('fs');
2 const { resolve } = require('path');
3 const { DefinePlugin } = require('webpack');
4
5 -const __DEV__ = process.env.NODE_ENV !== 'production';
5 +const NODE_ENV = process.env.NODE_ENV;
6 +const __DEV__ = NODE_ENV !== 'production';
7
8 const DEVTOOLS_VERSION = JSON.parse(
9 readFileSync(resolve(__dirname, '../../../package.json'))
@@ -27,21 +28,13 @@ module.exports = {
28 src: resolve(__dirname, '../../../src'),
29 },
30 },
30 - plugins: __DEV__
31 - ? [
32 - new DefinePlugin({
33 - 'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
34 - }),
35 - ]
36 - : [
37 - // Ensure we get production React
38 - new DefinePlugin({
39 - 'process.env.NODE_ENV': '"production"',
40 - }),
41 - new DefinePlugin({
42 - 'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
43 - }),
44 - ],
31 + plugins: [
32 + new DefinePlugin({
33 + __DEV__: false,
34 + 'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
35 + 'process.env.NODE_ENV': `"${NODE_ENV}"`,
36 + }),
37 + ],
38 module: {
39 rules: [
40 {
shells/dev/webpack.config.js
+3
@@ -2,6 +2,8 @@ const { readFileSync } = require('fs');
2 const { resolve } = require('path');
3 const { DefinePlugin } = require('webpack');
4
5 +const __DEV__ = process.env.NODE_ENV !== 'production';
6 +
7 const DEVTOOLS_VERSION = JSON.parse(
8 readFileSync(resolve(__dirname, '../../package.json'))
9 ).version;
@@ -27,6 +29,7 @@ module.exports = {
29 },
30 plugins: [
31 new DefinePlugin({
32 + __DEV__: __DEV__,
33 'process.env.DEVTOOLS_VERSION': `"${DEVTOOLS_VERSION}"`,
34 }),
35 ],