Define process.env as object (#807)

* Define process.env as object

* Fix define process.env

* fix NODE_ENV check

* Fix style nitpick
This commit is contained in:
Thien Do
2016-10-01 00:06:26 +07:00
committed by Dan Abramov
parent 0ad930e121
commit 92d9cda964
2 changed files with 6 additions and 5 deletions

View File

@@ -15,24 +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;
}, {
// Useful for determining whether were running in production mode.
// Most importantly, it switches React into the correct mode.
'process.env.NODE_ENV': JSON.stringify(
'NODE_ENV': JSON.stringify(
process.env.NODE_ENV || 'development'
),
// Useful for resolving the correct path to static assets in `public`.
// For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
// 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)
'PUBLIC_URL': JSON.stringify(publicUrl)
});
return {'process.env': processEnv};
}
module.exports = getClientEnvironment;