Vite Frontend Build Performance Optimization Skill
Optimize frontend build performance with Vite's lightning-fast HMR, code splitting, and tree-shaking. Modern build tooling that has replaced Webpack as the developer favorite.
Open the source and read safety notes before installing.
Prerequisites
- Node.js 18+ (20+ recommended)
- vite ^5.0.0
- npm/pnpm/yarn package manager
- Basic understanding of JavaScript modules
- Node.js 18+ runtime environment for running Vite build processes and development server
- Project source code with Vite configuration (vite.config.js/ts) for build optimization customization
Schema details
- Install type
- package
- Reading time
- 6 min
- Difficulty score
- 100
- Troubleshooting
- Yes
- Breaking changes
- No
- Download URL
- /downloads/skills/vite-build-optimization.zip
- Package verified
- Yes
- SHA-256
- 3bc2f1a78615abff0539bd4f50e36337af9c433c6b145a16b2720fa8f00c26b1
- Skill type
- general
- Skill level
- advanced
- Verification
- draft
- Verified at
- 2025-10-23
| Platform | Support | Install path |
|---|---|---|
| claude-code | Native | .claude/skills/<skill-name>/SKILL.md |
| codex | Native | .agents/skills/<skill-name>/SKILL.md |
| windsurf | Native | .windsurf/skills/<skill-name>/SKILL.md |
| gemini | Native | .gemini/skills/<skill-name>/SKILL.md or .agents/skills/<skill-name>/SKILL.md |
| cursor | Adapter | .cursor/rules/<skill-name>.mdc |
| cli | Manual | AGENTS.md or tool-specific context file |
Full copyable content
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import { visualizer } from 'rollup-plugin-visualizer';
export default defineConfig({
plugins: [
react(),
visualizer({ open: true, filename: 'dist/stats.html' }),
],
build: {
target: 'es2020',
sourcemap: 'hidden',
rollupOptions: {
output: {
manualChunks: (id) => {
if (id.includes('node_modules/react') || id.includes('node_modules/react-dom')) {
return 'vendor-react';
}
if (id.includes('node_modules/@mui') || id.includes('node_modules/@emotion')) {
return 'vendor-ui';
}
if (id.includes('node_modules/lodash') || id.includes('node_modules/date-fns')) {
return 'vendor-utils';
}
},
},
},
cssCodeSplit: true,
minify: 'terser',
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
},
optimizeDeps: {
include: ['react', 'react-dom'],
},
});About this resource
What This Skill Enables
Claude can optimize your Vite build configuration for production-ready performance with instant Hot Module Replacement (HMR), intelligent code splitting, and tree-shaking. Vite leverages native ES modules during development and Rollup for optimized production builds, delivering the fastest developer experience while generating highly optimized bundles. From configuring build options to debugging bundle size, Claude handles the complexity of modern frontend tooling.
Compatibility
Native
- Claude Code / Claude: native skill usage via
SKILL.md. - Codex/OpenAI workflows: compatible with Agent Skills-style
SKILL.mdcontent as reusable workflow instructions.
Manual Adaptation
- Gemini CLI: native skill usage via
.gemini/skills/<skill-name>/SKILL.mdor.agents/skills/<skill-name>/SKILL.mdwhere supported. - Cursor: use the generated
.cursor/rules/*.mdcadapter for project rules. - OpenClaw and similar agents: use the same skill content as a reusable prompt/workflow file when native skill import is unavailable.
Prerequisites
Required:
- Claude Pro subscription or Claude Code CLI
- Node.js 18+ (20+ recommended)
- npm, pnpm, or yarn package manager
- Basic understanding of JavaScript modules
What Claude handles automatically:
- Configuring vite.config.ts for optimal builds
- Setting up code splitting strategies
- Implementing lazy loading for routes/components
- Analyzing and optimizing bundle size
- Configuring CSS optimization and extraction
- Setting up environment variables
- Implementing caching strategies
- Configuring build targets for browser support
How to Use This Skill
Production Build Optimization
Prompt: "Optimize my Vite config for production with: code splitting by route, lazy loading for heavy components, CSS extraction, source maps, and tree-shaking. Target modern browsers (ES2020)."
Claude will:
- Configure build.rollupOptions for chunking
- Set up manual chunks for vendors
- Enable CSS code splitting
- Configure source map generation
- Set build.target for ES2020
- Add tree-shaking optimizations
- Configure minification settings
Bundle Size Analysis
Prompt: "My Vite bundle is 2MB. Help me analyze what's taking space and optimize. Use rollup-plugin-visualizer and suggest splitting strategies."
Claude will:
- Install and configure bundle analyzer
- Generate visual bundle report
- Identify large dependencies
- Suggest dynamic imports for heavy libs
- Configure vendor chunk splitting
- Recommend lighter alternatives
- Set up lazy loading for routes
Multi-Page Application Setup
Prompt: "Configure Vite for multi-page app with 3 entry points: landing page, dashboard, admin panel. Each should have separate bundles but share common dependencies."
Claude will:
- Set up build.rollupOptions.input
- Create separate HTML entry points
- Configure shared chunk extraction
- Set up independent CSS bundles
- Implement common vendor splitting
- Add entry-specific optimizations
- Configure dev server for multi-page
Plugin Configuration & Optimization
Prompt: "Set up Vite with React, TypeScript, PWA support, image optimization, and SVG imports. Optimize for fastest dev server startup and HMR."
Claude will:
- Install and configure @vitejs/plugin-react
- Add vite-plugin-pwa with precaching
- Set up vite-imagetools for optimization
- Configure vite-plugin-svgr
- Enable React Fast Refresh
- Optimize dependencies prebundling
- Configure HMR boundaries
Tips for Best Results
Use Manual Chunks Wisely: Split vendors by update frequency. React/Vue rarely change, but business logic does. Use
manualChunksto separate stable from volatile code.Lazy Load Heavy Libraries: Import chart libraries, rich editors, or large UI components dynamically only when needed. Vite handles code splitting automatically.
Optimize Dependencies: Use
optimizeDeps.includefor dependencies that slow down dev server startup. Pre-bundle CJS dependencies to ESM.Environment Variables: Use
import.meta.env(notprocess.env). Prefix withVITE_to expose to client code. Use.env.localfor secrets.Source Maps in Production: Use
hidden-source-mapfor error tracking without exposing code. Never useinline-source-mapin production.CSS Optimization: Enable
build.cssCodeSplitfor route-based CSS. Use PostCSS for autoprefixer and minification.
Common Workflows
Large React App Optimization
"Optimize Vite build for React app with 50+ routes:
1. Implement route-based code splitting with React.lazy()
2. Split vendor chunks: react/react-dom, UI library, utilities
3. Configure dynamic imports for modals, charts, editors
4. Add preload hints for critical chunks
5. Enable CSS code splitting per route
6. Configure build.rollupOptions for optimal chunking
7. Add bundle analyzer and aim for <200KB initial load
8. Set up Lighthouse CI to track performance"
Monorepo Build Configuration
"Configure Vite in Turborepo monorepo:
1. Shared vite.config.base.ts for common config
2. App-specific configs extending base
3. Shared component library with optimized exports
4. Configure path aliases for @workspace packages
5. Set up cache strategy for unchanged packages
6. Optimize prebundling for internal dependencies
7. Configure dev server proxy for backend services
8. Add workspace-aware HMR"
Progressive Web App Build
"Set up Vite PWA with offline support:
1. Install vite-plugin-pwa with Workbox
2. Configure service worker precaching strategy
3. Add runtime caching for API calls
4. Set up offline fallback page
5. Generate web manifest with icons
6. Configure update notification for new versions
7. Optimize caching based on file types
8. Add service worker update lifecycle"
Library Build Configuration
"Configure Vite for component library build:
1. Set build.lib mode with entry point
2. Configure external dependencies (React, Vue)
3. Generate ESM and UMD bundles
4. Add TypeScript declaration generation
5. Set up CSS extraction and modules
6. Configure tree-shaking for optimal imports
7. Add source maps for debugging
8. Set up package.json exports field"
Troubleshooting
Issue: "Dev server slow to start with large dependencies"
Solution: Add slow dependencies to optimizeDeps.include array. Use server.warmup to prebundle commonly used files. Check for circular dependencies. Consider using optimizeDeps.esbuildOptions.target to skip unnecessary transforms.
Issue: "HMR not working for certain components"
Solution: Check component exports are named (not default). Ensure no side effects in module scope. Add HMR boundaries with import.meta.hot.accept(). Verify vite-plugin-react is installed for React Fast Refresh.
Issue: "Production bundle size larger than expected"
Solution: Run bundle analyzer to identify heavy dependencies. Check for duplicate dependencies in node_modules. Use dynamic imports for heavy libs. Verify tree-shaking with build.rollupOptions.treeshake. Check for unintentional global imports.
Issue: "Environment variables not accessible in client"
Solution: Prefix variables with VITE_ in .env file. Use import.meta.env.VITE_VAR_NAME not process.env. Check .env file is in project root. Restart dev server after adding new env vars.
Issue: "Build fails with 'Cannot find module' errors" Solution: Check path aliases in vite.config.ts match tsconfig.json. Verify resolve.alias configuration. Ensure all imports use correct file extensions. Check for case-sensitive file naming issues.
Learn More
- Vite Official Documentation
- Vite GitHub Repository
- Rollup Plugin Documentation
- Vite Plugin Collection
- ViteConf 2024 Talks
- Vite Performance Guide
Features
- Instant Hot Module Replacement (HMR) with native ESM for sub-second updates during development
- Rollup-powered production builds with advanced tree-shaking and dead code elimination
- Intelligent code splitting with manual chunks, dynamic imports, and route-based splitting
- Plugin ecosystem for React, Vue, Svelte, TypeScript, PWA, and more with Fast Refresh support
- Zero-config CSS code splitting and optimization with PostCSS integration
- Dependency pre-bundling with esbuild for faster dev server startup
- Multi-page application support with separate entry points and shared chunks
- Library mode with ESM and UMD output formats for component library distribution
Use Cases
- Optimizing large React/Vue apps with 50+ routes using route-based code splitting
- Building component libraries with ESM/UMD output formats and TypeScript declarations
- Configuring PWAs with offline support using vite-plugin-pwa and Workbox
- Multi-page application setup with separate bundles and shared dependencies
- Monorepo build configuration with shared configs and workspace-aware HMR
- Production bundle optimization with bundle analysis and size reduction strategies
- What This Skill Enables
- Compatibility
- Native
- Manual Adaptation
- Prerequisites
- How to Use This Skill
- Production Build Optimization
- Bundle Size Analysis
- Multi-Page Application Setup
- Plugin Configuration & Optimization
- Tips for Best Results
- Common Workflows
- Large React App Optimization
- Monorepo Build Configuration
- Progressive Web App Build
- Library Build Configuration
Source citations
Signals
Loading live community signals…
A short, calm digest of reviewed Claude resources. Unsubscribe any time.