From b5d80c28a3f846944ee8a539659a77bc049d6f72 Mon Sep 17 00:00:00 2001 From: Sebastian Scholl Date: Fri, 1 Jul 2022 14:15:19 -0400 Subject: [PATCH] Dedicated H3 to accessing Env Vars 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. --- docs/guide/env-and-mode.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/docs/guide/env-and-mode.md b/docs/guide/env-and-mode.md index e3eb14f6524329..e2078c00e65f62 100644 --- a/docs/guide/env-and-mode.md +++ b/docs/guide/env-and-mode.md @@ -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.