Created
May 13, 2021 14:07
-
-
Save evanhsu/0aa59bffee141136250ae5f948a8a0cc to your computer and use it in GitHub Desktop.
Load env variables into process.env for a create-react-app project
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"name": "Create React App", | |
"version": "1.0.0", | |
"private": true, | |
"scripts": { | |
"withenv": "export $(cat ../.env | xargs) && yarn", | |
"start": "yarn withenv react-scripts start", | |
"startnoenv": "react-scripts start" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This is mostly just useful for a local dev environment.
In CI, there's no way to have a .env file available unless it's stored in version control (e.g.
.env.dev
,.env.prod
, etc) which works as long as you're not storing secrets in there.If you're using a secret-manager like AWS Secrets Manager or the self-hosted Hashicorp Vault project, you should just load your secrets directly into your CI environment from your secret manager before building the React project (e.g. with
yarn build
).