All skills
asyrafhussin avatar

/react-vite-best-practices

@b2dc58c

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.

Use this Skill: https://skilld.dev/gh/asyrafhussin/agent-skills/react-vite-best-practices

This session only. Nothing lands on disk.

rulesbuild-target-modern.md

≈638 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Target Modern Browsers for Smaller Bundles

Impact: CRITICAL (10-15% smaller bundles)

Vite defaults to 'baseline-widely-available', which targets browser features that are widely available across all major browsers. Explicitly targeting older browsers includes unnecessary polyfills and transpilation, increasing bundle size.

Incorrect

// vite.config.ts - Targeting old browsers unnecessarily
export default defineConfig({
  build: {
    target: 'es2015', // Too old, includes many polyfills
  },
})

Problems:

  • Targeting es2015 adds polyfills for features all modern browsers support natively
  • Larger bundle size from unnecessary transpilation
  • Slower builds due to extra transformation passes

Correct

// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [react()],
  build: {
    // Default is 'baseline-widely-available' — good for most apps
    // Use 'esnext' for the smallest bundle if you control the browser environment
    target: 'esnext',

    // Or be specific about browser versions
    // target: ['es2022', 'edge88', 'firefox78', 'chrome87', 'safari14'],
  },
})
// vite.config.ts - With legacy browser support
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
import legacy from '@vitejs/plugin-legacy'

export default defineConfig({
  plugins: [
    react(),
    legacy({
      targets: ['defaults', 'not IE 11'],
      // Modern chunks for modern browsers
      // Legacy chunks only loaded by old browsers
    }),
  ],
  build: {
    target: 'esnext', // Modern build
  },
})

Benefits:

  • esnext produces the smallest bundles by using native browser features
  • baseline-widely-available (default) balances size with broad compatibility
  • The @vitejs/plugin-legacy plugin provides a fallback for older browsers without penalizing modern ones
  • Specific browser version targets give fine-grained control
Target Use Case
esnext Latest features, smallest bundle
baseline-widely-available Default — broad modern browser support
es2022 Good balance, wide support
Custom array Specific browser versions

Reference: Vite Build Options - target

Source: SKILL.md on GitHub

1 alert17d5 checks · Risk SAFE
  • Gen Agent Trust Hub17d

    The skill is a comprehensive performance optimization guide for React and Vite applications. It contains instructional content and code examples for build optimization, code splitting, and asset handling. The skill explicitly promotes security best practices, such as preventing the exposure of sensitive environment variables in client-side code, and no malicious patterns were detected.

  • Socket17d

    No alerts

  • Snyk17d

    Risk: LOW · No issues

  • Runlayer6mo

    4/29 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at b2dc58c. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub last month.

Steadyupdated 7 months ago
metadata
{
  "author": "agent-skills",
  "version": "2.0.0"
}

README badge

README badge for asyrafhussin/agent-skills/react-vite-best-practices