A Vite.js plugin (v1.1.3) that exposes environment variables to client code without requiring the VITE_ prefix. It acts as a shorthand for Vite's define option, similar to webpack's EnvironmentPlugin. Supports loading prefixed variables, custom define targets (import.meta.env), default values, optional/null handling, and .env file loading (on by default). Currently stable with monthly releases. Differentiates from Vite's built-in import.meta.env by allowing process.env usage and arbitrary variable names.
npm install vite-plugin-environmentVerified import paths — ran on the pinned version, not inferred.
Shows basic usage: expose two environment variables to client code as process.env.*
Upgrade Vite to at least 2.7
Explicitly parse booleans/numbers in client code: const debug = process.env.DEBUG === 'true'
Use specific array of variable names or prefix option to limit exposure
Explicitly set null for optional variables, undefined (or omit) for required
Run `npm install -D vite-plugin-environment` or `yarn add -D vite-plugin-environment`
Ensure plugin is properly loaded in vite.config.js, and check that the variable is defined in process.env during build
Use import statement: `import EnvironmentPlugin from 'vite-plugin-environment'`
Define the variable in your .env file or provide a default value in EnvironmentPlugin({ API_KEY: 'default' })