ArkEnv

Introduction

Link to section: what-is-thisWhat is this?

The ArkEnv plugin for Vite lets you validate environment variables at build-time with ArkEnv.

vite.config.ts
import arkenv from "@arkenv/vite-plugin";
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [
    arkenv({
      PORT: "number.port",
      VITE_MY_VAR: "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:

Terminal
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")

Link to section: installationInstallation

npm install @arkenv/vite-plugin arktype

For 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.