PYYUPSK

a self-taught dev from Thailand

Pongsakorn Thipayanate · Samutsakhon, TH ·webring

active

@vite-env/core

The env.ts layer for Vite. You define your variables once, validate them everywhere, and import them with types.

TypeScript / Vite / npm· 2026

GitHub →

view .mdopen in claudeopen in chatgpt

This plugin does for Vite what @t3-oss/env does for Next.js. It is built natively on Vite 8 and Rolldown. You define your environment variables once with a schema. You then get validated, typed imports everywhere.

Why I Built This

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

Key Features

  • Typed virtual modules: You import env with full IntelliSense.
  • Server/client split: The plugin detects leaks at build time.
  • Zod v4 native validation: The plugin also supports Standard Schema, including Valibot and ArkType.
  • Auto .d.ts generation: You get type safety without manual declarations.
  • Platform presets: The plugin supports Vercel, Railway, and Netlify.
  • HMR .env watching: Changes reload without a restart.

Technical Details

The plugin generates virtual modules at build time. It splits server and client variables into separate imports. If client code imports a server variable by accident, the build fails. This stops 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. It catches errors at build time instead of runtime.

← All projects