选项

配置 Vite 构建工具,使用其插件 API,设置服务器端渲染(SSR),并利用 Rolldown 迁移至 Vite 8。

...展开全部
10
更新时间 2026-09-06

Vite

基于 Vite 8 beta 版(由 Rolldown 驱动)。Vite 8 采用 Rolldown 打包器和 Oxc 转换器。

Vite 是一款新一代前端构建工具,具备快速开发服务器(原生 ESM + HMR)和经过优化的生产环境构建功能。

首选项

  • 使用 TypeScript:优先 vite.config.ts
  • 始终使用 ESM,避免使用 CommonJS

核心

主题 描述 参考
配置 vite.config.ts, defineConfig、条件配置、 loadEnv 核心配置
功能 import.meta.glob、资产查询(?raw, ?url), import.meta.env、HMR API 核心功能
插件 API Vite特定钩子、虚拟模块、插件排序 核心插件 API

构建与服务器端渲染

主题 描述 参考
构建与 SSR 库模式、SSR 中间件模式、 ssrLoadModule、JavaScript API build-and-ssr

高级

主题 描述 参考
环境 API Vite 支持 6 个及以上多环境,自定义运行时 environment-api
向下迁移 Vite 8项变更:Rolldown打包器、Oxc转换器、配置迁移 rolldown-migration

快速参考

CLI 命令

vite              # Start dev server
vite build        # Production build
vite preview      # Preview production build
vite build --ssr  # SSR build

常用配置

import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [],
  resolve: { alias: { '@': '/src' } },
  server: { port: 3000, proxy: { '/api': 'http://localhost:8080' } },
  build: { target: 'esnext', outDir: 'dist' },
})

官方插件

  • @vitejs/plugin-vue - 支持 Vue 3 SFC
  • @vitejs/plugin-vue-jsx - Vue 3 JSX
  • @vitejs/plugin-react - 支持 Oxc/Babel 的 React
  • @vitejs/plugin-react-swc - 支持使用 SWC 的 React
  • @vitejs/plugin-legacy - 旧版浏览器支持
在 GitHub 上查看
---
name: vite
description: Configure Vite build tool, use its plugin API, set up SSR, and migrate to Vite 8 with Rolldown.
---

# Vite

> Based on Vite 8 beta (Rolldown-powered). Vite 8 uses Rolldown bundler and Oxc transformer.

Vite is a next-generation frontend build tool with fast dev server (native ESM + HMR) and optimized production builds.

## Preferences

- Use TypeScript: prefer `vite.config.ts`
- Always use ESM, avoid CommonJS

## Core

| Topic | Description | Reference |
|-------|-------------|-----------|
| Configuration | `vite.config.ts`, `defineConfig`, conditional configs, `loadEnv` | [core-config](references/core-config.md) |
| Features | `import.meta.glob`, asset queries (`?raw`, `?url`), `import.meta.env`, HMR API | [core-features](references/core-features.md) |
| Plugin API | Vite-specific hooks, virtual modules, plugin ordering | [core-plugin-api](references/core-plugin-api.md) |

## Build & SSR

| Topic | Description | Reference |
|-------|-------------|-----------|
| Build & SSR | Library mode, SSR middleware mode, `ssrLoadModule`, JavaScript API | [build-and-ssr](references/build-and-ssr.md) |

## Advanced

| Topic | Description | Reference |
|-------|-------------|-----------|
| Environment API | Vite 6+ multi-environment support, custom runtimes | [environment-api](references/environment-api.md) |
| Rolldown Migration | Vite 8 changes: Rolldown bundler, Oxc transformer, config migration | [rolldown-migration](references/rolldown-migration.md) |

## Quick Reference

### CLI Commands

```bash
vite              # Start dev server
vite build        # Production build
vite preview      # Preview production build
vite build --ssr  # SSR build
```

### Common Config

```ts
import { defineConfig } from 'vite'

export default defineConfig({
  plugins: [],
  resolve: { alias: { '@': '/src' } },
  server: { port: 3000, proxy: { '/api': 'http://localhost:8080' } },
  build: { target: 'esnext', outDir: 'dist' },
})
```

### Official Plugins

- `@vitejs/plugin-vue` - Vue 3 SFC support
- `@vitejs/plugin-vue-jsx` - Vue 3 JSX
- `@vitejs/plugin-react` - React with Oxc/Babel
- `@vitejs/plugin-react-swc` - React with SWC
- `@vitejs/plugin-legacy` - Legacy browser support

所有文件

0 个文件

安装 vite

下载技能文件并将其解压到 .claude/skills/ 目录中。

下载ZIP

克隆仓库并复制技能文件到您的项目中。

git clone https://github.com/antfu/skills/tree/main/skills/vite # Copy SKILL.md to your .claude/skills/ directory

复制 复制
快速设置: 将技能文件夹复制到 .claude/skills/ Claude 会自动检测并使用该技能
仓库 antfu/skills

相关技能

github-code-search
更新时间 2026-06-29
drizzle-orm
更新时间 2026-06-29
clickhouse-io
更新时间 2026-06-29
prisma-client-api
更新时间 2026-06-29
OR