Skip to content
Back to skills

React Vite Best Practices

ASecurity

React and Vite performance optimization guidelines. Use when writing, reviewing, or optimizing React components built with Vite. Targets Vite 8 (Rolldown, Oxc), @vitejs/plugin-react 6 and React 19. Triggers on tasks involving Vite configuration, Vite 8 migration, build optimization, code splitting, lazy loading, HMR, bundle size, or React performance.

  • 2 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 2, 2026
developmentjavascripttypescriptgojavareactnodeapiperformancedocumentation

Works with

  • cli
  • api

Security analysis

A100/100

Pro scans all 19 files and shows the line behind each finding

Scanned December 2, 2026

npx -y skills add airshell/laravel-php-to-rust --skill react-vite-best-practices --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of React Vite Best Practices?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for React Vite Best Practices
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/airshell-react-vite-best-practices/badge)](https://www.skillsdirectory.com/skills/airshell-react-vite-best-practices)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: react-vite-best-practices
description: React and Vite performance optimization guidelines. Use when writing, reviewing, or optimizing React components built with Vite. Targets Vite 8 (Rolldown, Oxc), @vitejs/plugin-react 6 and React 19. Triggers on tasks involving Vite configuration, Vite 8 migration, build optimization, code splitting, lazy loading, HMR, bundle size, or React performance.
license: MIT
metadata:
  author: agent-skills
  version: "3.0.0"
---

# React + Vite Best Practices

Comprehensive performance optimization guide for React applications built with Vite. Targets Vite 8.x (Rolldown bundler, Oxc compiler), @vitejs/plugin-react 6 and React 19. Contains 24 rules across 6 categories for build optimization, code splitting, development performance, asset handling, environment configuration, and bundle analysis.

## Metadata

- **Version:** 3.0.0
- **Framework:** React + Vite
- **Target:** Vite 8.x (Rolldown, Oxc), @vitejs/plugin-react 6, React 19
- **Updated:** November 2026
- **Rule Count:** 24 rules across 6 categories
- **License:** MIT

## When to Apply

Reference these guidelines when:
- Configuring Vite for React projects
- Moving a Vite 7 config to Vite 8 (Rolldown, Oxc)
- 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-vite8-config` - Vite 8 option names (rolldownOptions, oxc, codeSplitting, tsconfigPaths, React Compiler)
- `build-manual-chunks` - Vendor chunk groups with codeSplitting
- `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(import.meta.dirname, './src'),
    },
  },

  build: {
    target: 'baseline-widely-available',
    sourcemap: false,
    chunkSizeWarningLimit: 500,
    rolldownOptions: {
      output: {
        codeSplitting: {
          groups: [
            {
              name: 'vendor',
              test: /[\\/]node_modules[\\/](react|react-dom|scheduler)[\\/]/,
            },
          ],
        },
      },
    },
  },

  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-vite8-config.md
rules/build-manual-chunks.md
rules/split-route-lazy.md
rules/env-vite-prefix.md
```

## References

- [Vite Documentation](https://vite.dev)
- [React Documentation](https://react.dev)
- [Rolldown Documentation](https://rolldown.rs)
- [Vite 8 Migration](https://vite.dev/guide/migration)

## Full Compiled Document

For the complete guide with all rules expanded: `AGENTS.md`

Files in this skill

  • AGENTS.md92.9 KB
  • README.md1.7 KB
  • SKILL.md5.5 KB
  • rules/_sections.md1.8 KB
  • rules/_template.md892 B
  • rules/asset-fonts.md3.3 KB
  • rules/asset-image-optimization.md4.1 KB
  • rules/asset-public-dir.md3.5 KB
  • rules/asset-svg-components.md4.3 KB
  • rules/build-asset-hashing.md4.1 KB
  • rules/build-compression.md4.1 KB
  • rules/build-manual-chunks.md4 KB
  • rules/build-minification.md5 KB
  • rules/build-sourcemaps.md3.4 KB
  • rules/build-target-modern.md2.5 KB
  • rules/build-tree-shaking.md3.7 KB
  • rules/build-vite8-config.md4.7 KB
  • rules/bundle-visualizer.md3.8 KB
  • rules/dev-dependency-prebundling.md2.5 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in development →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.