A Vite plugin that replaces `import.meta.env.VITE_*` with `window.env.*` at build time for flexible runtime environment variable injection. Current stable version is 1.4.0 (July 2024). Releases are active with a new minor/patch version every few months, adding features like `envsubstTemplate` and `injectHtml`. Key differentiators: eliminates the VITE_ prefix requirement, generates runtime env.js files, supports type generation, and can inject HTML scripts. Requires Node >=18 and any version of Vite. Peer dependency on Vite is required.
npm install vite-plugin-runtimeVerified import paths — ran on the pinned version, not inferred.
Configures vite-plugin-runtime with the runtimeEnv plugin, setting the runtime object name to 'env', enabling HTML injection and type generation.
Upgrade Node to version 18 or higher.
Use ESM imports: `import { runtimeEnv } from 'vite-plugin-runtime'`.Either leave `injectHtml: true` or add a `<script>` tag loading `/env.js` in your HTML file.
Update your code to use `window.env.VARIABLE` or set a custom `name` option.
Only enable `envsubstTemplate` if you specifically need to create an envsubst template file.
Use only one runtimeEnv plugin instance, or ensure plugin ordering is correct.
Change to `import { runtimeEnv } from 'vite-plugin-runtime'`.Switch to ESM imports or use a dynamic import: `const { runtimeEnv } = await import('vite-plugin-runtime')`.Run `npm install --save-dev vite vite-plugin-runtime`.
Set `injectHtml: true` or manually include `<script src='/env.js'></script>` in your HTML file.