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.

referencesbuild-and-ssr.md

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

Build and SSR

Library Mode

Build a library for distribution:

// vite.config.ts
import { resolve } from 'node:path'
import { defineConfig } from 'vite'

export default defineConfig({
  build: {
    lib: {
      entry: resolve(import.meta.dirname, 'lib/main.ts'),
      name: 'MyLib',
      fileName: 'my-lib',
    },
    rolldownOptions: {
      external: ['vue', 'react'],
      output: {
        globals: {
          vue: 'Vue',
          react: 'React',
        },
      },
    },
  },
})

Multiple Entries

build: {
  lib: {
    entry: {
      'my-lib': resolve(import.meta.dirname, 'lib/main.ts'),
      secondary: resolve(import.meta.dirname, 'lib/secondary.ts'),
    },
    name: 'MyLib',
  },
}

Output Formats

  • Single entry: es and umd
  • Multiple entries: es and cjs

Package.json Setup

{
  "name": "my-lib",
  "type": "module",
  "files": ["dist"],
  "main": "./dist/my-lib.umd.cjs",
  "module": "./dist/my-lib.js",
  "exports": {
    ".": {
      "import": "./dist/my-lib.js",
      "require": "./dist/my-lib.umd.cjs"
    },
    "./style.css": "./dist/my-lib.css"
  }
}

Multi-Page App

Prefer the top-level input option (Vite 8) — it applies in dev too:

export default defineConfig({
  input: {
    main: resolve(import.meta.dirname, 'index.html'),
    nested: resolve(import.meta.dirname, 'nested/index.html'),
  },
})

SSR Development

Note: Vite's SSR support is low-level and designed mostly for meta-framework authors, not application developers. If you need SSR for your app, use a Vite-based meta-framework instead:

These frameworks build on top of Vite's SSR primitives so you don't have to wire them up yourself.

Need a server? Consider Nitro -- think of it as "Vite for servers." Nitro provides a portable, framework-agnostic server layer with file-based API routing, auto-imports, and deployment presets for dozens of platforms (Node.js, Deno, Bun, Cloudflare Workers, Vercel, Netlify, etc.). It integrates naturally with Vite and is what powers Nuxt's server engine. See the Nitro docs for more details.

JavaScript API

createServer

import { createServer } from 'vite'

const server = await createServer({
  configFile: false,
  root: import.meta.dirname,
  server: { port: 1337 },
})

await server.listen()
server.printUrls()

build

Returns RolldownOutput | RolldownOutput[] | RolldownWatcher (was RollupOutput in Vite 7). On failure it throws a BundleError — inspect e.errors.

import { build } from 'vite'

await build({
  root: './project',
  build: { outDir: 'dist' },
})

createBuilder (Vite 8, environment-aware)

Use createBuilder instead of build to build all configured environments (Environment API):

import { createBuilder } from 'vite'

const builder = await createBuilder()
await builder.buildApp()

preview

import { preview } from 'vite'

const previewServer = await preview({
  preview: { port: 8080, open: true },
})
previewServer.printUrls()

resolveConfig

import { resolveConfig } from 'vite'

const config = await resolveConfig({}, 'build')

loadEnv

import { loadEnv } from 'vite'

const env = loadEnv('development', process.cwd(), '')
// Loads all env vars (empty prefix = no filtering)
<!-- Source references: - https://vite.dev/guide/build - https://vite.dev/guide/api-javascript - https://nitro.build -->

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.