Envka is a vite plugin designed to enhance environment variable management in Vite projects.
- Validate environment variables at Vite build and dev server startup
- TypeScript type generation (env.d.ts)
- Generate
.env.examplefrom schema - Checking for unused and undeclared environment variables (planned)
npm install vite-plugin-envka --save-devAdd to your vite.config.ts:
import envka from "vite-plugin-envka";
export default {
plugins: [envka(/* options */)],
};import envka from "vite-plugin-envka";
export default {
plugins: [
envka({
schema,
generateTypes: false /** Default */,
}),
],
};Generating env.d.ts is done after a successful validation. By default, its turned-off. You need to add generateTypes: true to turn it on.
Generating .env.example is done via the CLI
npx env example --schema /path/to/schema/file --output /optional/outputimport envka, { envkaValidator } from "vite-plugin-envka";
/** Example using Envka Validator */
export const builtinSchema = envkaValidator({
FOO: { type: "string", default: "bar" },
BAR: {
type: "number",
description: "A comment on your .env.example",
},
TEST_MODE: { type: "enum", enum: ["dev", "prod"] },
});
export default {
plugins: [
envka({
schema: builtinSchema,
generateTypes: true,
}),
],
};BSD-3 Clause