env.js 1.1 KB

1234567891011121314151617181920212223242526272829
  1. // Grab NODE_ENV and REACT_APP_* environment variables and prepare them to be
  2. // injected into the application via DefinePlugin in Webpack configuration.
  3. var REACT_APP = /^REACT_APP_/i;
  4. function getClientEnvironment(publicUrl) {
  5. var processEnv = Object
  6. .keys(process.env)
  7. .filter(key => REACT_APP.test(key))
  8. .reduce((env, key) => {
  9. env[key] = JSON.stringify(process.env[key]);
  10. return env;
  11. }, {
  12. // Useful for determining whether we’re running in production mode.
  13. // Most importantly, it switches React into the correct mode.
  14. 'NODE_ENV': JSON.stringify(
  15. process.env.NODE_ENV || 'development'
  16. ),
  17. // Useful for resolving the correct path to static assets in `public`.
  18. // For example, <img src={process.env.PUBLIC_URL + '/img/logo.png'} />.
  19. // This should only be used as an escape hatch. Normally you would put
  20. // images into the `src` and `import` them in code to get their paths.
  21. 'PUBLIC_URL': JSON.stringify(publicUrl)
  22. });
  23. return {'process.env': processEnv};
  24. }
  25. module.exports = getClientEnvironment;