
React Vite Best Practices
Ship a faster React + Vite production bundle with deliberate chunking, dev-server tuning, and measurable bundle hygiene.
Overview
React + Vite Best Practices is an agent skill for the Build phase that applies 23 prioritized Vite and React performance rules across six categories for production bundles and dev-server speed.
Install
npx skills add https://github.com/asyrafhussin/agent-skills --skill react-vite-best-practicesWhat is this skill?
- 23 performance rules organized across 6 categories with CRITICAL-to-HIGH impact labels
- Build optimization: manual chunks, OXC/Terser minification, modern targets, hashing, gzip/Brotli
- Code splitting via React.lazy(), Suspense boundaries, dynamic imports, and prefetch hints
- Development: optimizeDeps pre-bundling and Fast Refresh patterns for reliable HMR
- Asset handling, env configuration, and bundle analysis sections in the v2.0 reference
- 23 rules across 6 categories
- 6 sections: build, split, dev, assets, env, and bundle analysis
- Version 2.0.0 reference dated March 2026
Adoption & trust: 1.5k installs on skills.sh; 42 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
Your React + Vite app works locally but ships bloated chunks, slow HMR, or weak production scores because optimization was left as defaults.
Who is it for?
Solo developers on Vite 5+ React SPAs or dashboards who want a structured perf pass before Ship.
Skip if: Next.js or Remix apps, native mobile React Native stacks, or backends where Vite is not the frontend bundler.
When should I use this skill?
Scaffolding or hardening a React + Vite app for production bundle size, code splitting, or dev HMR reliability.
What do I get? / Deliverables
Your agent audits vite.config, routes, and imports against 23 rules so chunks, assets, and dev pre-bundling match production and navigation patterns.
- vite.config adjustments for chunks, targets, and compression
- Route and component lazy-loading plan with Suspense boundaries
- Documented fixes from bundle analysis and optimizeDeps tuning
Recommended Skills
Journey fit
Performance and Vite configuration work happens while you are actively building the client application. Rules target Vite, React.lazy, Suspense, and static assets—core frontend build concerns, not API or infra provisioning.
How it compares
Rule-based Vite+React performance catalog—broader than a single-purpose lazy-loading snippet, narrower than full design-system documentation.
Common Questions / FAQ
Who is react-vite-best-practices for?
Indie frontend builders using React with Vite who want an agent to enforce bundler-aware performance rules instead of ad-hoc Stack Overflow tweaks.
When should I use react-vite-best-practices?
In Build while configuring vite.config, adding routes with React.lazy, or preparing a production release; optionally in Ship perf subphase before launch checks.
Is react-vite-best-practices safe to install?
It is reference documentation without prescribed shell scripts—verify the Security Audits panel on this Prism page for the agent-skills package source.
SKILL.md
READMESKILL.md - React Vite Best Practices
# React + Vite Best Practices - Complete Reference **Version:** 2.0.0 **Framework:** React + Vite **Date:** March 2026 **License:** MIT ## Abstract Performance optimization guide for React applications built with Vite. Contains 23 rules across 6 categories covering build optimization, code splitting, development performance, asset handling, environment configuration, and bundle analysis. ## References - [Vite Documentation](https://vite.dev) - [React Documentation](https://react.dev) - [Rollup Documentation](https://rollupjs.org) --- # Sections This file defines all sections, their ordering, impact levels, and descriptions. The section ID (in parentheses) is the filename prefix used to group rules. --- ## 1. Build Optimization (build) **Impact:** CRITICAL **Description:** Vite build configuration for production. Manual chunk splitting, minification (OXC default, Terser for max compression), modern browser targets, sourcemap configuration, tree shaking, gzip/Brotli compression, and content-based asset hashing. ## 2. Code Splitting (split) **Impact:** CRITICAL **Description:** Route-based and component-level code splitting with React.lazy() and Suspense. Dynamic imports for heavy libraries, strategic Suspense boundary placement, and prefetch hints for anticipated navigation. ## 3. Development (dev) **Impact:** HIGH **Description:** Development server performance. Dependency pre-bundling with optimizeDeps, React Fast Refresh patterns for reliable HMR, and server configuration for HMR overlay, Docker, and proxy setups. ## 4. Asset Handling (asset) **Impact:** HIGH **Description:** Static asset optimization. Image lazy loading and responsive formats, SVG-as-React-components with SVGR, self-hosted web fonts with preloading, and correct usage of the public directory vs JavaScript imports. ## 5. Environment Config (env) **Impact:** MEDIUM **Description:** Environment variable management. The VITE_ prefix for client-side exposure, mode-specific env files (.env.production, .env.staging), and protecting sensitive data from being embedded in the client bundle. ## 6. Bundle Analysis (bundle) **Impact:** MEDIUM **Description:** Bundle size analysis and monitoring. Using rollup-plugin-visualizer to identify large dependencies and optimization opportunities. --- ## Configure Manual Chunks for Vendor Separation **Impact: CRITICAL (Optimal caching and parallel loading)** Without manual chunks, Vite bundles all vendor dependencies into a single chunk or mixes them with application code, leading to large initial downloads and poor cache efficiency. ## Incorrect ```typescript // vite.config.ts export default defineConfig({ plugins: [react()], build: { // No manual chunks configured // All code bundled together }, }) ``` **Problems:** - React, React DOM, and other vendors are bundled with application code - When you update your app, users must re-download everything - No parallel loading of separate chunks - Poor long-term caching — vendor code invalidated with every app change ## Correct ```typescript // vite.config.ts import { defineConfig } from 'vite' import react from '@vitejs/plugin-react' export default defineConfig({ plugins: [react()], build: { rollupOptions: { output: { manualChunks: { // Core React - rarely changes 'vendor-react': ['react', 'react-dom'], // Router - changes occasionally 'vendor-router': ['react-router-dom'], // UI library - if using one // 'vendor-ui': ['@headlessui/react', '@heroicons/react'], // State management // 'vendor-state': ['zustand', '@tanstack/react-query'], }, }, }, }, }) ``` ```typescript // vite.config.ts - Dynamic manual chunks function export default defineConfig({ build: { rollupOptions: { output: { manualChunks(id) { // Node modules go to vendor chunk if (id.includes('node_modules')) {