react-vite-best-practices
asyrafhussin/agent-skills
23 React + Vite performance optimization rules for build, code splitting, and bundle efficiency.
What is react-vite-best-practices?
Comprehensive guide for optimizing React applications built with Vite. Covers build configuration, code splitting, lazy loading, HMR, asset handling, and bundle analysis. Use when configuring Vite projects, implementing code splitting, optimizing bundle size, or reviewing React component performance.
- Configure manual chunks and vendor separation for optimal build output
- Implement route-based and component-level code splitting with React.lazy()
- Set up Suspense boundaries and dynamic imports for faster initial loads
- Optimize images, SVGs, fonts, and static assets for production
- Configure environment variables with VITE_ prefix for client-side safety
- Analyze bundle size and dependencies with visualization tools
How to install react-vite-best-practices
npx skills add https://github.com/asyrafhussin/agent-skills --skill react-vite-best-practices- React project using Vite as build tool
- Node.js and npm/yarn/pnpm installed
- Basic understanding of Vite configuration and React component patterns
How to use react-vite-best-practices
- 1.Review the 6 rule categories (Build Optimization, Code Splitting, Development, Asset Handling, Environment Config, Bundle Analysis) by priority
- 2.Apply CRITICAL priority rules first (build-* and split-*) to your vite.config.ts
- 3.Implement route-based code splitting using React.lazy() and Suspense boundaries
- 4.Configure environment variables with VITE_ prefix in .env files
- 5.Set up bundle analysis with rollup-plugin-visualizer to identify optimization opportunities
- 6.Test development performance with HMR and Fast Refresh enabled
Use cases
- Configuring vite.config.ts for a new React project with performance targets
- Implementing lazy loading for dashboard routes to reduce initial bundle size
- Setting up code splitting for heavy third-party libraries and vendor code
- Optimizing image and font loading strategies across development and production
- Analyzing bundle composition to identify and remove unused dependencies
- React developers building with Vite
- Frontend engineers optimizing application performance
- Teams managing large-scale React applications
- Developers reviewing or refactoring existing Vite + React projects
react-vite-best-practices FAQ
Use when writing, reviewing, or optimizing React components built with Vite, or when working on Vite configuration, build optimization, code splitting, lazy loading, HMR, bundle size, or React performance tasks.
Build Optimization (build-*) and Code Splitting (split-*) rules are CRITICAL. These have the highest impact on performance and should be applied first to any React + Vite project.
Use React.lazy() with dynamic imports for route-based splitting, place Suspense boundaries strategically, and configure manual chunks in vite.config.ts for vendor separation.
Only variables prefixed with VITE_ are exposed to client code. Never expose secrets, API keys, or sensitive data in client-side environment variables.
Use the bundle-visualizer rule with rollup-plugin-visualizer to generate interactive visualizations of your bundle composition and identify optimization opportunities.
Full instructions (SKILL.md)
Source of truth, from asyrafhussin/agent-skills.
name: react-vite-best-practices description: React and Vite performance optimization guidelines. Use when writing, reviewing, or optimizing React components built with Vite. Triggers on tasks involving Vite configuration, build optimization, code splitting, lazy loading, HMR, bundle size, or React performance. license: MIT metadata: author: agent-skills version: "2.0.0"
React + Vite Best Practices
Comprehensive performance optimization guide for React applications built with Vite. Contains 23 rules across 6 categories for build optimization, code splitting, development performance, asset handling, environment configuration, and bundle analysis.
Metadata
- Version: 2.0.0
- Framework: React + Vite
- Rule Count: 23 rules across 6 categories
- License: MIT
When to Apply
Reference these guidelines when:
- Configuring Vite for React projects
- Implementing code splitting and lazy loading
- Optimizing build output and bundle size
- Setting up development environment and HMR
- Handling images, fonts, SVGs, and static assets
- Managing environment variables across environments
- Analyzing bundle size and dependencies
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Build Optimization | CRITICAL | build- |
| 2 | Code Splitting | CRITICAL | split- |
| 3 | Development | HIGH | dev- |
| 4 | Asset Handling | HIGH | asset- |
| 5 | Environment Config | MEDIUM | env- |
| 6 | Bundle Analysis | MEDIUM | bundle- |
Quick Reference
1. Build Optimization (CRITICAL)
build-manual-chunks- Configure manual chunks for vendor separationbuild-minification- Minification with OXC (default) or Terserbuild-target-modern- Target modern browsers (baseline-widely-available)build-sourcemaps- Configure sourcemaps per environmentbuild-tree-shaking- Ensure proper tree shaking with ESMbuild-compression- Gzip and Brotli compressionbuild-asset-hashing- Content-based hashing for cache busting
2. Code Splitting (CRITICAL)
split-route-lazy- Route-based splitting with React.lazy()split-suspense-boundaries- Strategic Suspense boundary placementsplit-dynamic-imports- Dynamic import() for heavy componentssplit-component-lazy- Lazy load non-critical componentssplit-prefetch-hints- Prefetch chunks on hover/idle/viewport
3. Development (HIGH)
dev-dependency-prebundling- Configure optimizeDeps for faster startsdev-fast-refresh- React Fast Refresh patternsdev-hmr-config- HMR server configuration
4. Asset Handling (HIGH)
asset-image-optimization- Image optimization and lazy loadingasset-svg-components- SVGs as React components with SVGRasset-fonts- Web font loading strategyasset-public-dir- Public directory vs JavaScript imports
5. Environment Config (MEDIUM)
env-vite-prefix- VITE_ prefix for client variablesenv-modes- Mode-specific environment filesenv-sensitive-data- Never expose secrets in client code
6. Bundle Analysis (MEDIUM)
bundle-visualizer- Analyze bundles with rollup-plugin-visualizer
Essential Configurations
Recommended vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import path from 'path'
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
},
},
build: {
target: 'baseline-widely-available',
sourcemap: false,
chunkSizeWarningLimit: 500,
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-dom'],
},
},
},
},
optimizeDeps: {
include: ['react', 'react-dom'],
},
server: {
port: 3000,
hmr: {
overlay: true,
},
},
})
Route-Based Code Splitting
import { lazy, Suspense } from 'react'
const Home = lazy(() => import('./pages/Home'))
const Dashboard = lazy(() => import('./pages/Dashboard'))
const Settings = lazy(() => import('./pages/Settings'))
function App() {
return (
<Suspense fallback={<LoadingSpinner />}>
{/* Routes here */}
</Suspense>
)
}
Environment Variables
// src/vite-env.d.ts
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_API_URL: string
readonly VITE_APP_TITLE: string
}
interface ImportMeta {
readonly env: ImportMetaEnv
}
How to Use
Read individual rule files for detailed explanations and code examples:
rules/build-manual-chunks.md
rules/split-route-lazy.md
rules/env-vite-prefix.md
References
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
Related skills
More from asyrafhussin/agent-skills and the wider catalog.

clean-code-principles
SOLID principles, design patterns, DRY, KISS, and clean code fundamentals. Use when reviewing architecture, checking code quality, refactoring, or discussing design decisions. Triggers on "review architecture", "check code quality", "SOLID principles", "design patterns", or "clean code".

laravel-best-practices
Laravel 13 conventions and best practices. Use when creating controllers, models, migrations, validation, services, or structuring Laravel applications. Triggers on tasks involving Laravel architecture, Eloquent, database, API development, or PHP patterns.

laravel-inertia-react
Laravel + Inertia.js + React integration patterns. Use when building Inertia page components, handling forms with useForm, managing shared data, or implementing persistent layouts. Triggers on tasks involving Inertia.js, page props, form handling, or Laravel React integration.

php-best-practices
PHP 8.x modern patterns, PSR standards, and SOLID principles for code review and quality audits.
atxp
Agent wallet, identity, and paid tools—register, fund via Stripe/USDC, access 100+ LLM models and paid APIs.
atxp-memory
Agent memory management — cloud backup, restore, and local vector search of .md memory files