Skip to content

Commit

Permalink
Dedicated H3 to accessing Env Vars
Browse files Browse the repository at this point in the history
I propose dedicating a h3 section to "Accessing Environment Variables in Application Code" that more clearly calls out how env vars need to be prefixed with `VUE_` to be accessed via `import.meta.env` in client source code.
  • Loading branch information
sebscholl authored Jul 1, 2022
1 parent 8970f16 commit b5d80c2
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions docs/guide/env-and-mode.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,18 @@ In addition, environment variables that already exist when Vite is executed have

Loaded env variables are also exposed to your client source code via `import.meta.env` as strings.

To prevent accidentally leaking env variables to the client, only variables prefixed with `VITE_` are exposed to your Vite-processed code. e.g. the following file:
### Accessing Environment Variables in Application Code

To prevent accidentally leaking env variables to the client, only variables prefixed with `VITE_` are exposed to your Vite-processed code.

For example, consider the following file:

```
DB_PASSWORD=foobar
VITE_SOME_KEY=123
```

Only `VITE_SOME_KEY` will be exposed as `import.meta.env.VITE_SOME_KEY` to your client source code, but `DB_PASSWORD` will not.
The `VITE_SOME_KEY` will be accessible at `import.meta.env.VITE_SOME_KEY` to your client source code because it is prefixed with `VITE_`. The `DB_PASSWORD` will not be accessible in the cliect source code.

If you want to customize env variables prefix, see [envPrefix](/config/index#envprefix) option.

Expand Down

0 comments on commit b5d80c2

Please sign in to comment.