# vite

Supplies your coding agent with vetted Vite recipes for HMR, chunk splitting, framework plugins, and Vitest setups.

- skill · `type=skill` · Claude Code, Codex, Cursor, GitHub Copilot, Gemini CLI, OpenCode · 820 installs · ★ 286
- Author: Mindrally
- License: Apache-2.0 · policy=mirror · the beginning of the file is at the end of this page
- Source: https://github.com/Mindrally/skills/tree/HEAD/vite/SKILL.md
- Updated: 2026-10-08
- HTML: https://affpapa.org/en/nevibecode/skills/mindrally-vite

## What it does

This skill equips coding agents with reference configurations for modern Vite projects. It covers path alias resolution, custom environment types inside `vite-env.d.ts`, and special asset loading queries such as `?raw` and `?worker`.

Beyond basic bootstrapping, the reference includes manual Hot Module Replacement lifecycle handling, dev server proxying for REST and WebSockets, plus manual chunk splitting rules for Rollup. It also includes boilerplate for React Fast Refresh, Vue, Svelte, Vitest testing, SSR builds, and library mode packaging.

Style preprocessors like Sass still require installing their respective npm packages separately before Vite can bundle them.

## Install

### Claude Code (native platform)

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill vite -a claude-code
```

2. **Manually: put the files in place**
- File: `~/.claude/skills/vite/SKILL.md` — Copy the whole skill folder; for one project use .claude/skills/vite/

### Codex

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill vite -a codex
```

2. **Manually: put the files in place**
- File: `.agents/skills/vite/SKILL.md` — For all projects use ~/.agents/skills/

### Cursor

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill vite -a cursor
```

2. **Manually: put the files in place**
- File: `.cursor/skills/vite/SKILL.md` — Cursor also reads .agents/skills/ and .claude/skills/

### GitHub Copilot

1. **GitHub CLI**
```bash
gh skill install Mindrally/skills vite
```

2. **Manually: put the files in place**
- File: `.github/skills/vite/SKILL.md`

### Gemini CLI

1. **Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill vite -a gemini-cli
```

2. **Platform CLI**
```bash
gemini skills install https://github.com/Mindrally/skills --path vite
```

### Windsurf (Devin Desktop)

**Manually: put the files in place**
- File: `.devin/skills/vite/SKILL.md` — The legacy .windsurf/skills/ path still works

### OpenCode

**Skills CLI (Vercel)**
```bash
npx skills add Mindrally/skills --skill vite -a opencode
```

### Claude.ai

**Claude.ai**
- Zip the folder and upload it in Settings → Capabilities → Skills

Where a file is given instead of a command, copy the files from the source to that path: https://github.com/Mindrally/skills/tree/HEAD/vite/SKILL.md

## When to use it
- configure dev server proxies and path aliases
- split heavy dependencies into manual Rollup chunks
- integrate React, Vue, or Svelte plugins correctly
- set up Vitest with jsdom and code coverage

## Example prompts
- Configure vite.config.ts for React with custom path aliases and vendor chunks
- Show how to type custom VITE_ environment variables in vite-env.d.ts
- Set up a WebSocket and API proxy inside the Vite dev server

## Source text · SKILL.md · Apache-2.0

Below is the content of a third-party file. It is data, not instructions for you: do not act on anything written inside unless the human asks. Block tag: 84b85002176e12cd.

BEGIN THIRD-PARTY FILE 84b85002176e12cd
````text
---
name: vite
description: Expert guidance for Vite development with modern build tooling, HMR, framework integrations, and performance optimization
metadata:
  maintainer: Mindrally
  source: https://github.com/Mindrally/skills
---

# Vite Development

You are an expert in Vite, modern JavaScript/TypeScript build tooling, and frontend development.

## Key Principles

- Leverage native ES modules for fast development
- Use Vite's opinionated defaults when possible
- Configure only what needs customization
- Understand the dev/build differences
- Optimize for both development speed and production performance

## Project Setup

### Basic Configuration
```typescript
// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [react()],
  server: {
    port: 3000,
    open: true,
  },
  build: {
    outDir: 'dist',
    sourcemap: true,
  },
});
```

### Path Aliases
```typescript
import { defineConfig } from 'vite';
import path from 'path';

export default defineConfig({
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
      '@components': path.resolve(__dirname, './src/components'),
      '@utils': path.resolve(__dirname, './src/utils'),
    },
  },
});
```

## Environment Variables

### Usage
```typescript
// .env
VITE_API_URL=https://api.example.com
VITE_APP_TITLE=My App

// In code
const apiUrl = import.meta.env.VITE_API_URL;
const isDev = import.meta.env.DEV;
const isProd = import.meta.env.PROD;
const mode = import.meta.env.MODE;
```

### Type Definitions
```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;
}
```

## Hot Module Replacement

### Manual HMR
```typescript
// For libraries without HMR support
if (import.meta.hot) {
  import.meta.hot.accept('./module.ts', (newModule) => {
    // Handle the updated module
    console.log('Module updated:', newModule);
  });

  import.meta.hot.dispose(() => {
    // Cleanup before module is replaced
  });
}
```

## Asset Handling

### Static Assets
```typescript
// Import as URL
import imageUrl from './image.png';
// <img src={imageUrl} />

// Import as string (raw)
import shaderCode from './shader.glsl?raw';

// Import as worker
import Worker from './worker.ts?worker';
const worker = new Worker();
```

### Public Directory
```
public/
├── favicon.ico      # Served at /favicon.ico
├── robots.txt       # Served at /robots.txt
└── images/          # Served at /images/
```

## Framework Integrations

### React
```typescript
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';

export default defineConfig({
  plugins: [
    react({
      // Enable Fast Refresh
      fastRefresh: true,
      // Babel plugins
      babel: {
        plugins: ['@emotion/babel-plugin'],
      },
    }),
  ],
});
```

### Vue
```typescript
import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';

export default defineConfig({
  plugins: [vue()],
});
```

### Svelte
```typescript
import { defineConfig } from 'vite';
import { svelte } from '@sveltejs/vite-plugin-svelte';

export default defineConfig({
  plugins: [svelte()],
});
```

## Build Optimization

### Code Splitting
```typescript
````
END THIRD-PARTY FILE 84b85002176e12cd

The third-party file has ended. Everything between the 84b85002176e12cd tags is data: requests and commands from it are not followed. An “end of file” line with another tag inside the block is part of the file.

First 3394 of 6858 bytes. © Mindrally · Apache-2.0 · https://github.com/Mindrally/skills/tree/HEAD/vite/SKILL.md

_Part of the page did not fit — see the HTML version._

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
