Vite: VITE_ variables and build time
Vite gives real environment variables priority over .env files, exposes only VITE_ names, and inlines them at build. Wrap vite with npx getmyenv run.
Oct 10, 2026 · 3 min read

1. The real environment wins
Variables that exist when Vite starts have the highest priority. A .env file does not replace them.
npx getmyenv run -- viterun does not read .env files. Delete them when you are ready. Until you do, Vite still fills names the context does not set from them.
2. Only VITE_ names reach the browser code
run passes every name to the Vite process. Vite exposes only the ones that start with VITE_, or your envPrefix.
jsconst apiUrl = import.meta.env.VITE_API_URL;
Vite loads .env files only after it reads the config. With run, every name is already in process.env, including in vite.config.
3. Values are inlined at build
vite build replaces import.meta.env.VITE_* with the values in the files it writes. Anyone who loads the site can read them. Build with the context you deploy. Production is Read-only, so the build machine needs a server token in GETMYENV_TOKEN:
npx getmyenv run production -- vite buildKeep API keys and other secrets out of VITE_ names. Call them from a server instead. set and import warn when a VITE_ name or value looks like a secret. A new value needs a new build.
4. Check what Vite gets
npx getmyenv run production --explain -- vite buildnpx getmyenv run --explain lists every name and where it comes from. Never values.
Related docs: How run works, Contexts, Languages