Skip to content

Latest commit

 

History

History
31 lines (24 loc) · 761 Bytes

README.md

File metadata and controls

31 lines (24 loc) · 761 Bytes

vite-plugin-zod-validate-envs

Vite plugin to validate and transform environment variables using Zod at build or dev time.

Usage

$ pnpm add -D @kevbook/vite-plugin-zod-validate-envs
// vite.config.ts
import { resolve } from 'node:path';
import { defineConfig } from 'vite';
import { validateEnvs } from '@kevbook/vite-plugin-zod-validate-envs';

export default defineConfig({
  plugins: [validateEnvs({ schemaFile: resolve('config/validate-envs') })],
});
// validate-envs.ts
import { z } from 'zod';

export default z.object({
  OTEL_SERVICE_NAME: z.string().toLowerCase(),
  VERCEL_GIT_COMMIT_SHA: z.string().transform((val) => val.substring(0, 8)),
  ENABLED_FLAG: z.enum(['true', 'false']),
});