vite-patterns
Skill này làm gì
Skill này giúp bạn cấu hình và tối ưu Vite, công cụ dùng để build các dự án web. Nó giải thích Vite hoạt động thế nào, cách điều chỉnh cài đặt và cách dùng plugin để thêm tính năng.
Khi nào nên dùng
- ✓Khi cấu hình tệp `vite.config.ts`.
- ✓Khi điều chỉnh cách Vite chuẩn bị dự án cho môi trường thực tế.
- ✓Khi xử lý sự cố với máy chủ phát triển hoặc quá trình build.
Liên kết skill
https://github.com/affaan-m/ECC/blob/main/pi/core/skills/vite-patterns/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Làm sao để cấu hình Vite để dùng proxy đến API?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Vite dùng một máy chủ phát triển nhanh, biến đổi code theo yêu cầu. Khi đưa vào môi trường thực tế, nó đóng gói code bằng các công cụ như Rollup hoặc Rolldown, tối ưu kích thước và hiệu năng. Nó cũng xử lý trước các phụ thuộc để khởi động nhanh hơn.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Vite Patterns
Build tool and dev server patterns for Vite 8+ projects. Covers configuration, environment variables, proxy setup, library mode, dependency pre-bundling, and common production pitfalls.
When to Use
- Configuring
vite.config.tsorvite.config.js - Setting up environment variables or
.envfiles - Configuring dev server proxy for API backends
- Optimizing build output (chunks, minification, assets)
- Publishing libraries with
build.lib - Troubleshooting dependency pre-bundling or CJS/ESM interop
- Debugging HMR, dev server, or build errors
- Choosing or ordering Vite plugins
How It Works
- Dev mode serves source files as native ESM — no bundling. Transforms happen on-demand per module request, which is why cold starts are fast and HMR is precise.
- Build mode uses Rolldown (v7+) or Rollup (v5–v6) to bundle the app for production with tree-shaking, code-splitting, and Oxc-based minification.
- Dependency pre-bundling converts CJS/UMD deps to ESM once via esbuild and caches the result under
node_modules/.vite, so subsequent starts skip the work. - Plugins share a unified interface across dev and build — the same plugin object works for both the dev server's on-demand transforms and the production pipeline.
- Environment variables are statically inlined at build time.
VITE_-prefixed vars become public constants in the bundle; everything unprefixed is invisible to client code.
Examples
Config Structure
Basic Config
// vite.config.ts
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig({
plugins: [react()],
resolve: {
alias: { '@': new URL('./src', import.meta.url).pathname },
},
})
Conditional Config
// vite.config.ts
import { defineConfig, loadEnv } from 'vite'
import react from '@vitejs/plugin-react'
export default defineConfig(({ command, mode }) => {
const env = loadEnv(mode, process.cwd()) // VITE_ prefixed only (safe)
return {
plugins: [react()],
server: command === 'serve' ? { port: 3000 } : undefined,
define: {
__API_URL__: JSON.stringify(env.VITE_API_URL),
},
}
})
Key Config Options
| Key | Default | Description |
|---|---|---|
root |
'.' |
Project root (where index.html lives) |
base |
'/' |
Public base path for deployed assets |
envPrefix |
'VITE_' |
Prefix for client-exposed env vars |
build.outDir |
'dist' |
Output directory |
build.minify |
'oxc' |
Minifier ('oxc', 'terser', or false) |
build.sourcemap |
false |
true, 'inline', or 'hidden' |
Plugins
Essential Plugins
Most plugin needs are covered by a handful of well-maintained packages. Reach for these before writing your own.
| Plugin | Purpose | When to use |
|---|---|---|
@vitejs/plugin-react-swc |
React HMR + Fast Refresh via SWC | Default for React apps (faster than Babel variant) |
@vitejs/plugin-react |
React HMR + Fast Refresh via Babel | Only if you need Babel plugins (emotion, MobX decorators) |
@vitejs/plugin-vue |
Vue 3 SFC support | Vue apps |
vite-plugin-checker |
Runs tsc + ESLint in worker thread with HMR overlay |
Any TypeScript app — Vite does NOT type-check during vite build |
vite-tsconfig-paths |
Honors tsconfig.json paths aliases |
Any time you already have aliases in tsconfig.json |
vite-plugin-dts |
Emits .d.ts files in library mode |
Publishing TypeScript libraries |
vite-plugin-svgr |
Imports SVGs as React components | React apps using SVGs as components |
rollup-plugin-visualizer |
Bundle treemap/sunburst report | Periodic bundle size audits (use enforce: 'post') |
vite-plugin-pwa |
Zero-config PWA + Workbox | Offline-capable apps |
Critical callout: vite build transpiles but does NOT type-check. Type errors silently ship to production unless you add vite-plugin-checker or run tsc --noEmit in CI.
Authoring Custom Plugins
Authoring is rare — most needs are covered by existing plugins. When you do need one, start inline in vite.config.ts and only extract if reused.
// vite.config.ts — minimal inline plugin
function myPlugin(): Plugin {
return {
name: 'my-plugin', // required, must be unique
enforce: 'pre', // 'pre' | 'post' (optional)
…
Câu hỏi thường gặp
HMR là gì?
HMR (Hot Module Replacement) cập nhật từng phần code trong trình duyệt theo thời gian thực mà không cần tải lại toàn bộ trang, giúp phát triển nhanh hơn.
Vì sao dùng plugin trong Vite?
Plugin mở rộng chức năng của Vite, cho phép thêm các tính năng như hỗ trợ React hoặc Vue, tối ưu hình ảnh, hoặc tích hợp PWA (ứng dụng web tiến bộ).
Vite xử lý biến môi trường như thế nào?
Các biến môi trường có tiền tố `VITE_` được đưa vào code của dự án để dùng cho giao diện. Các biến khác không được công khai vì lý do bảo mật.
Chi tiết
Mô tả gốc của tác giả
Vite build tool patterns including config, plugins, HMR, env variables, proxy setup, SSR, library mode, dependency pre-bundling, and build optimization. Activate when working with vite.config.ts, Vite plugins, or Vite-based projects.
repo: affaan-m/ECC
Độ phổ biến
- Sao GitHub
- 280k
- Vị trí xếp hạng
- #256
- Giấy phép
- MIT
- Cập nhật
- 15/10/2026
Bình luận
- …
Thêm skill từ kho mã này
accessibility
280kGiúp agent của bạn tạo giao diện mà ai cũng dùng được, đảm bảo website và app hoạt động tốt với người khuyết tật như người mù hoặc khó vận động.
agent-architecture-audit
280kGiúp agent của bạn kiểm tra xem mọi thứ có hoạt động đúng không, đồng thời tìm và sửa các lỗi trong hệ thống AI để chúng chạy như mong đợi.
agent-eval
280kGiúp agent của bạn so sánh các công cụ lập trình AI khác nhau, đo xem công cụ nào nhanh hơn, rẻ hơn và đáng tin cậy hơn cho từng tác vụ.
agent-harness-construction
280kGiúp agent của bạn hiểu rõ hơn cách thực hiện tác vụ, tối ưu các công cụ và chỉ dẫn mà agent dùng để tăng khả năng thành công.
Skill tương tự
dream-loop
260kGiúp agent của bạn đẩy một cảnh 3D hoặc ứng dụng trực quan lên chất lượng đồ họa cao, bằng cách so ảnh chụp màn hình với concept art và lặp lại.
pretext
260kXây dựng các bản demo trình duyệt vui nhộn, trong đó chữ tự chảy quanh các hình chuyển động, tạo màn chơi hoặc tách thành các hạt.
page-agent
260kGiúp agent của bạn thêm một trợ lý AI tích hợp vào ứng dụng web, để người dùng ra lệnh bằng ngôn ngữ thường và trang thực hiện theo.