All skills
antfu avatar

/vite

@d02c484 official
by Anthony Fuantfu/skills5.9k stars
335

Vite build tool configuration, plugin API, SSR, and Vite 8 Rolldown migration. Use when working with Vite projects, vite.config.ts, Vite plugins, or building libraries/SSR apps with Vite.

Use this Skill: https://skilld.dev/gh/antfu/skills/vite

This session only. Nothing lands on disk.

referencescore-config.md

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

Vite Configuration

Basic Setup

// vite.config.ts
import { defineConfig } from 'vite'

export default defineConfig({
  // config options
})

Vite auto-resolves vite.config.ts from project root. Supports ES modules syntax regardless of package.json type.

Conditional Config

Export a function to access command and mode:

export default defineConfig(({ command, mode, isSsrBuild, isPreview }) => {
  if (command === 'serve') {
    return { /* dev config */ }
  } else {
    return { /* build config */ }
  }
})
  • command: 'serve' during dev, 'build' for production
  • mode: 'development' or 'production' (or custom via --mode)

Async Config

export default defineConfig(async ({ command, mode }) => {
  const data = await fetchSomething()
  return { /* config */ }
})

Using Environment Variables in Config

.env files are loaded after config resolution. Use loadEnv to access them in config:

import { defineConfig, loadEnv } from 'vite'

export default defineConfig(({ mode }) => {
  // Load env files from cwd, include all vars (empty prefix)
  const env = loadEnv(mode, process.cwd(), '')
  
  return {
    define: {
      __APP_ENV__: JSON.stringify(env.APP_ENV),
    },
    server: {
      port: env.APP_PORT ? Number(env.APP_PORT) : 5173,
    },
  }
})

Key Config Options

input (top-level, Vite 8)

Declare entry points once at the top level. Acts as the default for build.rolldownOptions.input, build.lib.entry, build.ssr (when true), and optimizeDeps.entries. Useful when the app has no index.html entry.

export default defineConfig({
  input: 'src/main.ts',
  // or multi-page: { main: 'index.html', nested: 'nested/index.html' }
})

resolve.alias

export default defineConfig({
  resolve: {
    alias: {
      '@': '/src',
      '~': '/src',
    },
  },
})

The array form's customResolver was removed in Vite 8 — use a custom plugin with a resolveId hook and enforce: 'pre' instead.

define (Global Constants)

export default defineConfig({
  define: {
    __APP_VERSION__: JSON.stringify('1.0.0'),
    __API_URL__: 'window.__backend_api_url',
  },
})

Values must be JSON-serializable or single identifiers. Non-strings auto-wrapped with JSON.stringify.

plugins

import vue from '@vitejs/plugin-vue'

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

Plugins array is flattened; falsy values ignored.

server.proxy

export default defineConfig({
  server: {
    proxy: {
      '/api': {
        target: 'http://localhost:3000',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
      },
    },
  },
})

build.target

Default 'baseline-widely-available' → ['chrome111', 'edge111', 'firefox114', 'safari16.4', 'ios16.4'] (Vite 8, Baseline Widely Available as of 2026-01-01). Customize:

export default defineConfig({
  build: {
    target: 'esnext', // or 'es2020', ['chrome90', 'firefox88']
  },
})

To set the dev/transform target, use oxc.target (replaces esbuild.target); build.target takes precedence for builds.

tsconfig (Vite 8)

Force a specific tsconfig instead of Vite's per-file discovery. Discouraged — prefer placing tsconfig.json near the files it configures and using TS references.

export default defineConfig({ tsconfig: './tsconfig.app.json' })

devtools (Vite 8, experimental)

Enable Vite DevTools integration (requires @vitejs/devtools* packages). Cannot be set from a plugin config hook.

export default defineConfig({ devtools: { apply: 'serve' } })

TypeScript Intellisense

For plain JS config files:

/** @type {import('vite').UserConfig} */
export default {
  // ...
}

Or use satisfies:

import type { UserConfig } from 'vite'

export default {
  // ...
} satisfies UserConfig
<!-- Source references: - https://vite.dev/config/ - https://vite.dev/guide/ -->

Source: SKILL.md on GitHub

No alerts3d5 checks · Risk SAFE
  • Gen Agent Trust Hub3d

    This skill provides comprehensive documentation and reference material for the Vite build tool, including Vite 8 migration guidance, plugin API details, and server-side rendering configurations. No security issues were detected.

  • Socket3d

    No alerts

  • Snyk3d

    Risk: LOW · No issues

  • Runlayer6mo

    1/8 files flagged

  • ZeroLeaks5mo

    Score: 93/100 · 2 sections analyzed

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

Last checked against GitHub 2 days ago.

Activeupdated 4 days ago
Other metadata
metadata
{
  "author": "Anthony Fu",
  "version": "2026.9.25",
  "source": "Generated from https://github.com/vitejs/vite, scripts at https://github.com/antfu/skills"
}

README badge

README badge for antfu/skills/vite

Vite is a next-generation frontend build tool with a fast dev server using native ESM and HMR, optimized production builds, and Vite 8 support for Rolldown-powered bundling. Use this skill when configuring vite.config.ts, developing Vite plugins, or building libraries and SSR applications.

Generated from the current SKILL.md.

Does this skill cover Vite 8 and Rolldown?
Yes. The skill is based on Vite 8 beta and includes migration guidance for Rolldown bundler and Oxc transformer changes.
What does this skill help with?
Configuration (vite.config.ts), plugin API, asset imports, SSR setup, library mode, and Vite 8 migration patterns.
Does this cover framework-specific setups like React or Vue?
The skill documents official plugins like @vitejs/plugin-react and @vitejs/plugin-vue, but focuses on core Vite configuration and APIs, not framework-specific best practices.
Is CommonJS supported?
No. The skill prefers ESM and encourages avoiding CommonJS in Vite projects.

Generated from the current SKILL.md. These answers refresh after source changes.