ViteHub

Env

Declare build-time and runtime environment variables with typed access for Vite and Nitro.

@vitehub/env gives Vite and Nitro apps one place to declare environment variables, defaults, sources, and secret boundaries.

Use Env when configuration needs to be explicit and typed instead of scattered across process.env, import.meta.env, and provider dashboards.

import { env, envVite } from '@vitehub/env/vite'
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [envVite({ prefix: 'VITEHUB_' })],
  env: {
    define: {
      __APP_VERSION__: env({
        mode: 'build',
        source: env.packageJson('version'),
      }),
    },
    public: {
      appName: env({
        default: 'ViteHub Env',
        mode: 'build',
      }),
    },
  },
})

What Env solves

Environment values have different safety rules depending on when and where they are exposed.

Secret boundaries

Mark runtime values as secret so diagnostics mask them and Cloudflare required secrets are generated.

Public Env

Expose browser-safe values through #vitehub/env/public.

Server Env

Resolve Nitro server values through #vitehub/env/server.

Validation

Validate declarations with string defaults, zod-like schemas, or Standard Schema-compatible validators.

Two configuration paths

Vite handles build-time values. Use env.public for values read from #vitehub/env/public, and env.define for compile-time replacements.

Source model

Each env() declaration can read from:

  • an inferred environment variable name
  • an explicit environment variable through env.source(name)
  • package.json through env.packageJson(path)
  • git branch or commit metadata
  • a custom build-only resolver

Runtime declarations must be serializable. Custom sources and custom runtime schemas are build-only.

Start here

Start with Quickstart for a Vite public build value and a Nitro runtime secret. Use Usage when you need prefixes, nested config, custom sources, or diagnostics.

Next steps

Quickstart
Configure build and runtime env declarations and verify both outputs.
Usage
Use defaults, optional variables, sources, schemas, diagnostics, and secret config.
Runtime API
Review exports, declaration shapes, generated import paths, and runtime helpers.
Troubleshooting
Fix missing values, invalid schemas, async validation, and generated type issues.
Copyright © 2026