Skip to content

Vite plugin for validating environment variables with Zod

Notifications You must be signed in to change notification settings

kevbook/vite-plugin-zod-validate-envs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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']),
});

About

Vite plugin for validating environment variables with Zod

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published