03

Projects · active

@vite-env/core

The env.ts layer for Vite — define once, validate everywhere, import with types.

Created
Stack
TypeScriptVitenpm
Source
pyyupsk/vite-env

What @t3-oss/env is for Next.js, but built natively on Vite 8 and Rolldown. Define your environment variables once with a schema, and get validated, typed imports everywhere.

Why I Built This

I wrote about the four problems with plain Vite environment variables — no validation, no type safety, string-only values, and easy server/client leaks. This plugin solves all four.

Key Features

  • Typed virtual modules — import env with full IntelliSense
  • Server/client split with build-time leak detection
  • Zod v4 native validation with Standard Schema support (Valibot, ArkType)
  • Auto .d.ts generation for type safety without manual declarations
  • Platform presets for Vercel, Railway, Netlify
  • HMR .env watching — changes reload without restart

Technical Details

The plugin generates virtual modules at build time, splitting server and client variables into separate imports. If client code accidentally imports a server variable, the build fails — preventing secret leaks before they happen.

Getting started

  1. Install @vite-env/core and add the plugin to your Vite config
  2. Create an env.ts file with your schema
  3. Import from virtual:env/client or virtual:env/server
  4. Type-check your environment variables at build time

Why it matters

Environment variable bugs are silent and dangerous — a missing key returns undefined, a leaked secret exposes your backend. This plugin makes environment variables type-safe and validated, catching errors at build time instead of runtime.