Skip to content

Commit 3c4a571

Browse files
Thien Dofeiqitian
Thien Do
authored andcommitted
Define process.env as object (facebook#807)
* Define process.env as object * Fix define process.env * fix NODE_ENV check * Fix style nitpick
1 parent 5c3696e commit 3c4a571

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

Diff for: packages/react-scripts/config/env.js

+5-4
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,25 @@
1515
var REACT_APP = /^REACT_APP_/i;
1616

1717
function getClientEnvironment(publicUrl) {
18-
return Object
18+
var processEnv = Object
1919
.keys(process.env)
2020
.filter(key => REACT_APP.test(key))
2121
.reduce((env, key) => {
22-
env['process.env.' + key] = JSON.stringify(process.env[key]);
22+
env[key] = JSON.stringify(process.env[key]);
2323
return env;
2424
}, {
2525
// Useful for determining whether we’re running in production mode.
2626
// Most importantly, it switches React into the correct mode.
27-
'process.env.NODE_ENV': JSON.stringify(
27+
'NODE_ENV': JSON.stringify(
2828
process.env.NODE_ENV || 'development'
2929
),
3030
// Useful for resolving the correct path to static assets in `public`.
3131
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
3232
// This should only be used as an escape hatch. Normally you would put
3333
// images into the `src` and `import` them in code to get their paths.
34-
'process.env.PUBLIC_URL': JSON.stringify(publicUrl)
34+
'PUBLIC_URL': JSON.stringify(publicUrl)
3535
});
36+
return {'process.env': processEnv};
3637
}
3738

3839
module.exports = getClientEnvironment;

Diff for: packages/react-scripts/config/webpack.config.prod.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ var env = getClientEnvironment(publicUrl);
4949

5050
// Assert this just to be safe.
5151
// Development builds of React are slow and not intended for production.
52-
if (env['process.env.NODE_ENV'] !== '"production"') {
52+
if (env['process.env'].NODE_ENV !== '"production"') {
5353
throw new Error('Production builds must have NODE_ENV=production.');
5454
}
5555

0 commit comments

Comments
 (0)