docs(misc): Adding index.html interpolation to env variable guide (#6184)

This commit is contained in:
Zachary DeRose 2021-07-02 10:57:34 -07:00 committed by GitHub
parent d8cc3d91cf
commit 9acf7ecd69
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,7 +4,10 @@ Environment variables are global system variables accessible by all the processe
## How to Use ## How to Use
It's important to note that NX will only include in the process default and NX prefixed env vars such as: `NODE_ENV` or `NX_CUSTOM_VAR`. It's important to note that NX will only include in the process:
- default env vars such as: `NODE_ENV`
- any environment variable prefixed with `NX_` such as: `NX_CUSTOM_VAR`
Defining environment variables can vary between OSes. Its also important to know that this is temporary for the life of the shell session. Defining environment variables can vary between OSes. Its also important to know that this is temporary for the life of the shell session.
@ -66,3 +69,17 @@ If you want to load variables from `env` files other than the ones listed above:
1. Use the [env-cmd](https://www.npmjs.com/package/env-cmd) package: `env-cmd -f .qa.env nx serve` 1. Use the [env-cmd](https://www.npmjs.com/package/env-cmd) package: `env-cmd -f .qa.env nx serve`
2. Use the `envFile` option of the [run-commands](/{{framework}}/workspace/run-commands-executor#envfile) builder and execute your command inside of the builder 2. Use the `envFile` option of the [run-commands](/{{framework}}/workspace/run-commands-executor#envfile) builder and execute your command inside of the builder
## Using Environment Variables in index.html
Nx supports interpolating environment variables into your `index.html` file for React and Web applications.
To interpolate an environment variable named `NX_DOMAIN_NAME` into your `index.html`, surround it with `%` symbols like so:
```html
<html>
<body>
<p>The domain name is %NX_DOMAIN_NAME%.</p>
</body>
</html>
```