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-features.md

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

Vite Features

Vite 8: TS/JSX transforms run on Oxc (oxc option, not esbuild), dep pre-bundling on Rolldown, and CSS minification on Lightning CSS by default. esbuild/rollupOptions still work as deprecated aliases.

Glob Import

Import multiple modules matching a pattern:

const modules = import.meta.glob('./dir/*.ts')
// { './dir/foo.ts': () => import('./dir/foo.ts'), ... }

for (const path in modules) {
  modules[path]().then((mod) => {
    console.log(path, mod)
  })
}

Eager Loading

const modules = import.meta.glob('./dir/*.ts', { eager: true })
// Modules loaded immediately, no dynamic import

Named Imports

const modules = import.meta.glob('./dir/*.ts', { import: 'setup' })
// Only imports the 'setup' export from each module

const defaults = import.meta.glob('./dir/*.ts', { import: 'default', eager: true })

Multiple Patterns

const modules = import.meta.glob(['./dir/*.ts', './another/*.ts'])

Negative Patterns

const modules = import.meta.glob(['./dir/*.ts', '!**/ignored.ts'])

Custom Queries

const svgRaw = import.meta.glob('./icons/*.svg', { query: '?raw', import: 'default' })
const svgUrls = import.meta.glob('./icons/*.svg', { query: '?url', import: 'default' })

Case-Insensitive Matching (Vite 8)

// matches Module.js, module.js, MODULE.js
const modules = import.meta.glob('./dir/module*.js', { caseSensitive: false })

Asset Import Queries

URL Import

import imgUrl from './img.png'
// Returns resolved URL: '/src/img.png' (dev) or '/assets/img.2d8efhg.png' (build)

Explicit URL

import workletUrl from './worklet.js?url'

Raw String

import shaderCode from './shader.glsl?raw'

Inline/No-Inline

import inlined from './small.png?inline'    // Force base64 inline
import notInlined from './large.png?no-inline'  // Force separate file

Web Workers

import Worker from './worker.ts?worker'
const worker = new Worker()

// Or inline:
import InlineWorker from './worker.ts?worker&inline'

Preferred pattern using constructor:

const worker = new Worker(new URL('./worker.ts', import.meta.url), {
  type: 'module',
})

Environment Variables

Built-in Constants

import.meta.env.MODE      // 'development' | 'production' | custom
import.meta.env.BASE_URL  // Base URL from config
import.meta.env.PROD      // true in production
import.meta.env.DEV       // true in development
import.meta.env.SSR       // true when running in server

Custom Variables

Only VITE_ prefixed vars exposed to client:

# .env
VITE_API_URL=https://api.example.com
DB_PASSWORD=secret  # NOT exposed to client
console.log(import.meta.env.VITE_API_URL) // works
console.log(import.meta.env.DB_PASSWORD)  // undefined

Mode-specific Files

.env                # always loaded
.env.local          # always loaded, gitignored
.env.[mode]         # only in specified mode
.env.[mode].local   # only in specified mode, gitignored

TypeScript Support

// vite-env.d.ts
interface ImportMetaEnv {
  readonly VITE_API_URL: string
}

interface ImportMeta {
  readonly env: ImportMetaEnv
}

HTML Replacement

<p>Running in %MODE%</p>
<script>window.API = "%VITE_API_URL%"</script>

CSS Modules

Any .module.css file treated as CSS module:

import styles from './component.module.css'
element.className = styles.button

With camelCase conversion:

// .my-class -> myClass (if css.modules.localsConvention configured)
import { myClass } from './component.module.css'

JSON Import

import pkg from './package.json'
import { version } from './package.json'  // Named import with tree-shaking

HMR API

if (import.meta.hot) {
  import.meta.hot.accept((newModule) => {
    // Handle update
  })
  
  import.meta.hot.dispose((data) => {
    // Cleanup before module is replaced
  })
  
  import.meta.hot.invalidate()  // Force full reload
}

WebAssembly

ESM Integration (Vite 8)

Import a .wasm file directly — Vite instantiates it and re-exposes its exports as named ESM exports. Behaves as an async module (needs top-level await):

import { add } from './add.wasm'
console.log(add(1, 2)) // 3

For TS support, enable allowArbitraryExtensions and add add.d.wasm.ts. SSR builds rely on node:fs, so this only works in Node-compatible runtimes.

Manual Initialization

import init from './example.wasm?init'
const instance = await init({ imports: { /* ... */ } })
instance.exports.test()

Chunk Import Map Optimization (Vite 8, experimental)

Set build.chunkImportMap: true to reference chunks by stable ID via an import map instead of hashed URLs. Prevents cascading cache invalidation (updating a leaf chunk no longer invalidates its importers). Requires import.meta.resolve support (use @vitejs/plugin-legacy for older browsers).

<!-- Source references: - https://vite.dev/guide/features - https://vite.dev/guide/env-and-mode - https://vite.dev/guide/assets - https://vite.dev/guide/api-hmr -->

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.