From 8f96bf0f21a5fa811057373973e1451655565446 Mon Sep 17 00:00:00 2001 From: Thien Do Date: Fri, 30 Sep 2016 22:39:45 +0700 Subject: [PATCH 1/4] Define process.env as object --- packages/react-scripts/config/env.js | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/packages/react-scripts/config/env.js b/packages/react-scripts/config/env.js index 2bdc65afa15..ecc56fef232 100644 --- a/packages/react-scripts/config/env.js +++ b/packages/react-scripts/config/env.js @@ -19,19 +19,21 @@ function getClientEnvironment(publicUrl) { .keys(process.env) .filter(key => REACT_APP.test(key)) .reduce((env, key) => { - env['process.env.' + key] = JSON.stringify(process.env[key]); + env['process.env'][key] = JSON.stringify(process.env[key]); return env; }, { - // Useful for determining whether we’re running in production mode. - // Most importantly, it switches React into the correct mode. - 'process.env.NODE_ENV': JSON.stringify( - process.env.NODE_ENV || 'development' - ), - // Useful for resolving the correct path to static assets in `public`. - // For example, . - // This should only be used as an escape hatch. Normally you would put - // images into the `src` and `import` them in code to get their paths. - 'process.env.PUBLIC_URL': JSON.stringify(publicUrl) + 'process.env': { + // Useful for determining whether we’re running in production mode. + // Most importantly, it switches React into the correct mode. + 'NODE_ENV': JSON.stringify( + process.env.NODE_ENV || 'development' + ), + // Useful for resolving the correct path to static assets in `public`. + // For example, . + // This should only be used as an escape hatch. Normally you would put + // images into the `src` and `import` them in code to get their paths. + 'PUBLIC_URL': JSON.stringify(publicUrl) + } }); } From 5c96669cff2a974c6ef7a6d50c910fd0704146ff Mon Sep 17 00:00:00 2001 From: Thien Date: Fri, 30 Sep 2016 23:30:01 +0700 Subject: [PATCH 2/4] Fix define process.env --- packages/react-scripts/config/env.js | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/packages/react-scripts/config/env.js b/packages/react-scripts/config/env.js index ecc56fef232..c8e6c9c1fc7 100644 --- a/packages/react-scripts/config/env.js +++ b/packages/react-scripts/config/env.js @@ -15,26 +15,25 @@ var REACT_APP = /^REACT_APP_/i; function getClientEnvironment(publicUrl) { - return Object + var processEnv = Object .keys(process.env) .filter(key => REACT_APP.test(key)) .reduce((env, key) => { - env['process.env'][key] = JSON.stringify(process.env[key]); + env[key] = JSON.stringify(process.env[key]); return env; }, { - 'process.env': { - // Useful for determining whether we’re running in production mode. - // Most importantly, it switches React into the correct mode. - 'NODE_ENV': JSON.stringify( - process.env.NODE_ENV || 'development' - ), - // Useful for resolving the correct path to static assets in `public`. - // For example, . - // This should only be used as an escape hatch. Normally you would put - // images into the `src` and `import` them in code to get their paths. - 'PUBLIC_URL': JSON.stringify(publicUrl) - } + // Useful for determining whether we’re running in production mode. + // Most importantly, it switches React into the correct mode. + 'NODE_ENV': JSON.stringify( + process.env.NODE_ENV || 'development' + ), + // Useful for resolving the correct path to static assets in `public`. + // For example, . + // This should only be used as an escape hatch. Normally you would put + // images into the `src` and `import` them in code to get their paths. + 'PUBLIC_URL': JSON.stringify(publicUrl) }); + return { 'process.env': processEnv } } module.exports = getClientEnvironment; From 769ec2112c87d4338d7eae9f3039d8ea47fd3835 Mon Sep 17 00:00:00 2001 From: Thien Date: Fri, 30 Sep 2016 23:46:00 +0700 Subject: [PATCH 3/4] fix NODE_ENV check --- packages/react-scripts/config/webpack.config.prod.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/config/webpack.config.prod.js b/packages/react-scripts/config/webpack.config.prod.js index 4c43cdf5193..2fb3035719e 100644 --- a/packages/react-scripts/config/webpack.config.prod.js +++ b/packages/react-scripts/config/webpack.config.prod.js @@ -49,7 +49,7 @@ var env = getClientEnvironment(publicUrl); // Assert this just to be safe. // Development builds of React are slow and not intended for production. -if (env['process.env.NODE_ENV'] !== '"production"') { +if (env['process.env'].NODE_ENV !== '"production"') { throw new Error('Production builds must have NODE_ENV=production.'); } From 84f69c0e0d617b753ec97218d72f762721b0de80 Mon Sep 17 00:00:00 2001 From: Dan Abramov Date: Fri, 30 Sep 2016 18:06:01 +0100 Subject: [PATCH 4/4] Fix style nitpick --- packages/react-scripts/config/env.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/react-scripts/config/env.js b/packages/react-scripts/config/env.js index c8e6c9c1fc7..66ba341b358 100644 --- a/packages/react-scripts/config/env.js +++ b/packages/react-scripts/config/env.js @@ -33,7 +33,7 @@ function getClientEnvironment(publicUrl) { // images into the `src` and `import` them in code to get their paths. 'PUBLIC_URL': JSON.stringify(publicUrl) }); - return { 'process.env': processEnv } + return {'process.env': processEnv}; } module.exports = getClientEnvironment;