You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[feature] Implement dotenv-expand to accept variable expansion in dot env files #2223
Currently we use the dotenv library to parse a .env file in the project root and populate process.env. Great!
Although there exists scenarios in large scale deployments where the same environment variables are used accross many "app" or "services" or "containers"... For example
We have websites, API services and databases consuming a base set of environment variables such as:
CDN
STRIPE_KEY
API_HOST
VERSION_TAG
We don't want to have to add another set to this simply with the leading key REACT_APP_XXX. Dotenv has a has a sister project / plugin called dotenv-expand that allows, wait for it.... variable expansion in the file! e.g.
Also particularly useful for accessing properties in package.json, which are exposed as npm_package_* environment variables. For examples, npm_package_version or npm_package_name. For a more complete list, see this gist.
Sure - they are many ways to load a json file, however, most will expose the entirety of the file to the build bundle (see #2466). Method requested here and fulfilled by linked PR will allow cherry picking which vars get exposed.
FYI, to include an underscore in your expression use the ${ } format in your .env:
// bad
FOO_BAR=$npm_package_dependencies_foo_$npm_package_dependencies_bar
// 2.0
// good
FOO_BAR=${npm_package_dependencies_foo}_${npm_package_dependencies_bar}
// 1.0_2.0
Activity
FDiskas commentedon Sep 7, 2017
🚷 Keep in mind
.env
Result will be
fix react#2223 - [feature] Implement dotenv-expand to accept variable…
moos commentedon Nov 2, 2017
Also particularly useful for accessing properties in package.json, which are exposed as npm_package_* environment variables. For examples,
npm_package_versionornpm_package_name. For a more complete list, see this gist.FDiskas commentedon Nov 2, 2017
Json loader will do this
moos commentedon Nov 12, 2017
Sure - they are many ways to load a json file, however, most will expose the entirety of the file to the build bundle (see #2466). Method requested here and fulfilled by linked PR will allow cherry picking which vars get exposed.
gaearon commentedon Jan 8, 2018
This looks neat. I wouldn't mind taking a PR for this, but I'll close this issue since we likely won't add this ourselves.
gaearon commentedon Jan 9, 2018
I merged #3387.
fix #2223 - [feature] Implement dotenv-expand to accept variable expa… (
gaearon commentedon Jan 15, 2018
This is out in
react-scripts@1.1.0! Please let us know if something doesn’t quite work.https://github.com/facebookincubator/create-react-app/releases/tag/v1.1.0
moos commentedon Apr 13, 2018
FYI, to include an underscore in your expression use the
${ }format in your.env:where
fix react#2223 - [feature] Implement dotenv-expand to accept variable…
fix react#2223 - [feature] Implement dotenv-expand to accept variable…
fix react#2223 - [feature] Implement dotenv-expand to accept variable…