--- name: vite description: "Vite build tool configuration, plugin API, SSR, environment variables, Environment API, and Vite 8 Rolldown migration. Use when working with Vite projects, vite.config.ts, Vite plugins, env exposure, or building libraries/SSR apps with Vite." --- # Vite Based on current Vite 8 docs. Prefer retrieving `https://vite.dev/` for config, env, plugin, and migration details when exact behavior matters. Vite is a next-generation frontend build tool with fast dev server (native ESM + HMR) and optimized production builds. ## Preferences - Use TypeScript: prefer `vite.config.ts` - Always use ESM, avoid CommonJS - Never read or print `.env*` files or actual env values; that rule has no exception. Only edit or create `.env*` files when the user explicitly asks to add or append exact env vars, using user-provided values or clearly fake placeholders without inspecting existing values. Mechanical worktree env-file copies follow the global Git worktree rule and still must not inspect values. - Treat `VITE_` variables as public client bundle data; never put secrets behind that prefix. - Convert `import.meta.env` values from strings before numeric/boolean use. - Bun loads env files into `process.env` before scripts run; account for that when debugging Vite env precedence. ## Core | Topic | Description | Reference | |-------|-------------|-----------| | Configuration | `vite.config.ts`, `defineConfig`, conditional configs, `loadEnv` | [core-config](references/core-config.md) | | Features | `import.meta.glob`, asset queries (`?raw`, `?url`), `import.meta.env`, HMR API | [core-features](references/core-features.md) | | Plugin API | Vite-specific hooks, virtual modules, plugin ordering | [core-plugin-api](references/core-plugin-api.md) | ## Build & SSR | Topic | Description | Reference | |-------|-------------|-----------| | Build & SSR | Library mode, SSR middleware mode, `ssrLoadModule`, JavaScript API | [build-and-ssr](references/build-and-ssr.md) | ## Advanced | Topic | Description | Reference | |-------|-------------|-----------| | Environment API | Vite 6+ multi-environment support, custom runtimes | [environment-api](references/environment-api.md) | | Rolldown Migration | Vite 8 changes: Rolldown bundler, Oxc transformer, config migration | [rolldown-migration](references/rolldown-migration.md) | ## Quick Reference ### CLI Commands ```bash vite # Start dev server vite build # Production build vite preview # Preview production build vite build --ssr # SSR build ``` ### Common Config ```ts import { defineConfig } from 'vite' export default defineConfig({ plugins: [], resolve: { alias: { '@': '/src' } }, server: { port: 3000, proxy: { '/api': 'http://localhost:8080' } }, build: { target: 'esnext', outDir: 'dist' }, }) ``` ### Official Plugins - `@vitejs/plugin-vue` - Vue 3 SFC support - `@vitejs/plugin-vue-jsx` - Vue 3 JSX - `@vitejs/plugin-react` - React with Oxc/Babel - `@vitejs/plugin-react-swc` - React with SWC