{"id":42248,"library":"vite-plugin-runtime-dotenv","title":"vite-plugin-runtime-dotenv","description":"A Vite plugin that enables runtime environment variables, allowing a single build to be deployed across multiple environments by generating separate builds with environment-specific variables injected. Version 1.0.0 requires Vite 7.x and ships TypeScript type definitions. Released in 2025. Unlike compile-time env substitution, this plugin duplicates the output into per-mode directories with injected runtime variables, making it suitable for CI/CD workflows where you want to 'build once, deploy anywhere'.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/DidacBA/vite-plugin-runtime-dotenv","tags":["javascript","vite","vite-plugin","env","dotenv","runtime-env","typescript"],"install":[{"cmd":"npm install vite-plugin-runtime-dotenv","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-runtime-dotenv","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-runtime-dotenv","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency – plugin requires Vite ^7.0.0 to function","package":"vite","optional":false}],"imports":[{"note":"Named export only; default import does not exist and will be undefined.","wrong":"import runtimeEnv from 'vite-plugin-runtime-dotenv'","symbol":"runtimeEnv","correct":"import { runtimeEnv } from 'vite-plugin-runtime-dotenv'"},{"note":"This is a TypeScript type export, not a runtime value. Use 'import type'.","wrong":"import { RuntimeEnvOptions } from 'vite-plugin-runtime-dotenv'","symbol":"RuntimeEnvOptions","correct":"import type { RuntimeEnvOptions } from 'vite-plugin-runtime-dotenv'"},{"note":"CJS require destructures the named export; default require returns the module object.","wrong":"const runtimeEnv = require('vite-plugin-runtime-dotenv')","symbol":"plugin (require)","correct":"const { runtimeEnv } = require('vite-plugin-runtime-dotenv')"}],"quickstart":{"code":"// vite.config.ts\nimport { defineConfig } from 'vite';\nimport { runtimeEnv } from 'vite-plugin-runtime-dotenv';\n\nexport default defineConfig({\n  plugins: [\n    runtimeEnv({\n      output: 'runtimeEnv.js',\n      globalVariableName: 'runtimeEnv',\n      modes: ['qa', 'stg', 'prod'],\n      generateDts: true,\n      defaultEnvFilenameAliases: {\n        production: 'prod',\n        development: 'dev',\n      },\n    }),\n  ],\n});\n\n// In your app code, access env variables via globalThis.runtimeEnv.VITE_API_URL","lang":"typescript","description":"Configures the plugin with three modes, enables TypeScript declaration generation, and shows how to access variables in application code."},"warnings":[{"fix":"Upgrade Vite to version 7 or higher, or use an alternative plugin for older Vite.","message":"Requires Vite ^7.0.0 – incompatible with older Vite versions","severity":"breaking","affected_versions":"<7.0.0"},{"fix":"Provide at least one mode in the 'modes' array.","message":"The 'modes' array is required – omitting it causes a runtime error","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Prefix your environment variables with VITE_ or configure the 'envPrefix' option in Vite.","message":"Only variables that start with VITE_ (or custom prefix if configured) are exposed to client code","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Ensure your deployment script references the correct path, e.g., dist/qa/runtimeEnv.js.","message":"The generated runtimeEnv.js is placed in each mode's output directory, not at the root of dist","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'1.0.0':35 '2025':47 '7':38 'across':21 'allow':14 'anywher':81 'build':17,27,78 'ci/cd':72 'compil':50 'compile-tim':49 'definit':44 'deploy':20,80 'directori':63 'dotenv':5,88 'duplic':56 'enabl':10 'env':52,87,91 'environ':12,23,30 'environment-specif':29 'generat':25 'inject':33,65 'javascript':82 'make':68 'mode':62 'multipl':22 'output':58 'per':61 'per-mod':60 'plugin':3,8,55,86 'releas':45 'requir':36 'runtim':4,11,66,90 'runtime-env':89 'separ':26 'ship':41 'singl':16 'specif':31 'substitut':53 'suitabl':70 'time':51 'type':43 'typescript':42,92 'unlik':48 'variabl':13,32,67 'version':34 'vite':2,7,37,83,85 'vite-plugin':84 'vite-plugin-runtime-dotenv':1 'want':76 'workflow':73 'x':39","created_at":"2026-06-04T18:56:20.322786+00:00","updated_at":"2026-06-04T18:56:20.322786+00:00","problems":[{"fix":"import { runtimeEnv } from 'vite-plugin-runtime-dotenv'","cause":"Default import used instead of named import","error":"TypeError: Cannot destructure property 'runtimeEnv' of '...' as it is undefined"},{"fix":"Add a non-empty 'modes' array to the plugin options.","cause":"The 'modes' option was omitted or set to an empty array","error":"The plugin requires at least one mode to be provided"},{"fix":"Run 'npm install vite-plugin-runtime-dotenv' and ensure Vite version is >=7.0.0","cause":"Package not installed or peer dependency Vite ^7.0.0 not met","error":"Error: Cannot find module 'vite-plugin-runtime-dotenv'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/DidacBA/vite-plugin-runtime-dotenv","github":"https://github.com/DidacBA/vite-plugin-runtime-dotenv","docs":null,"changelog":null,"pypi":null,"npm":"vite-plugin-runtime-dotenv","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}