I\'m trying to follow a tutorial and it says:
There are a few ways to load credentials.
- Loaded from environment variables,
Step 1: Add your environment variables to their appropriate file. For example, your staging environment could be called .env.staging
, which contains the environment variables USER_ID
and USER_KEY
, specific to your staging environment.
Step 2: In your package.json
file, add the following:
"scripts": {
"build": "sh -ac '. ./.env.${REACT_APP_ENV}; react-scripts build'",
"build:staging": "REACT_APP_ENV=staging npm run build",
"build:production": "REACT_APP_ENV=production npm run build",
...
}
then call it in your deploy script like this:
npm run build:staging
Super simple set up and works like a charm!
Source: https://medium.com/@tacomanator/environments-with-create-react-app-7b645312c09d