vite-plugin-crush-envy
v1.0.2
Published
Make .env type-safe, finally
Maintainers
Readme
Vite Plugin Crush Envy
Make .env type-safe, finally
Features
- ✨ Auto-generate
ImportMetaEnvtypes from.envfiles - 🎯 Safe injection into existing
vite-env.d.ts - ⚡ Auto-regenerate on
.envfile changes - 📦 Optional
process.envtype support
Getting Started
Requires
- Vite 7.0.0+
Install
pnpm add -D vite-plugin-crush-envyQuick Start
Add plugin to Vite config
vite.config.ts
import { defineConfig } from 'vite';
import crushEnvy from 'vite-plugin-crush-envy';
export default defineConfig({
plugins: [crushEnvy()],
});Example
.env
VITE_ENV=development
VITE_BASE_URL=/appGenerated in src/vite-env.d.ts:
interface ImportMetaEnv {
readonly VITE_BASE_URL: string;
readonly VITE_ENV: string;
}Now import.meta.env.VITE_* has full autocompletion!
Options
| Option | Type | Default | Description |
| ------ | ---- | ------- | ----------- |
| injectToViteEnv | boolean | true | Inject into src/vite-env.d.ts |
| output | string | src/env.d.ts | Output path when injectToViteEnv: false |
| includeProcessEnv | boolean | true | Generate NodeJS.ProcessEnv types |
