Agent skill

react-vite-best-practices

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.

Stars 22
Forks 2

Install this agent skill to your Project

npx add-skill https://github.com/AsyrafHussin/agent-skills/tree/main/skills/react-vite-best-practices

Metadata

Additional technical details for this skill

author
agent-skills
version
2.0.0

SKILL.md

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 separation
  • build-minification - Minification with OXC (default) or Terser
  • build-target-modern - Target modern browsers (baseline-widely-available)
  • build-sourcemaps - Configure sourcemaps per environment
  • build-tree-shaking - Ensure proper tree shaking with ESM
  • build-compression - Gzip and Brotli compression
  • build-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 placement
  • split-dynamic-imports - Dynamic import() for heavy components
  • split-component-lazy - Lazy load non-critical components
  • split-prefetch-hints - Prefetch chunks on hover/idle/viewport

3. Development (HIGH)

  • dev-dependency-prebundling - Configure optimizeDeps for faster starts
  • dev-fast-refresh - React Fast Refresh patterns
  • dev-hmr-config - HMR server configuration

4. Asset Handling (HIGH)

  • asset-image-optimization - Image optimization and lazy loading
  • asset-svg-components - SVGs as React components with SVGR
  • asset-fonts - Web font loading strategy
  • asset-public-dir - Public directory vs JavaScript imports

5. Environment Config (MEDIUM)

  • env-vite-prefix - VITE_ prefix for client variables
  • env-modes - Mode-specific environment files
  • env-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

typescript
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

typescript
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

typescript
// 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

Expand your agent's capabilities with these related and highly-rated skills.

AsyrafHussin/agent-skills

testing-best-practices

Unit testing, integration testing, and test-driven development principles. Use when writing tests, reviewing test code, improving test coverage, or setting up testing strategy. Triggers on "write tests", "review tests", "testing best practices", or "TDD".

22 2
Explore
AsyrafHussin/agent-skills

laravel-owasp-security

OWASP Top 10 security audit and secure coding guidelines for Laravel + React/Inertia.js applications. Use when auditing for vulnerabilities ("run OWASP audit", "security review", "check my app security") or writing secure Laravel code involving auth, payments, file uploads, or API design. Triggers on security-related tasks, payment handling, authentication, or any request to audit a Laravel codebase.

22 2
Explore
AsyrafHussin/agent-skills

laravel-ai-sdk

Laravel AI SDK for building AI-powered features. Use when creating agents, generating images or audio, working with embeddings, vector search, or testing AI features. Triggers on tasks involving laravel/ai, AI agents, tool-calling, structured output, streaming, embeddings, reranking, or AI faking in tests.

22 2
Explore
AsyrafHussin/agent-skills

php-best-practices

PHP 8.x modern patterns, PSR standards, and SOLID principles. Use when reviewing PHP code, checking type safety, auditing code quality, or ensuring PHP best practices. Triggers on "review PHP", "check PHP code", "audit PHP", or "PHP best practices".

22 2
Explore
AsyrafHussin/agent-skills

laravel-mcp

Laravel MCP server development. Use when building MCP servers, tools, prompts, or resources for AI client integration. Triggers on tasks involving laravel/mcp, MCP tools, MCP prompts, MCP resources, or AI client protocols.

22 2
Explore
AsyrafHussin/agent-skills

state-management

React Query and Zustand patterns for state management. Use when implementing data fetching, caching, mutations, or client-side state. Triggers on tasks involving useQuery, useMutation, Zustand stores, caching, or state management.

22 2
Explore

Didn't find tool you were looking for?

Be as detailed as possible for better results