Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dedicated H3 to accessing Env Vars #8885

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions docs/guide/env-and-mode.md
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