Vite plugin (v4.6.2, actively maintained) that enables dynamic injection of environment variables at container startup rather than build time. Designed for Dockerized Vite apps, it generates a shell script during build that populates import.meta.env and index.html placeholders (e.g., %FOO%) at runtime. Unlike standard Vite which requires rebuilding for env changes, vite-envs allows deploying a single Docker image configurable via --env flags. Supports type-safe imports with hot reload, optional EJS in HTML, and explicit variable declaration. Does not require the VITE_ prefix.
npm install vite-envsVerified import paths — ran on the pinned version, not inferred.
Minimal Vite config using viteEnvs plugin. Shows declaration, .env fallback, and runtime access via import.meta.env.
Update Dockerfile to run ./vite-envs.sh before starting server (see README).
List all expected variables in a .env file (or use the declaration option in vite.config.ts).
Use explicit declaration for all env vars to avoid surprises.
Avoid relying on internal global names; use the default behavior.
npm install vite-envs --save-dev && ensure tsconfig.json includes 'node' in moduleResolution or 'moduleResolution': 'bundler'.
Use 'import { viteEnvs } from 'vite-envs'; or 'import viteEnvs from 'vite-envs';'Add FOO to your .env file (even with a dummy value) or use the declaration option in viteEnvs().