affaan-m/everything-claude-code/vite-patterns
- community
- ext:[{"type":"plugin","description":"Custom plugin integration"}]
Checking that the SKILL.md file is still in the repository.
Vite build tool patterns including config, plugins, HMR, env variables, proxy setup, SSR, library mode, dependency pre-bundling, and build optimization. Activate when working with vite.config.ts, Vite plugins, or Vite-based projects.
Install
npx vskill@latest install affaan-m/everything-claude-code/vite-patternsSemi-extensibleMentions customization, but needs skill-specific knowledge. Read the extensible skills standard
SKILL.md
Vite Patterns
Build tool and dev server patterns for Vite 8+ projects. Covers configuration, environment variables, proxy setup, library mode, dependency pre-bundling, and common production pitfalls.
When to Use
- Configuring
vite.config.tsorvite.config.js - Setting up environment variables or
.envfiles - Configuring dev server proxy for API backends
- Optimizing build output (chunks, minification, assets)
- Publishing libraries with
build.lib - Troubleshooting dependency pre-bundling or CJS/ESM interop
- Debugging HMR, dev server, or build errors
- Choosing or ordering Vite plugins
How It Works
- Dev mode serves source files as native ESM — no bundling. Transforms happen on-demand per module request, which is why cold starts are fast and HMR is precise.
- Build mode uses Rolldown (v7+) or Rollup (v5–v6) to bundle the app for production with tree-shaking, code-splitting, and Oxc-based minification.
- Dependency pre-bundling converts CJS/UMD deps to ESM once via esbuild and caches the result under
node_modules/.vite, so subsequent starts skip the work. - Plugins share a unified interface across dev and build — the same plugin object works for both the dev server's on-demand transforms and the production pipeline.
- Environment variables are statically inlined at build time.
VITE_-prefixed vars become public constants in the bundle; everything unprefixed is invisible to client code.
Examples
Config Structure
Basic Config
Conditional Config
Key Config Options
| Key | Default | Description | |
|---|---|---|---|
root | '.' | Project root (where index.html lives) | |
base | '/' | Public base path for deployed assets | |
envPrefix | 'VITE_' | Prefix for client-exposed env vars | |
build.outDir | 'dist' | Output directory | |
build.minify | 'oxc' | Minifier ('oxc', 'terser', or false) | |
build.sourcemap | false | true, 'inline', or 'hidden' |
Plugins
Essential Plugins
Most plugin needs are covered by a handful of well-maintained packages. Reach for these before writing your own.
| Plugin | Purpose | When to use | |
|---|---|---|---|
@vitejs/plugin-react-swc | React HMR + Fast Refresh via SWC | Default for React apps (faster than Babel variant) | |
@vitejs/plugin-react | React HMR + Fast Refresh via Babel | Only if you need Babel plugins (emotion, MobX decorators) | |
@vitejs/plugin-vue | Vue 3 SFC support | Vue apps | |
vite-plugin-checker | Runs tsc + ESLint in worker thread with HMR overlay | Any TypeScript app — Vite does NOT type-check during vite build | |
vite-tsconfig-paths | Honors tsconfig.json paths aliases | Any time you already have aliases in tsconfig.json | |
vite-plugin-dts | Emits .d.ts files in library mode | Publishing TypeScript libraries | |
vite-plugin-svgr | Imports SVGs as React components | React apps using SVGs as components | |
rollup-plugin-visualizer | Bundle treemap/sunburst report | Periodic bundle size audits (use enforce: 'post') | |
vite-plugin-pwa | Zero-config PWA + Workbox | Offline-capable apps |
Critical callout: vite build transpiles but does NOT type-check. Type errors silently ship to production unless you add vite-plugin-checker or run tsc --noEmit in CI.
Authoring Custom Plugins
Authoring is rare — most needs are covered by existing plugins. When you do need one, start inline in vite.config.ts and only extract if reused.
Key hooks: transform (modify source), resolveId + load (virtual modules), transformIndexHtml (inject into HTML), configureServer (add dev middleware), hotUpdate (custom HMR — replaces deprecated handleHotUpdate in v7+).
Virtual modules use the \0 prefix convention — resolveId returns '\0virtual:my-id' so other plugins skip it. User code imports 'virtual:my-id'.
For full plugin API, see vite.dev/guide/api-plugin. Use vite-plugin-inspect during development to debug the transform pipeline.
HMR API
Framework plugins (@vitejs/plugin-react, @vitejs/plugin-vue, etc.) handle HMR automatically. Reach for import.meta.hot directly only when building custom state stores, dev tools, or framework-agnostic utilities that need to persist state across updates.
All import.meta.hot code is tree-shaken out of production builds — no guard removal needed.
Environment Variables
Vite loads .env, .env.local, .env.[mode], and .env.[mode].local in that order (later overrides earlier); *.local files are gitignored and meant for local secrets.
Client-Side Access
Only VITE_-prefixed vars are exposed to client code:
Using Env in Config
Security
VITE_ Prefix is NOT a Security Boundary
Any variable prefixed with VITE_ is statically inlined into the client bundle at build time. Minification, base64 encoding, and disabling source maps do NOT hide it. A determined attacker can extract any VITE_ var from the shipped JavaScript.
Rule: Only public values (API URLs, feature flags, public keys) go in VITE_ vars. Secrets (API tokens, database URLs, private keys) MUST live server-side behind an API or serverless function.
The loadEnv('') Trap
Source Maps in Production
Production source maps leak your original source code. Disable them unless you upload to an error tracker (Sentry, Bugsnag) and delete locally afterward:
.gitignore Checklist
.env.local,.env.*.local— local secret overridesdist/— build outputnode_modules/.vite— pre-bundle cache (stale entries cause phantom errors)
Server Proxy
For WebSocket proxying, add ws: true to the route config.
Build Optimization
Manual Chunks
Performance
Avoid Barrel Files
Barrel files (index.ts re-exporting everything from a directory) force Vite to load every re-exported file even when you import a single symbol. This is the #1 dev-server slowdown flagged by the official docs.
Be Explicit with Import Extensions
Each implicit extension forces up to 6 filesystem checks via resolve.extensions. In large codebases, this adds up.
Narrow tsconfig.json allowImportingTsExtensions + resolve.extensions to only the extensions you actually use.
Warm-Up Hot-Path Routes
server.warmup.clientFiles pre-transforms known hot entries before the browser requests them — eliminating the cold-load request waterfall on large apps.
Profiling Slow Dev Servers
When vite dev feels slow, start with vite --profile, interact with the app, then press p+enter to save a .cpuprofile. Load it in Speedscope to find which plugins are eating time — usually buildStart, config, or configResolved hooks in community plugins.
Library Mode
When publishing an npm package, use build.lib. Two footguns matter more than config detail:
- Types are not emitted — add
vite-plugin-dtsor runtsc --emitDeclarationOnlyseparately. - Peer dependencies MUST be externalized — unlisted peers get bundled into your library, causing duplicate-runtime errors in consumers.
SSR Externals
Bare createServer({ middlewareMode: true }) setups are framework-author territory. Most apps should use Nuxt, Remix, SvelteKit, Astro, or TanStack Start instead. What you will tweak as a framework user is the externals config when deps break in SSR:
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 95 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/vite-patterns/SKILL.md
Popularity
- Repository stars
- 183,809
- Repository forks
- 28,361
- Repository npm downloads, 7 days
- 1,807
- 7-day trend score
- 78
Stars and forks are for the whole GitHub repository, not this skill alone. Downloads are for the repository's npm package. Refreshed 16 May 2026, 5 months ago.
Extension points
pluginCustom plugin integration
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/affaan-m/everything-claude-code/vite-patterns)