Skip to content

Vite Spickzettel

Frontend-Build-Tool der nächsten Generation mit sofortigem Serverstart.

01

Erste Schritte

Erstellen

Projekte mit Templates scaffolden.

vite
# npm create vite@latest my-app -- --template vue
# npm create vite@latest my-app -- --template react-ts

Konfiguration

Vite-Konfiguration mit Plugins.

vite
// vite.config.ts
import { defineConfig } from "vite";

export default defineConfig({
  plugins: [vue()],
  server: { port: 3000 },
});

Dev/Build

Drei Hauptbefehle.

vite
# vite        # dev server
# vite build  # production build
# vite preview # preview build
02

Features

Plugins

Plugins erweitern die Vite-Funktionalität.

vite
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

export default defineConfig({
  plugins: [react()],
});

Umgebungsvariablen

Das VITE_-Präfix legt Umgebungsvariablen für den Client offen.

vite
import.meta.env.VITE_API_URL

// .env
VITE_API_URL=https://api.example.com

Proxy

API-Requests während der Entwicklung proxen.

vite
server: {
  proxy: {
    "/api": "http://localhost:8080",
  },
}

Was this helpful?