A Vite plugin (v1.0.2) enabling runtime configuration for static builds. Unlike Vite's built-in env variables that are baked at build time, this plugin allows dynamic replacement of config placeholders (e.g., {{ VITE_X }}) in index.html via a generated script (patch_runtime_config.js). Supports development mode (auto-replacement from Vite env) and production mode (post-build script execution). Requires Vite ^3.1.0 and Vitest >0.23.2 <1.0 as peer dependencies. Suitable for projects served by external webservers without SSR.
npm install vite-plugin-runtime-configVerified import paths — ran on the pinned version, not inferred.
Shows minimal setup: adding plugin to vite config, placeholder syntax, and build + post-build steps for production.
Update CI/CD to run 'node dist/patch_runtime_config.js' instead of 'node apply-config.js'.
Remove 'outDir' from runtimeConfig options and adjust paths accordingly.
Ensure placeholders are formatted as '{{ VITE_VAR }}' or '{% VITE_RT_CONFIG %}'.Set 'htmlFiles' option in runtimeConfig to include additional files, or run patch script on each file individually.
npm install --save-dev vite-plugin-runtime-config
Use {{ VITE_test }} or define a correct environment variable with VITE_ prefix.Ensure runtimeConfig() is called in vite.config.ts plugins array and re-run 'npx vite build'.