Skip to content

Instantly share code, notes, and snippets.

@evanhsu
Created May 13, 2021 14:07
Show Gist options
  • Save evanhsu/0aa59bffee141136250ae5f948a8a0cc to your computer and use it in GitHub Desktop.
Save evanhsu/0aa59bffee141136250ae5f948a8a0cc to your computer and use it in GitHub Desktop.
Load env variables into process.env for a create-react-app project
{
"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"
}
}
@evanhsu
Copy link
Author

evanhsu commented May 13, 2021

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).

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