Introduction
What is this?
The ArkEnv plugin for Vite lets you validate environment variables at build-time with ArkEnv.
import from "@arkenv/vite-plugin";
import { } from "vite";
export default ({
: [
({
: "number.port",
: "string",
}),
],
});With this setup, if any environment variable is missing or invalid, your dev server won't start and your production build will fail with an error:
ArkEnvError: Errors found while validating environment variables
VITE_MY_VAR must be a string (was missing)
PORT must be an integer between 0 and 65535 (was "hello")Using Standard Schema validators (Zod, Valibot)
This plugin uses ArkType for validation, which natively supports Standard Schema. You can freely mix ArkType DSL strings with Zod or Valibot validators in the same schema - no extra configuration needed.
import { defineConfig } from "vite";
import arkenv from "@arkenv/vite-plugin";
import { z } from "zod";
export default defineConfig({
plugins: [
arkenv({
VITE_API_URL: z.url(),
VITE_API_KEY: z.string().min(1),
VITE_DEBUG: "boolean",
}),
],
});Important
This plugin requires ArkType to be installed.
For a zero-ArkType setup, use arkenv/standard directly in your app code instead.
See Standard Schema validators for details.
Installation
npm install @arkenv/vite-pluginpnpm add @arkenv/vite-pluginyarn add @arkenv/vite-pluginbun add @arkenv/vite-pluginIf you intend to use arkenv (requires ArkType), also install arktype:
npm install arktypepnpm add arktypeyarn add arktypebun add arktypeFor some workflows (including using ArkEnv in Vite config and typing import.meta.env), a dedicated arkenv installation is needed. See ArkEnv quickstart for more instructions.