| name | analyze-bundle |
| description | Use this skill when the user asks to analyze the bundle size, find large dependencies, optimize the build output, check what's included in the bundle, or reduce the app size. Trigger phrases: "analyze bundle", "bundle size", "large bundle", "reduce bundle size". |
Analyze Bundle
Analyzes the production bundle to identify size issues and optimization opportunities.
Generate Bundle Report
ANALYZE=true npm run build:vite
This generates _stats.html in the project root (via rollup-plugin-visualizer). Open it in a browser to see an interactive treemap of the bundle.
Alternatively, build and open directly:
npm run build:vite && xdg-open _stats.html
npm run build:vite && open _stats.html
Reading the Visualizer
- Large boxes = large chunks — investigate these first
- node_modules boxes = third-party dependencies
- src/ boxes = your application code
Common Issues and Fixes
Large third-party libraries
Check if the library supports tree-shaking. Import only what you need:
import _ from "lodash";
import debounce from "lodash/debounce";
Routes not code-split
TanStack Router automatically code-splits routes. Verify your route components are not imported statically elsewhere.
Icons imported wholesale
Lucide React supports tree-shaking — import individual icons:
import { Home, User, Settings } from "lucide-react";
Large assets in JS bundle
Images and fonts should be in public/ or src/assets/, not imported into JS as data URLs.
Lazy Loading Routes
For pages with heavy dependencies, ensure they're loaded lazily. TanStack Router does this automatically via file-based routing — each route is a separate chunk.
Bundle Size Budget
General targets for a modern SPA:
- Initial JS (gzipped): < 200KB
- Per-route chunk: < 100KB
- Total assets: < 2MB
Optimization Checklist