Registry / web-framework / vite-plugin-runtime-config

vite-plugin-runtime-config

JSON →
library1.0.2jsnpmunverified

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-config
INSTALL
IMPORT
SIG · VITE-PLUGIN-RUNTIM
V
vite-plugin-runtime-config
web-frameworkjavascriptv1.0.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

runtimeConfig
import runtimeConfig from 'vite-plugin-runtime-config'
const runtimeConfig = require('vite-plugin-runtime-config')
Default export; ESM-only. CommonJS require will fail.
RuntimeConfigOptions
import type { RuntimeConfigOptions } from 'vite-plugin-runtime-config'
import { RuntimeConfigOptions } from 'vite-plugin-runtime-config'
Type import; not a runtime value. Use import type to avoid bundler issues.
vite-plugin-runtime-config
import runtimeConfig from 'vite-plugin-runtime-config'
import { runtimeConfig } from 'vite-plugin-runtime-config'
Default export only; named export 'runtimeConfig' does not exist.

Shows minimal setup: adding plugin to vite config, placeholder syntax, and build + post-build steps for production.

// vite.config.ts import { defineConfig } from 'vite'; import runtimeConfig from 'vite-plugin-runtime-config'; export default defineConfig({ plugins: [runtimeConfig()], }); // index.html snippet // Placeholder: {{ VITE_APP_TITLE }} // Build: npx vite build // Post-build: node dist/patch_runtime_config.js --in dist/index.html --out dist/index.html
Debug
Known issues
breakingNode script location mismatch: In versions prior to 1.0.0, the patch script was named 'apply-config.js' and located at root of output. Since v1.0.0, it is 'patch_runtime_config.js' in the dist folder.
fix
Update CI/CD to run 'node dist/patch_runtime_config.js' instead of 'node apply-config.js'.
affects: <1.0.0
deprecatedThe 'outDir' option is deprecated in v1.0.0+. The patch script is always placed in the Vite output directory (configured by build.outDir, default 'dist').
fix
Remove 'outDir' from runtimeConfig options and adjust paths accordingly.
affects: >=1.0.0
gotchaPlaceholder syntax must match exactly: use double curly braces with leading/trailing spaces ({{ VITE_X }}) or {% VITE_RT_CONFIG %}. Single braces or missing spaces will not be replaced.
fix
Ensure placeholders are formatted as '{{ VITE_VAR }}' or '{% VITE_RT_CONFIG %}'.
affects: >=1.0.0
gotchaThe plugin only processes 'index.html' by default. Custom HTML files are not patched unless explicitly specified via options.
fix
Set 'htmlFiles' option in runtimeConfig to include additional files, or run patch script on each file individually.
affects: >=1.0.0
Errors
Common errors & fixes
Cannot find module 'vite-plugin-runtime-config'
Package not installed.
fix
npm install --save-dev vite-plugin-runtime-config
Error: Configuration option 'test' is not a valid key.
Attempting to reference a placeholder like {{ test }} but VITE_ prefix is missing (env vars require VITE_ prefix).
fix
Use {{ VITE_test }} or define a correct environment variable with VITE_ prefix.
Error: patch_runtime_config.js is missing.
Build failed or plugin not applied correctly.
fix
Ensure runtimeConfig() is called in vite.config.ts plugins array and re-run 'npx vite build'.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies
viterequiredPeer dependency; plugin requires Vite >=3.1.0
vitestoptionalPeer dependency for testing; required only for development
Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
vite-plugin-runtime-config — npm install vite-plugin-runtime-config · libregistry