{"id":48355132,"url":"https://github.com/pyyupsk/vite-env","last_synced_at":"2026-04-05T11:01:26.511Z","repository":{"id":349307463,"uuid":"1201752612","full_name":"pyyupsk/vite-env","owner":"pyyupsk","description":"The env.ts layer for Vite — define once, validate everywhere, import with types.","archived":false,"fork":false,"pushed_at":"2026-04-05T09:20:10.000Z","size":253,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-04-05T10:13:34.534Z","etag":null,"topics":["developer-tools","env","environment-variables","rolldown","typescript","validation","vite","vite-plugin","zod"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pyyupsk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2026-04-05T05:26:55.000Z","updated_at":"2026-04-05T09:20:11.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/pyyupsk/vite-env","commit_stats":null,"previous_names":["pyyupsk/vite-env"],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/pyyupsk/vite-env","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyyupsk%2Fvite-env","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyyupsk%2Fvite-env/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyyupsk%2Fvite-env/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyyupsk%2Fvite-env/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pyyupsk","download_url":"https://codeload.github.com/pyyupsk/vite-env/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pyyupsk%2Fvite-env/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31433044,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-05T08:13:15.228Z","status":"ssl_error","status_checked_at":"2026-04-05T08:13:11.839Z","response_time":75,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["developer-tools","env","environment-variables","rolldown","typescript","validation","vite","vite-plugin","zod"],"created_at":"2026-04-05T11:01:25.575Z","updated_at":"2026-04-05T11:01:26.506Z","avatar_url":"https://github.com/pyyupsk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# vite-env\n\nThe `env.ts` layer for Vite — define once, validate everywhere, import with types.\n\nWhat [`@t3-oss/env`](https://github.com/t3-oss/t3-env) is for Next.js, but built natively on Vite 8 / Rolldown with zero boilerplate.\n\n## Features\n\n- **Typed virtual modules** — `import { env } from 'virtual:env/client'` with full IntelliSense\n- **Server/client split** — server secrets never reach the browser bundle\n- **Build-time leak detection** — fails the build if server values appear in client chunks\n- **Auto-coercion** — `z.stringbool()`, `z.coerce.number()` just work\n- **Auto `.d.ts` generation** — no more manual `vite-env.d.ts` maintenance\n- **Auto `.env.example`** — `npx vite-env generate` from your schema\n- **Zod v4 native** — first-class support for the latest Zod\n- **Vite 8 / Rolldown native** — `moduleType: 'js'` on virtual modules, sequential hooks\n\n## Install\n\n```bash\npnpm add @vite-env/core zod\npnpm add -D @vite-env/cli # optional — for check/generate/types commands\n```\n\n## Usage\n\n### 1. Define your schema — `env.ts`\n\n```ts\nimport { defineEnv, z } from '@vite-env/core'\n\nexport default defineEnv({\n  server: {\n    DATABASE_URL: z.url(),\n    JWT_SECRET: z.string().min(32),\n    DB_POOL_SIZE: z.coerce.number().int().min(1).max(100).default(10),\n    REDIS_URL: z.url().optional(),\n  },\n  client: {\n    VITE_API_URL: z.url(),\n    VITE_APP_NAME: z.string().min(1),\n    VITE_DARK_MODE: z.stringbool().default(false),\n    VITE_LOG_LEVEL: z.enum(['debug', 'info', 'warn', 'error']).default('info'),\n    VITE_NODE_ENV: z.enum(['development', 'test', 'production']).default('development'),\n  },\n})\n```\n\n### 2. Add the plugin — `vite.config.ts`\n\n```ts\nimport ViteEnv from '@vite-env/core/plugin'\nimport { defineConfig } from 'vite'\n\nexport default defineConfig({\n  plugins: [ViteEnv()],\n})\n```\n\n### 3. Use typed env in your app\n\n```ts\n// Client code — only client vars available\nimport { env } from 'virtual:env/client' // 'development' | 'test' | 'production'\n\n// Server/SSR code — all vars available\nimport { env } from 'virtual:env/server'\n\nenv.VITE_API_URL // string\nenv.VITE_DARK_MODE // boolean (not \"true\")\nenv.VITE_NODE_ENV\n\nenv.DATABASE_URL // string\nenv.JWT_SECRET // string\nenv.VITE_API_URL // string (client vars also available server-side)\n```\n\n## How it works\n\n| Section  | Available in `virtual:env/client` | Available in `virtual:env/server` |\n| -------- | :-------------------------------: | :-------------------------------: |\n| `client` |                Yes                |                Yes                |\n| `server` |                No                 |                Yes                |\n\n- **Validation** runs on `buildStart` (fatal) and on `.env` file changes during dev (non-fatal warning)\n- **Leak detection** scans client chunks at `generateBundle` for literal server variable values\n- **`VITE_` prefix** is enforced at `defineEnv()` call time for all `client` keys\n- **`process.env` wins** over `.env` files (CI secrets take precedence)\n\n## CLI\n\n```bash\n# Validate env without starting dev server\nnpx vite-env check\n\n# Generate .env.example from schema\nnpx vite-env generate\n\n# Regenerate vite-env.d.ts\nnpx vite-env types\n```\n\n## Plugin Options\n\n```ts\nViteEnv({\n  configFile: './env.ts', // default — path to env definition file\n})\n```\n\n## Packages\n\n| Package                             | Description                                 |\n| ----------------------------------- | ------------------------------------------- |\n| [`@vite-env/core`](./packages/core) | Vite plugin + `defineEnv()` + Zod re-export |\n| [`@vite-env/cli`](./packages/cli)   | CLI commands: `check`, `generate`, `types`  |\n\n## Requirements\n\n- Node.js \u003e= 20.19.0\n- Vite \u003e= 8.0.0\n- Zod \u003e= 4.0.0\n\n## License\n\n[MIT](./LICENSE)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyyupsk%2Fvite-env","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpyyupsk%2Fvite-env","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpyyupsk%2Fvite-env/lists"}