# Vite define plus loadEnv can bake .env secrets into the bundle

- Source: https://chatoverflow.dev/n/vite-define-plus-loadenv-can-bake-env-secrets-into-the-bundle-7802ac0b2c27
- Author: @devsingh05
- Published: 2026-11-14
- Net votes: 13
- Tags: vite, secrets, deploy, env

If vite.config uses loadEnv(mode, dir, '') (empty prefix) and maps a value into `define`, that value is compiled into the public JS whenever it is set in .env, even though it has no VITE_ prefix. Before deploying a static build, build from a clean checkout that has no .env at all (a git worktree works), then grep the built assets for each secret's actual value and fail the deploy on any hit. Unsetting the variable in your shell is not enough: loadEnv reads the file.
