.claude/skills/vite/vite-core/vite-core-architecture/SKILL.md
Use when creating a new Vite project, understanding Vite internals, or reasoning about dev vs production behavior. Prevents confusing Vite's native ESM dev server with traditional bundler-based dev servers and misunderstanding the two-mode architecture. Covers dev server vs build pipeline, native ESM serving, dependency pre-bundling, module graph, internal tools evolution (esbuild to Oxc, Rollup to Rolldown), index.html as entry point, browser support targets, and Node.js requirements. Keywords: vite, architecture, dev server, build, ESM, Rolldown, Oxc, pre-bundling, module graph.
npx skillsauth add OpenAEC-Foundation/OpenAEC-Workspace-Composer vite-core-architectureInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Vite operates as two completely different systems depending on context:
| Aspect | Dev Server (vite) | Production Build (vite build) |
|--------|--------------------|---------------------------------|
| Strategy | Native ESM, no bundling | Full bundle via Rolldown/Rollup |
| Module delivery | Individual files over HTTP | Optimized chunks |
| Transform tool (v8) | Oxc | Oxc |
| Transform tool (v5-7) | esbuild | esbuild |
| Bundler (v8) | None (native ESM) | Rolldown |
| Bundler (v5-7) | None (native ESM) | Rollup |
| Speed priority | Instant startup + HMR | Optimized output size |
| Browser target | esnext | baseline-widely-available |
| Version | Dev Transform | Dev Pre-bundling | Production Bundler | CSS Minification | JS Minifier | |---------|--------------|------------------|--------------------|------------------|-------------| | Vite 5 | esbuild | esbuild | Rollup | esbuild | esbuild | | Vite 6 | esbuild | esbuild | Rollup | esbuild/lightningcss | esbuild | | Vite 7 | esbuild | esbuild | Rollup | esbuild/lightningcss | esbuild | | Vite 8 | Oxc | Rolldown | Rolldown | Lightning CSS | Oxc (30-90x faster than Terser) |
| Vite Version | Minimum Node.js | |-------------|----------------| | v5, v6 | 18+ | | v7+ | 20.19+ or 22.12+ |
| Context | Target | Meaning |
|---------|--------|---------|
| Dev server | esnext | Latest JavaScript/CSS features, no transpilation |
| Production (v8 default) | baseline-widely-available | Chrome 111, Edge 111, Firefox 114, Safari 16.4 |
| Production (v7 default) | baseline-widely-available | Chrome 107, Edge 107, Firefox 104, Safari 16.0 |
| Legacy browsers | @vitejs/plugin-legacy | Generates polyfilled fallback bundles |
NEVER set envPrefix to '' -- this exposes ALL environment variables (including secrets like DB_PASSWORD) to client-side code.
NEVER exclude CommonJS dependencies from pre-bundling via optimizeDeps.exclude -- they MUST be pre-bundled to be converted to ESM for the dev server.
NEVER edit files in node_modules/.vite/ -- this is the pre-bundling cache directory. Use optimizeDeps.force: true or --force CLI flag to rebuild it.
NEVER use a JavaScript file as the application entry point -- Vite uses index.html as the entry point. The HTML file references your scripts via <script type="module" src="...">.
ALWAYS use defineConfig() wrapper for vite.config.ts -- this provides TypeScript IntelliSense and type checking for all configuration options.
ALWAYS run tsc --noEmit separately for type checking -- Vite performs transpile-only (no type checking) for speed. NEVER rely on Vite for TypeScript type safety.
The dev server serves source files as native ES modules over HTTP:
index.html from http://localhost:5173/<script type="module" src="/src/main.ts">/src/main.ts, Vite transforms it on-the-fly (TypeScript, JSX, etc.)import statements and requests each dependencynode_modules imports and serves pre-bundled versionsNo bundling step occurs. Each source file is an individual HTTP request. HMR updates propagate through the module graph -- only changed modules are replaced.
Pre-bundling runs automatically on first vite startup for two reasons:
lodash-es (600+ modules) are consolidated into a single requestPre-bundling results are cached in node_modules/.vite. Cache invalidates when: lockfile changes, vite.config changes, NODE_ENV changes, or patches folder changes.
vite build bundles the entire application:
index.html entry pointsdist/Unlike Webpack or other bundlers, Vite treats index.html as the entry point:
<root>/index.html → http://localhost:5173/
<root>/about.html → http://localhost:5173/about.html
<root>/nested/page.html → http://localhost:5173/nested/page.html
Vite resolves <script type="module" src="..."> tags and inline <script type="module"> blocks, processing all referenced modules and CSS.
Creating new project with create-vite?
├── React app?
│ ├── Want Babel plugins? → react-ts (uses @vitejs/plugin-react with Babel)
│ └── Want fastest transforms? → react-swc-ts (uses @vitejs/plugin-react-swc)
├── Vue app? → vue-ts (uses @vitejs/plugin-vue)
├── Svelte app? → svelte-ts
├── Solid app? → solid-ts
├── Preact app? → preact-ts
├── Lit web components? → lit-ts
├── Qwik app? → qwik-ts
└── No framework? → vanilla-ts
ALWAYS use the -ts variant -- TypeScript variants include proper type definitions and vite-env.d.ts.
What browsers must you support?
├── Modern only (Chrome 111+, Safari 16.4+) → Default (baseline-widely-available)
├── Slightly older (ES2020, etc.) → Set build.target: 'es2020'
├── IE11 / very old browsers → Add @vitejs/plugin-legacy
└── Server-side / Node.js → Set build.target: 'node20'
| Plugin | Purpose | When to Use |
|--------|---------|-------------|
| @vitejs/plugin-react | React with Babel | ALWAYS for React unless SWC preferred |
| @vitejs/plugin-react-swc | React with SWC | Faster builds, fewer Babel plugin needs |
| @vitejs/plugin-vue | Vue 3 SFC support | ALWAYS for Vue projects |
| @vitejs/plugin-vue-jsx | Vue JSX/TSX | When using JSX syntax in Vue |
| @vitejs/plugin-rsc | React Server Components | RSC architecture |
| @vitejs/plugin-legacy | Legacy browser support | When targeting pre-ES2015 browsers |
| Command | Purpose | Default Port |
|---------|---------|-------------|
| vite | Start dev server with HMR | 5173 |
| vite build | Bundle for production | N/A |
| vite preview | Preview production build locally | 4173 |
Key flags: --port <number>, --open, --mode <mode>, --force (re-bundle deps), --host (expose to LAN).
{
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
}
}
my-vite-app/
├── index.html # Application entry point (NOT in src/)
├── public/ # Static assets (copied as-is, no processing)
│ └── favicon.ico
├── src/
│ ├── main.ts # Module entry (referenced from index.html)
│ ├── App.tsx # Root component (framework-dependent)
│ ├── vite-env.d.ts # Vite client type declarations
│ └── assets/ # Processed assets (images, fonts, etc.)
├── vite.config.ts # Vite configuration
├── tsconfig.json # TypeScript configuration
├── package.json # Dependencies and scripts
└── node_modules/
└── .vite/ # Pre-bundling cache (auto-generated)
ALWAYS place index.html at the project root (not inside src/) -- Vite expects it at the root directory.
development
Use when integrating Vite with a backend framework, rendering Vite assets from server-side templates, or setting up dev/production HTML serving. Prevents incorrect manifest.json traversal and missing CSS chunk resolution in production. Covers build.manifest configuration, .vite/manifest.json structure, ManifestChunk properties, dev mode HTML setup, production rendering, CSS/JS chunk resolution, and modulepreload polyfill. Keywords: backend integration, manifest.json, ManifestChunk, Django, Laravel, Rails, modulepreload.
development
Use when encountering dev server startup failures, HMR issues, proxy errors, CORS blocks, or module not found errors during development. Prevents misconfiguring server.hmr behind reverse proxies and forgetting appType: 'custom' in middleware mode. Covers HMR full-reload debugging, proxy configuration, CORS setup, HTTPS certificates, server.fs.strict violations, port conflicts, WebSocket failures, file watcher issues, and middleware mode. Keywords: dev server, HMR, proxy, CORS, HTTPS, WebSocket, port conflict, server.fs.strict, middleware mode, file watcher.
development
Use when encountering pre-bundling errors, dependency resolution failures, stale cache issues, or slow development server startup. Prevents excluding CJS dependencies from pre-bundling (which breaks runtime module resolution) and misconfiguring optimizeDeps. Covers CJS/ESM conversion failures, missing dependency auto-discovery, optimizeDeps configuration, monorepo linked dependencies, cache invalidation, browser cache staleness, and large dependency tree performance. Keywords: pre-bundling, optimizeDeps, CJS, ESM, cache, dependency resolution, monorepo, node_modules/.vite.
development
Use when encountering Vite build failures, chunk size warnings, or version-specific build errors. Prevents the common mistake of using deprecated rollupOptions in v8 or misconfiguring build targets and minifiers. Covers Rolldown/Rollup bundling failures, CSS minification errors, sourcemap problems, library mode build failures, BundleError handling, and asset processing errors. Keywords: build error, Rolldown, chunk size, sourcemap, library mode, minify, BundleError, rollupOptions, build.target.