@qalisa/vike-envz
Version:
A type-safe environment variable management system for Vike applications that enables validation and transformation of environment variables using Zod schemas.
38 lines (37 loc) • 1.09 kB
TypeScript
/**
* @module plugin/index
* @description Vite plugin for vike-envz that injects environment variables into the Vite build process.
* This plugin makes environment variables available on the client-side through import.meta.env.
*/
import { type Plugin } from "vite";
import { type EnvZ } from "../types/public.js";
/**
* Creates a Vite plugin that injects environment variables into the build process.
*
* @param {Object} options - Plugin configuration options
* @param {EnvZ} options.envSchema - Schema definition for environment variables
* @returns {Plugin} A Vite plugin instance
*
* @example
* ```ts
* // vite.config.ts
* import { defineConfig } from 'vite';
* import envZ from 'vike-envz/plugin';
* import { z } from 'zod';
*
* export default defineConfig({
* plugins: [
* envZ({
* envSchema: {
* API_URL: [z.string().url()],
* DEBUG: [z.enum(['true', 'false']).transform(v => v === 'true')]
* }
* })
* ]
* });
* ```
*/
declare const envZ: ({ envSchema }: {
envSchema: EnvZ;
}) => Plugin;
export default envZ;