Vite plugin that injects environment variables at runtime instead of build time, enabling adherence to 12-factor app principles. Current stable version is v1.0.0, released as first stable after a long period in pre-release. It replaces import.meta.env references with window.env lookups and inserts placeholder variables in index.html for substitution during deployment using tools like envsubst. Key differentiators: supports multiple substitution syntaxes (dollar-basic, dollar-curly, handlebars), optionally ignores certain variables for build-time replacement, and allows custom variable names. Requires Vite as a peer dependency.
npm install vite-plugin-runtime-envVerified import paths — ran on the pinned version, not inferred.
Configures vite-plugin-runtime-env to replace import.meta.env with window.env references and inject placeholders in index.html.
Update to v1.0.0 or later; check for API stability.
Use v1.0.0+ for a stable API.
Ensure all runtime environment variables are prefixed with VITE_ and included in the plugin's scope.
Use a tool like envsubst or npx envsub to replace placeholders when deploying.
Monitor release notes; consider using 'dollar-curly' as default.
Run 'npm install --save-dev vite-plugin-runtime-env'
Use 'import runtimeEnv from 'vite-plugin-runtime-env'' (ESM).
Use one of 'dollar-basic', 'dollar-curly', or 'handlebars'.
Only use import.meta.env in browser/ESM context; the plugin only applies to Vite builds.
Define the variable in the deployment environment or set substitution syntax correctly.