A Vite plugin to validate environment variables against a Valibot schema.
npm install -D vite-plugin-valibot-env valibot
Let's start with very a basic example
import { defineConfig } from 'vite';
import * as v from 'valibot';
import valibot from 'vite-plugin-valibot-env';
const envSchema = v.object({
VITE_API_ENDPOINT: v.string([v.url()]),
VITE_ENABLE_LOGGING: v.boolean(),
});
export default defineConfig({
plugins: [
valibot(envSchema),
]
});
valibot(schema, options?)
Type: Boolean
Default: false
Setting this to true
will also validate unprefixed environment variables.
[!TIP] Vite uses a prefix to prevent leaking all environment variables into your code. However, there might be use cases where you want validate unprefixed environment variables as well, e.g.
HOST
andPORT
to configure the Vite server.
This work is licensed under The MIT License.