Zum Inhalt springen
Skillpedia
Websites & UI (Frontend)280k · #256

vite-patterns

Was er macht

Dieser Skill hilft dir, Vite zu konfigurieren und zu optimieren, ein Tool zum Bauen von Web-Projekten. Er erklärt, wie Vite funktioniert, wie du die Einstellungen anpasst und wie du mit Plugins zusätzliche Funktionen einbaust.

Wann du ihn nutzt

  • ✓Wenn du die Datei `vite.config.ts` konfigurierst.
  • ✓Wenn du anpasst, wie Vite dein Projekt für die Produktion vorbereitet.
  • ✓Wenn du Probleme mit dem Entwicklungsserver oder dem Build-Prozess behebst.

Link zum Skill

https://github.com/affaan-m/ECC/blob/main/pi/core/skills/vite-patterns/SKILL.md

Kopiere ihn und füge ihn in deine KI ein (Claude, ChatGPT oder Cursor) mit der Bitte, den Anweisungen zu folgen.

So nutzt du ihn

Am einfachsten: Kopiere die Nachricht und füge sie in deine KI ein. Sie liest den Skill und folgt den Anweisungen.

Fertige Nachricht zum Einfügen

Nutze diesen Skill, um mir zu helfen: https://github.com/affaan-m/ECC/blob/main/pi/core/skills/vite-patterns/SKILL.md Lies die SKILL.md unter diesem Link und folge ihren Anweisungen für meine Aufgabe.
Soll deine KI Skills wie diesen selbst finden?Installiere den kostenlosen Skillpedia-MCP: eine Zeile, und sie durchsucht vor jeder Aufgabe 15.000+ Skills.In 1 Minute installieren →

Beispielanfrage an deine KI

“Wie konfiguriere ich Vite so, dass es einen API-Proxy verwendet?”

5 neue Skills pro Woche. 1 Minute Lesezeit.

So funktioniert es

Vite nutzt einen schnellen Entwicklungsserver, der deinen Code bei Bedarf umwandelt. Für die Produktion bündelt es deinen Code mit Tools wie Rollup oder Rolldown und optimiert Größe und Leistung. Außerdem bündelt es Abhängigkeiten vorab, damit der Start schneller geht.

Technischer Inhalt (originale SKILL.md)

Originaltext des Autors, auf Englisch, direkt von 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)

…
Häufige Fragen

Was ist HMR?

HMR (Hot Module Replacement) aktualisiert Teile deines Codes live im Browser, ohne dass die ganze Seite neu geladen wird. Das macht die Entwicklung schneller.

Warum Plugins in Vite nutzen?

Plugins erweitern die Funktionen von Vite. So kannst du Unterstützung für React oder Vue, Bildoptimierung oder PWA-Integration (Progressive Web Apps) hinzufügen.

Wie geht Vite mit Umgebungsvariablen um?

Umgebungsvariablen mit dem Präfix `VITE_` werden in den Code deines Frontends eingebunden. Andere Variablen werden aus Sicherheitsgründen nicht offengelegt.

Details

Originalbeschreibung des Autors

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

Beliebtheit

GitHub-Sterne
280k
Platz im Ranking
#256
Lizenz
MIT
Aktualisiert
15.10.2026

Ist dieser Skill nützlich?

0

Anmelden um abzustimmen.

Kommentare

  • …

Weitere Skills aus diesem Repository

Ähnliche Skills