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
Copy file name to clipboardExpand all lines: packages/react-scripts/template/README.md
+40-23
Original file line number
Diff line number
Diff line change
@@ -400,8 +400,8 @@ to `process.env.NODE_ENV`.
400
400
These environment variables can be useful for displaying information conditionally based on where the project is
401
401
deployed or consuming sensitive data that lives outside of version control.
402
402
403
-
First, you need to have environment variables defined, which can vary between OSes. For example, let's say you wanted to
404
-
consume a secret defined in the environment inside a `<form>`:
403
+
First, you need to have environment variables defined. For example, let's say you wanted to consume a secret defined
404
+
in the environment inside a `<form>`:
405
405
406
406
```jsx
407
407
render() {
@@ -416,27 +416,6 @@ render() {
416
416
}
417
417
```
418
418
419
-
The above form is looking for a variable called `REACT_APP_SECRET_CODE` from the environment. In order to consume this
420
-
value, we need to have it defined in the environment:
421
-
422
-
#### Windows (cmd.exe)
423
-
424
-
```cmd
425
-
set REACT_APP_SECRET_CODE=abcdef&&npm start
426
-
```
427
-
428
-
(Note: the lack of whitespace is intentional.)
429
-
430
-
#### Linux, OS X (Bash)
431
-
432
-
```bash
433
-
REACT_APP_SECRET_CODE=abcdef npm start
434
-
```
435
-
436
-
> Note: Defining environment variables in this manner is temporary for the life of the shell session. Setting
437
-
permanent environment variables in development can be done in a `.env` file in the root of your project.
438
-
[dotenv](https://github.com/motdotla/dotenv) takes care of loading these for you.
439
-
440
419
With our environment variable defined, we start the app and consume the values. Remember that the `NODE_ENV`
441
420
variable will be set for you automatically. When you load the app in the browser and inspect the `<input>`, you will see
442
421
its value set to `abcdef`, and the bold text will show the environment provided when using `npm start`:
@@ -458,6 +437,44 @@ if (process.env.NODE_ENV !== 'production') {
458
437
}
459
438
```
460
439
440
+
The above form is looking for a variable called `REACT_APP_SECRET_CODE` from the environment. In order to consume this
441
+
value, we need to have it defined in the environment. This can be done using two ways: either in your shell or in
442
+
a `.env` file.
443
+
444
+
### Adding Temporary Environment Variables In Your Shell
445
+
446
+
Defining environment variables can vary between OSes. It's also important to know that this manner is temporary for the
447
+
life of the shell session.
448
+
449
+
#### Windows (cmd.exe)
450
+
451
+
```cmd
452
+
set REACT_APP_SECRET_CODE=abcdef&&npm start
453
+
```
454
+
455
+
(Note: the lack of whitespace is intentional.)
456
+
457
+
#### Linux, OS X (Bash)
458
+
459
+
```bash
460
+
REACT_APP_SECRET_CODE=abcdef npm start
461
+
```
462
+
463
+
### Adding Development Environment Variables In `.env`
464
+
465
+
>Note: this feature is available with `react-scripts@0.5.0` and higher.
466
+
467
+
Defining permanent environment variables in development can be done in a `.env` file in the root of your project.
468
+
[dotenv](https://github.com/motdotla/dotenv) takes care of loading these for you.
469
+
470
+
```bash
471
+
echo "REACT_APP_SECRET_CODE=abcsdef">> .env
472
+
npm start
473
+
```
474
+
475
+
>Note: if you are defining environment variables for development your CI and/or hosting platform will most likely need
476
+
these defined as well. Consult their documentation how to do this. Eg. [Travis CI](https://docs.travis-ci.com/user/environment-variables/) or [Heroku](https://devcenter.heroku.com/articles/config-vars)
477
+
461
478
## Can I Use Decorators?
462
479
463
480
Many popular libraries use [decorators](https://medium.com/google-developers/exploring-es7-decorators-76ecb65fb841) in their documentation.
0 commit comments