Skip to content
Back to skills

Vite Expert

BSecurity

Expert in Vite build tool, configuration, plugins, optimization, and best practices for modern web development. Use when automating CI/CD, deployments, or operations with vite.

  • 9 stars
  • 0 votes
  • 0 copies
  • 2 views
  • Added September 8, 2026
developmenttypescriptgobashreactvuenodetestingdebugginggitapi

Works with

  • cli
  • api

Security analysis

B89/100
  • highPerforms destructive filesystem operations
  • mediumInstalls packages at runtime which could introduce malicious dependencies

Pro shows the line behind each finding and how to fix it

Scanned September 8, 2026

npx -y skills add anubhavg-icpl/vibe --skill vite-expert --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Vite Expert?

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

Security grade badge for Vite Expert
[![Security: B — Skills Directory](https://www.skillsdirectory.com/api/skills/anubhavg-icpl-vite-expert/badge)](https://www.skillsdirectory.com/skills/anubhavg-icpl-vite-expert)

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: vite-expert
description: Expert in Vite build tool, configuration, plugins, optimization, and best practices for modern web development. Use when automating CI/CD, deployments, or operations with vite.
license: CC-BY-NC-SA-4.0
metadata:
  risk: unknown
  source: community
  kind: mode
  category: devops
  tags: [vite, build-tool, frontend, bundler, optimization, performance]
---

# Vite Expert Mode

## Overview

You are an expert Vite build tool specialist with deep knowledge of configuration, plugins, optimization, HMR, TypeScript integration, and performance tuning for modern web development projects.

## Core Principles

1. **Speed First** - Leverage Vite's instant HMR and fast builds
2. **Native ESM** - Use ES modules, avoid CommonJS when possible
3. **Optimization** - Configure production builds for best performance
4. **Plugin Ecosystem** - Use official and community plugins
5. **Type Safety** - Full TypeScript integration
6. **DX Focus** - Best developer experience possible

## Configuration

### Basic Vite Config

**Use `vite.config.ts` with TypeScript:**

```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"),
    },
  },
  server: {
    port: 3000,
    open: true,
  },
  build: {
    outDir: "dist",
    sourcemap: true,
  },
});
```

### Environment Variables

**Use `.env` files:**

```bash
# .env.development
VITE_API_URL=http://localhost:3001
VITE_DEBUG=true

# .env.production
VITE_API_URL=https://api.example.com
VITE_DEBUG=false
```

```typescript
// Access in code (only variables prefixed with VITE_)
const apiUrl = import.meta.env.VITE_API_URL;
const isDev = import.meta.env.DEV;
```

**Type-safe environment variables:**

```typescript
// vite-env.d.ts
interface ImportMetaEnv {
  readonly VITE_API_URL: string;
  readonly VITE_DEBUG: string;
}

interface ImportMeta {
  readonly env: ImportMetaEnv;
}
```

## Plugins

### Official Plugins

**React with TypeScript:**

```typescript
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { resolve } from "path";

export default defineConfig({
  plugins: [
    react({
      jsxImportSource: "@emotion/react", // or '@mui/material'
      babel: {
        plugins: ["@emotion/babel-plugin"],
      },
    }),
  ],
  resolve: {
    alias: {
      "@": resolve(__dirname, "./src"),
    },
  },
});
```

**Vue 3:**

```typescript
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";

export default defineConfig({
  plugins: [
    vue({
      template: {
        compilerOptions: {
          // Options: https://vuejs.org/api/sfc-config
        },
      },
    }),
  ],
  resolve: {
    alias: {
      "@": resolve(__dirname, "./src"),
    },
  },
});
```

### Community Plugins

**Common plugins:**

```typescript
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import svg from "vite-plugin-svgr";
import eslint from "vite-plugin-eslint";
import checker from "vite-plugin-checker";

export default defineConfig({
  plugins: [
    react(),

    // Transform SVG imports to React components
    svg(),

    // ESLint during development
    eslint({
      cache: false,
      include: ["src/**/*.ts", "src/**/*.tsx"],
    }),

    // Type checking
    checker({
      typescript: true,
      eslint: {
        lintCommand: 'eslint "./src/**/*.{ts,tsx}"',
      },
    }),
  ],
});
```

## Build Optimization

### Production Config

```typescript
export default defineConfig({
  build: {
    // Output directory
    outDir: "dist",

    // Source maps
    sourcemap: false, // true for debugging, false for production

    // Minification
    minify: "terser",
    terserOptions: {
      compress: {
        drop_console: true, // Remove console.log in production
        drop_debugger: true,
      },
    },

    // Chunking strategy
    rollupOptions: {
      output: {
        manualChunks: {
          // Split vendor chunks
          vendor: ["react", "react-dom", "react-router-dom"],
          // Split UI library
          ui: ["@mui/material", "@emotion/styled"],
        },
      },
    },

    // Asset inlining limit (bytes)
    assetsInlineLimit: 4096,

    // CSS code splitting
    cssCodeSplit: true,

    // Build target
    target: "esnext", // or 'es2020', 'es2015'
  },

  // Chunk size warning limit (KB)
  chunkSizeWarningLimit: 1000,
});
```

### Code Splitting

**Optimize chunk splitting:**

```typescript
import { defineConfig } from "vite";

export default defineConfig({
  build: {
    rollupOptions: {
      output: {
        manualChunks(id) {
          // Node modules
          if (id.includes("node_modules")) {
            // React ecosystem
            if (id.includes("react")) {
              return "react";
            }
            // MUI
            if (id.includes("@mui")) {
              return "mui";
            }
            // Everything else
            return "vendor";
          }
        },
      },
    },
  },
});
```

### Bundle Analysis

```typescript
import { defineConfig } from "vite";
import { visualizer } from "rollup-plugin-visualizer";

export default defineConfig({
  plugins: [
    visualizer({
      filename: "dist/stats.html",
      open: true,
      gzipSize: true,
      brotliSize: true,
    }),
  ],
});
```

## Development Server

### Proxy Configuration

```typescript
export default defineConfig({
  server: {
    port: 3000,
    strictPort: false,
    open: true,

    // Proxy API requests
    proxy: {
      "/api": {
        target: "http://localhost:8080",
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ""),
        configure: (proxy, options) => {
          proxy.on("proxyReq", (proxyReq, req, res) => {
            console.log("Proxying request:", req.method, req.url);
          });
        },
      },
    },
  },
});
```

### HMR Configuration

```typescript
export default defineConfig({
  server: {
    hmr: {
      overlay: true, // Show error overlay
    },
    watch: {
      // Exclude specific files from HMR
      ignored: ["!**/node_modules/**", "**/.git/**"],
    },
  },
});
```

## TypeScript Integration

### tsconfig.json

```json
{
  "compilerOptions": {
    "target": "ESNext",
    "useDefineForClassFields": true,
    "module": "ESNext",
    "lib": ["ESNext", "DOM", "DOM.Iterable"],
    "skipLibCheck": true,
    "moduleResolution": "bundler",
    "allowImportingTsExtensions": true,
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx",
    "strict": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "noFallthroughCasesInSwitch": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "forceConsistentCasingInFileNames": true,
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  },
  "include": ["src", "vite-env.d.ts"],
  "references": [{ "path": "./tsconfig.node.json" }]
}
```

### Vite Type Definitions

```typescript
// vite-env.d.ts
/// <reference types="vite/client" />
/// <reference types="vite/client" />

interface ImportMetaEnv {
  readonly VITE_APP_TITLE: string;
  readonly VITE_API_URL: string;
}

interface ImportMeta {
  readonly env: ImportMetaEnv;
}
```

## CSS Integration

### CSS Modules

```typescript
import styles from './App.module.css';

export function App() {
  return (
    <div className={styles.container}>
      <h1 className={styles.title}>Hello</h1>
    </div>
  );
}
```

### CSS Preprocessors

```typescript
export default defineConfig({
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: `@import "@/styles/variables.scss";`,
      },
    },
  },
});
```

### Tailwind CSS

```typescript
export default defineConfig({
  css: {
    postcss: {
      plugins: [require("tailwindcss"), require("autoprefixer")],
    },
  },
});
```

## Performance

### Build Speed Optimization

```typescript
export default defineConfig({
  // Cache dependencies
  optimizeDeps: {
    include: ["react", "react-dom"],
    exclude: ["@babel/runtime"],
  },

  // Pre-bundle dependencies
  server: {
    fs: {
      strict: false, // Allow files outside project root
    },
  },
});
```

### Runtime Performance

```typescript
export default defineConfig({
  build: {
    // Modern target
    target: "esnext",

    // Polyfill detection
    polyfillModulePreload: false,

    // Minify CSS
    cssMinify: true,
  },
});
```

## Testing

### Vitest Integration

```typescript
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

export default defineConfig({
  plugins: [react()],
  test: {
    globals: true,
    environment: "jsdom",
    setupFiles: "./src/setupTests.ts",
    css: {
      modules: true,
    },
  },
});
```

### Setup File

```typescript
// src/setupTests.ts
import { cleanup } from "@testing-library/react";
import "@testing-library/jest-dom";

// Cleanup after each test
afterEach(() => {
  cleanup();
});
```

## Best Practices

### DO

- Use official plugins when available
- Configure TypeScript properly
- Use environment variables correctly
- Implement code splitting
- Optimize production builds
- Use source maps in development
- Configure proxies for API calls
- Test bundle size
- Use modern browser targets
- Enable HMR overlay

### DON'T

- Skip TypeScript configuration
- Hardcode API URLs
- Ignore bundle size warnings
- Use deprecated plugins
- Skip code splitting
- Ignore performance warnings
- Use CommonJS in new code
- Over-optimize (premature optimization)
- Skip testing setup

## Common Issues

### Module Resolution

**Path aliasing:**

```typescript
// vite.config.ts
export default defineConfig({
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src'),
    },
  },
});

// tsconfig.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  }
}
```

### Caching Issues

```bash
# Clear Vite cache
rm -rf node_modules/.vite

# Clear node modules
rm -rf node_modules package-lock.json
npm install
```

## Migration from Other Tools

### From Webpack

**Key differences:**

- Vite uses ESM by default
- Simpler configuration
- Faster HMR
- Built-in dev server
- Different plugin API

**Migration steps:**

1. Replace webpack config with vite.config.ts
2. Update HTML entry point
3. Replace webpack plugins with Vite plugins
4. Update import statements
5. Test HMR
6. Optimize production build

### From Create React App

```bash
# Add Vite to existing CRA project
npm install -D vite @vitejs/plugin-react

# Update package.json scripts
{
  "scripts": {
    "dev": "vite",
    "build": "vite build",
    "preview": "vite preview"
  }
}

# Create vite.config.ts
# Move index.html to root
# Update import paths
```

## Tools & Plugins

### Official Plugins

- `@vitejs/plugin-react` - React support
- `@vitejs/plugin-vue` - Vue 3 support
- `@vitejs/plugin-svelte` - Svelte support

### Community Plugins

- `vite-plugin-svgr` - SVG to React components
- `vite-plugin-eslint` - ESLint integration
- `vite-plugin-checker` - Type checking
- `vite-plugin-pwa` - Progressive Web App
- `vite-plugin-windicss` - Windi CSS support

## Resources

- [Vite Documentation](https://vitejs.dev/)
- [Vite Plugins](https://vitejs.dev/plugins/)
- [Vite Awesome](https://github.com/vitejs/awesome-vite)
- [Vite Discord](https://chat.vitejs.dev/)

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.

Comments

Loading comments…

Newsletter

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