Skip to main content
skill CX Codex

react-vite-best-practices — Claude Code skill: React and Vite rules

A skill with 23 rules for optimizing React apps built with Vite: build config, code splitting, HMR, assets, env variables and bundle analysis. Useful when an agent writes or reviews components.

Install into Claude Code · Skills CLI (Vercel) All methods and platforms ↓
npx skills add AsyrafHussin/agent-skills --skill react-vite-best-practices -a claude-code
Open on GitHub

What react-vite-best-practices does

The skill splits into 6 categories by priority. The first two are critical: build optimization (manual chunks, minification, tree shaking, compression, asset hashing) and code splitting (lazy routes with React.lazy(), Suspense boundaries, dynamic imports, chunk prefetching). Development, asset handling, environment config and bundle analysis follow.

Each rule lives in its own file under rules/, such as rules/build-manual-chunks.md or rules/split-route-lazy.md, with an explanation and code samples. There is a ready vite.config.ts with aliases, vendor manualChunks and optimizeDeps settings, plus a typed env example in vite-env.d.ts. The full compiled guide sits in AGENTS.md.

One rule is blunt about secrets: anything prefixed with VITE_ ends up in the bundle and is visible in the browser. If your project already has its own Vite conventions, the skill may push against them, so decide whose rules win before the agent starts editing your config.

What it helps with

  • set up manual chunks so vendors stop sharing a bundle with app code
  • split routes with React.lazy() and place Suspense boundaries
  • speed up dev server startup through optimizeDeps
  • find out which env variables leak into the client bundle
  • inspect what is inside the bundle with rollup-plugin-visualizer

Example prompts for the agent

  • Check my vite.config.ts against react-vite-best-practices and tell me what to improve
  • Split the app routes into lazy chunks and suggest where Suspense boundaries go
  • Audit whether any secrets reach client code through VITE_ variables

How to install react-vite-best-practices

1Skills CLI (Vercel)

npx skills add AsyrafHussin/agent-skills --skill react-vite-best-practices -a claude-code

2Manually: put the files in place

~/.claude/skills/react-vite-best-practices/SKILL.md

Copy the whole skill folder; for one project use .claude/skills/react-vite-best-practices/

Step by step, with commands for each platform: How to install skills in Claude Code: five ways

Questions about react-vite-best-practices

How do I install react-vite-best-practices in Claude?

Run npx skills add AsyrafHussin/agent-skills --skill react-vite-best-practices -a claude-code. The skill file then lands at ~/.claude/skills/react-vite-best-practices/SKILL.md.

What does react-vite-best-practices do?

It hands the agent 23 rules for optimizing React apps on Vite: build output, code splitting, the dev server, assets, env variables and bundle analysis. The agent pulls them in when writing, reviewing or optimizing components.

Which platforms does it support?

Besides Claude, there are install paths for Codex, Cursor, GitHub Copilot, Gemini CLI and OpenCode. Each platform has its own command and skill file location.

Source text

SKILL.md · MIT
---
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 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

- [Vite Documentation](https://vite.dev)
- [React Documentation](https://react.dev)
- [Rollup Documentation](https://rollupjs.org)

## Full Compiled Document

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

© agent-skills · MIT · AsyrafHussin/agent-skills

Similar skills

Everything for Frontend and UI →

From the same set12

php-best-practices A 51-rule guide for reviewing PHP 8.0–8.5 code against PSR standards, SOLID principles, and strict typing. Helps audit classes and adopt modern syntax. CX Codex +1 3,700installs laravel-best-practices A skill with 31 Laravel 13 rules covering architecture, Eloquent, controllers and validation. Useful when your agent writes PHP. CX Codex +1 2,300installs laravel-inertia-react A skill that hands your agent ready rules for Inertia pages, useForm handling and shared data across Laravel and React. CX Codex +1 1,900installs clean-code-principles A skill for architecture review and code quality: SOLID, DRY, KISS, design patterns. Useful when refactoring or weighing design decisions. CX Codex +1 1,800installs typescript-react-patterns A skill with 33 TypeScript rules for React: props, hooks, events, refs, generics and context. Useful when the agent writes components and fights type errors. CX Codex +1 1,100installs api-design-patterns A skill with 38 REST API rules covering resources, errors, security, pagination and versioning. Useful when an agent writes or reviews endpoints. CX Codex +1 929installs laravel-testing Guides AI agents in writing Laravel 13 feature and unit tests with Pest 4 or PHPUnit 12, covering model factories and service mocks. CX Codex +1 907installs testing-best-practices A rule set for unit and integration tests and TDD: 34 rules in 7 categories, TypeScript with Jest and Vitest. Useful while writing tests or reviewing someone else's. CX Codex +1 899installs

Project sponsors

Companies that keep this analytics open
Gold sponsor

Impressions, clicks and code copies — open statistics. We keep the numbers public for the same reason NeBlask itself is public. Become a sponsor