Nviron
Installation

Vite Installation

Install and configure nviron with Vite

Vite

For Vite projects, use the source and prefix options:

src/env.ts
import { defineEnv, z } from "nviron";

export const env = defineEnv(
  {
    API_URL: z.string().url(),
    ENABLE_ANALYTICS: z.coerce.boolean(),
  },
  {
    source: import.meta.env,
    prefix: "VITE_",
  },
);

Your .env file:

.env
VITE_API_URL=https://api.example.com
VITE_ENABLE_ANALYTICS=true

On this page