Skip to content

Instantly share code, notes, and snippets.

@jsphstls
Created December 30, 2019 18:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jsphstls/71d4cffd74ebfc31877fd802bbca3095 to your computer and use it in GitHub Desktop.
Save jsphstls/71d4cffd74ebfc31877fd802bbca3095 to your computer and use it in GitHub Desktop.
Environment Based Config
const SOME_KEY = 'someOption'
const something = {
development: {
[SOME_KEY]: 'for dev'
},
production: {
[SOME_KEY]: 'for prod'
},
test: {
[SOME_KEY]: 'for test'
}
}
module.exports = something[process.env.NODE_ENV]
// Usage: import { someOption } from 'config.js'
@jsphstls
Copy link
Author

Each React package in a monorepo could have its own .env.* file that uses REACT_APP_ variables, but dependency env variables are overwritten when the dependency is imported. See more here: facebook/create-react-app#4654

Instead, a different set of variables will be provided based on the NODE_ENV. This also helps align multiple packages that connect to the same service while reducing the number of ENV files.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment