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-cy-scripts/template/README.md
+8-7
Original file line number
Diff line number
Diff line change
@@ -446,13 +446,12 @@ default you will have `NODE_ENV` defined for you, and any other environment vari
446
446
447
447
**The environment variables are embedded during the build time**. Since Create React App produces a static HTML/CSS/JS bundle, it can’t possibly read them at runtime. To read them at runtime, you would need to load HTML into memory on the server and replace placeholders in runtime, just like [described here](#injecting-data-from-the-server-into-the-page). Alternatively you can rebuild the app on the server anytime you change them.
448
448
449
-
>Note: You must create custom environment variables beginning with `REACT_APP_`. Any other variables except `NODE_ENV` will be ignored to avoid accidentally [exposing a private key on the machine that could have the same name](https://github.com/facebookincubator/create-react-app/issues/865#issuecomment-252199527).
449
+
>Note: You must create custom environment variables beginning with `REACT_APP_`. Any other variables except `NODE_ENV` will be ignored to avoid accidentally [exposing a private key on the machine that could have the same name](https://github.com/facebookincubator/create-react-app/issues/865#issuecomment-252199527). Changing any environment variables will require you to restart the development server if it is running.
450
450
451
451
These environment variables will be defined for you on `process.env`. For example, having an environment
452
-
variable named `REACT_APP_SECRET_CODE` will be exposed in your JS as `process.env.REACT_APP_SECRET_CODE`, in addition
453
-
to `process.env.NODE_ENV`.
452
+
variable named `REACT_APP_SECRET_CODE` will be exposed in your JS as `process.env.REACT_APP_SECRET_CODE`.
454
453
455
-
>Note: Changing any environment variables will require you to restart the development server if it is running.
454
+
There is also a special built-in environment variable called `NODE_ENV`. You can read it from `process.env.NODE_ENV`. When you run `npm start`, it is always equal to `'development'`, when you run `npm test`it is always equal to `'test'`, and when you run `npm run build` to make a production bundle, it is always equal to `'production'`. **You cannot override `NODE_ENV` manually.** This prevents developers from accidentally deploying a slow development build to production.
456
455
457
456
These environment variables can be useful for displaying information conditionally based on where the project is
458
457
deployed or consuming sensitive data that lives outside of version control.
@@ -486,6 +485,10 @@ When you load the app in the browser and inspect the `<input>`, you will see its
486
485
</div>
487
486
```
488
487
488
+
The above form is looking for a variable called `REACT_APP_SECRET_CODE` from the environment. In order to consume this
489
+
value, we need to have it defined in the environment. This can be done using two ways: either in your shell or in
490
+
a `.env` file. Both of these ways are described in the next few sections.
491
+
489
492
Having access to the `NODE_ENV` is also useful for performing actions conditionally:
490
493
491
494
```js
@@ -494,9 +497,7 @@ if (process.env.NODE_ENV !== 'production') {
494
497
}
495
498
```
496
499
497
-
The above form is looking for a variable called `REACT_APP_SECRET_CODE` from the environment. In order to consume this
498
-
value, we need to have it defined in the environment. This can be done using two ways: either in your shell or in
499
-
a `.env` file.
500
+
When you compile the app with `npm run build`, the minification step will strip out this condition, and the resulting bundle will be smaller.
0 commit comments