본문으로 건너뛰기
Skillpedia
웹사이트 및 UI (프런트엔드)280k · #256

vite-patterns

하는 일

이 스킬은 웹 프로젝트를 빌드하는 도구인 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가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/affaan-m/ECC/blob/main/pi/core/skills/vite-patterns/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“Vite에서 API 프록시를 사용하도록 어떻게 설정하나요?”

매주 새 스킬 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.ts or vite.config.js
  • Setting up environment variables or .env files
  • 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 App) 연동 같은 기능을 추가할 수 있습니다.

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.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬