選項

設定 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