vite
БесплатноБез исполняемых скриптовНе проверенVite frontend build tool and dev server. Fast HMR and optimized builds. USE WHEN: user mentions "Vite", "vite config", "vite.config", asks about "Vite setup"…
от claude-dev-suite★ 51 звезда на GitHubОб этом скилле
Vite - Quick Reference
When to Use This Skill
- Set up React/Vue/Svelte projects
- Configure dev server and proxy
- Optimize production builds
Deep Knowledge: Use
mcp__documentation__fetch_docswith technology:vitefor comprehensive documentation.
When NOT to Use This Skill
- Webpack-based projects - Use
webpackskill for webpack.config.js - Next.js - Has its own build system (uses SWC/Turbopack)
- Create React App - Still uses Webpack (consider migrating)
- Pure Rollup - Use Rollup directly for libraries
Essential Patterns
Setup
npm create vite@latest my-app -- --template react-ts
cd my-app
npm install
npm run dev
Basic Config
// vite.config.ts
import { defineConfig } from 'vite';
import react from '@vitejs/plugin-react';
import path from 'path';
export default defineConfig({
plugins: [react()],
resolve: {
alias: {
'@': path.resolve(__dirname, './src'),
}
},
server: {
port: 3000,
proxy: {
'/api': {
target: 'http://localhost:8080',
changeOrigin: true
}
}
},
build: {
outDir: 'dist',
sourcemap: true
}
});
Environment Variables
# .env
VITE_API_URL=http://localhost:8080/api
// Usage
const apiUrl = import.meta.env.VITE_API_URL;
const isProd = import.meta.env.PROD;
// TypeScript types (vite-env.d.ts)
interface ImportMetaEnv {
readonly VITE_API_URL: string;
}
Code Splitting
// Dynamic imports
const AdminPanel = lazy(() => import('./AdminPanel'));
// Manual chunks
export default defineConfig({
build: {
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-dom'],
}
}
}
}
});
Commands
| Command | Usage |
|---|---|
npm run dev |
Dev server HMR |
npm run build |
Build production |
npm run preview |
Preview build |
Anti-Patterns to Avoid
- Do not forget the
VITE_prefix for env vars - Do not use relative paths (use aliases)
- Do not ignore chunk size warnings
Anti-Patterns
| Anti-Pattern | Why It's Bad | Correct Approach |
|---|---|---|
| No VITE_ prefix for env vars | Won't be exposed to client | All client vars need VITE_ prefix |
| Relative imports | Hard to refactor | Use path aliases (@/...) |
| Ignoring chunk size warnings | Large initial bundles | Use manual chunks or lazy loading |
| Not using TypeScript for config | Missing type hints | Use defineConfig from 'vite' |
| No dev/prod environment separation | Same config for both | Use env-specific .env files |
| Large public folder | Slow builds | Only static assets in public/ |
Quick Troubleshooting
| Issue | Cause | Solution |
|---|---|---|
| Env vars undefined | Missing VITE_ prefix | Rename to VITE_API_URL |
| HMR not working | Proxy configuration | Check server.hmr settings |
| Build fails with dynamic imports | Wrong syntax | Use import() not require() |
| Slow dev server | Too many dependencies | Add to optimizeDeps.include |
| 404 on refresh (SPA) | No fallback | Add server.historyApiFallback |
| CORS errors in dev | Wrong proxy config | Configure server.proxy correctly |
Production Readiness
Build Optimization
// vite.config.ts
import { defineConfig, splitVendorChunkPlugin } from 'vite';
import { visualizer } from 'rollup-plugin-visualizer';
export default defineConfig({
plugins: [
react(),
splitVendorChunkPlugin(),
visualizer({ open: true }), // Bundle analysis
],
build: {
target: 'es2020',
minify: 'esbuild',
sourcemap: true,
rollupOptions: {
output: {
manualChunks: {
vendor: ['react', 'react-dom'],
router: ['react-router-dom'],
ui: ['@radix-ui/react-dialog', '@radix-ui/react-dropdown-menu'],
},
},
},
chunkSizeWarningLimit: 500,
},
// Optimize deps
optimizeDeps: {
include: ['react', 'react-dom'],
exclude: ['@some/heavy-package'],
},
});
Security Configuration
// vite.config.ts
export default defineConfig({
// Never expose server-only vars
define: {
'process.env.API_SECRET': 'undefined',
},
server: {
// CORS for dev
cors: {
origin: 'http://localhost:3000',
credentials: true,
},
// Proxy to avoid CORS issues
proxy: {
'/api': {
target: 'http://localhost:8080',
changeOrigin: true,
secure: false,
},
},
},
// Preview server (for testing prod builds)
preview: {
port: 4173,
strictPort: true,
},
});
// Type-safe env vars
// env.d.ts
/// <reference types="vite/client" />
interface ImportMetaEnv {
readonly VITE_API_URL: string;
readonly VITE_APP_TITLE: string;
// Add all VITE_ prefixed vars here
}
interface ImportMeta {
readonly env: ImportMetaEnv;
}
Performance
// vite.config.ts
export d
Установить vite в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
ReadGrepGlobWriteEditFAQ
Что делает скилл vite?
Vite frontend build tool and dev server. Fast HMR and optimized builds. USE WHEN: user mentions "Vite", "vite config", "vite.config", asks about "Vite setup", "Vite dev server", "Vite build", "fast HMR" DO NOT USE FOR: Webpack projects (use webpack skill), Next.js (uses its own bundler), Create React App (uses Webpack), library builds with Rollup only
Как установить скилл vite?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл vite запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
mcp-builder
Guide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when…
от Anthropicclaude-api
Reference for the Claude API / Anthropic SDK — model ids, pricing, params, streaming, tool use, MCP, agents, caching, token counting, model migration. TRIGGER…
от Anthropicalgorithmic-art
Creating algorithmic art using p5.js with seeded randomness and interactive parameter exploration. Use this when users request creating art using code…
от Anthropicmcp-integration
This skill should be used when the user asks to "add MCP server", "integrate MCP", "configure MCP in plugin", "use .mcp.json", "set up Model Context…
от Anthropic