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.

referencesenvironment-api.md

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

Environment API (Vite 6+)

The Environment API formalizes multiple runtime environments beyond the traditional client/SSR split.

Concept

Before Vite 6: Two implicit environments (client and ssr).

Vite 6+: Configure as many environments as needed (browser, node server, edge server, etc.).

Basic Configuration

For SPA/MPA, nothing changes—options apply to the implicit client environment:

export default defineConfig({
  build: { sourcemap: false },
  optimizeDeps: { include: ['lib'] },
})

Multiple Environments

export default defineConfig({
  build: { sourcemap: false },  // Inherited by all environments
  optimizeDeps: { include: ['lib'] },  // Client only
  environments: {
    // SSR environment
    server: {},
    // Edge runtime environment
    edge: {
      resolve: { noExternal: true },
    },
  },
})

Environments inherit top-level config. Some options (like optimizeDeps) only apply to client by default.

Environment Options

interface EnvironmentOptions {
  define?: Record<string, any>
  resolve?: EnvironmentResolveOptions
  optimizeDeps: DepOptimizationOptions
  consumer?: 'client' | 'server'
  dev: DevOptions
  build: BuildOptions
}

Custom Environment Instances

Runtime providers can define custom environments:

import { customEnvironment } from 'vite-environment-provider'

export default defineConfig({
  environments: {
    ssr: customEnvironment({
      build: { outDir: '/dist/ssr' },
    }),
  },
})

Example: Cloudflare's Vite plugin runs code in workerd runtime during development.

Dev Environment Types

Environments run modules through a runner. Two dev environment shapes exist:

  • RunnableDevEnvironment — evaluates modules in the same runtime as the Vite server, so it exchanges arbitrary JS values in-process. Its runner.import(url) is the modern replacement for server.ssrLoadModule (full HMR). Default for ssr and other non-client envs. Guard with isRunnableDevEnvironment(env).
if (isRunnableDevEnvironment(server.environments.ssr)) {
  const mod = await server.environments.ssr.runner.import('/src/entry-server.ts')
}
  • FetchableDevEnvironment — communicates only via the Fetch API (Request/Response), so it works for runtimes that can't run Vite directly (e.g. Cloudflare Workers). Preferred over RunnableDevEnvironment for such runtimes. Handle requests with handleRequest; dispatch via env.dispatchFetch(new Request(url)).

Building Environments

vite build / vite build --ssr still build only client/ssr for back-compat. Setting the builder option (even {}, which is what vite build --app does) opts into building all environments.

import { createBuilder } from 'vite'

const builder = await createBuilder()      // build-time equivalent of createServer
await builder.buildApp()                    // build every configured environment
// await builder.build(builder.environments.ssr) // or one at a time

createBuilder supersedes the standalone build() for environment-aware builds. Customize with the builder.buildApp config option or the global buildApp plugin hook (use environment.isBuilt to skip already-built envs).

Per-Environment Plugins

Restrict a plugin to specific environments with applyToEnvironment, or configure each env with the configEnvironment hook (set defaults in config, since the full env list isn't known there):

{
  name: 'ssr-only',
  applyToEnvironment(env) { return env.name === 'ssr' },
}

Backward Compatibility

  • server.moduleGraph returns mixed client/SSR view
  • ssrLoadModule still works
  • Existing SSR apps work unchanged

When to Use

  • End users: Usually don't need to configure—frameworks handle it
  • Plugin authors: Use for environment-aware transformations
  • Framework authors: Create custom environments for their runtime needs

Plugin Environment Access

Plugins can access environment in hooks:

{
  name: 'env-aware',
  transform(code, id, options) {
    if (options?.ssr) {
      // SSR-specific transform
    }
  },
}
<!-- Source references: - https://vite.dev/guide/api-environment - https://vite.dev/guide/api-environment-frameworks - https://vite.dev/guide/api-environment-plugins - https://vite.dev/guide/api-environment-runtimes - https://vite.dev/blog/announcing-vite6 -->

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.