vite-patterns
できること
このスキルは、Webプロジェクトのビルドに使われるツールであるViteの設定と最適化を手助けします。Viteの仕組み、設定の調整方法、プラグインで機能を追加する方法を説明します。
使う場面
- ✓`vite.config.ts`ファイルを設定するとき。
- ✓本番環境向けにプロジェクトを準備する方法を調整したいとき。
- ✓開発サーバーやビルドの処理で問題が起きたとき。
スキルのリンク
https://github.com/affaan-m/ECC/blob/main/pi/core/skills/vite-patterns/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“APIプロキシを使うようにViteを設定するにはどうすればよいですか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
Viteは、リクエストに応じてコードを変換する高速な開発サーバーを使います。本番環境では、RollupやRolldownなどのツールを使ってコードをまとめ(バンドル)、サイズと性能を最適化します。また、依存関係を事前にまとめて、起動を速くします。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
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)
…
よくある質問
HMRとは何ですか?
HMR(Hot Module Replacement)は、ブラウザ上でページ全体を再読み込みせずに、コードの一部をリアルタイムで更新する仕組みです。開発がより速くなります。
Viteでプラグインを使うのはなぜですか?
プラグインはViteの機能を拡張するもので、ReactやVueへの対応、画像の最適化、PWA(Progressive Web Apps)との連携などの機能を追加できます。
Viteは環境変数をどのように扱いますか?
`VITE_`で始まる環境変数は、フロントエンドで使うためにプロジェクトのコードに含まれます。それ以外の変数は、セキュリティ上の理由から公開されません。
詳細
作者による元の説明
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
人気
- GitHubのスター
- 280k
- ランキング
- #256
- ライセンス
- MIT
- 更新日
- 2026/10/15
コメント
- …
このリポジトリの他のスキル
accessibility
280kエージェントが誰にとっても使いやすいインターフェースを作れるように手助けします。目が見えない方や身体の動きに制限のある方など、障害のある人にとってもWebサイトやアプリが正しく動くようにします。
agent-architecture-audit
280kエージェントがすべて正しく動いているかを確認できるようにします。AIシステムの問題を見つけて修正し、期待どおりに動くようにします。
agent-eval
280kエージェントが異なるAIコーディングツールを比較できるようにします。特定のタスクにおいて、どれがより速く、安く、信頼性が高いかを測定します。
agent-harness-construction
280kエージェントがタスクの進め方をよりよく理解できるようにします。エージェントが使うツールや指示を最適化し、成功する可能性を高めます。
似ているスキル
dream-loop
260kコンセプトアートと比べながら、ライブのスクリーンショットを繰り返し確認して、3Dのシーンやビジュアルアプリを高いグラフィック品質に近づけるようエージェントを支援します。
pretext
260kテキストが動く図形の周りに回り込んだり、ゲームのレベルを形作ったり、粒子になって崩れたりする、遊び心のあるブラウザのデモを作るようエージェントを支援します。
page-agent
260kウェブアプリに組み込みのAIアシスタントを加え、利用者が平易な言葉で命令し、ページがそれを実行できるようにするのを、エージェントが支援します。