Projekt erstellen
Ein modernes Vue-Projekt benötigt verschiedene Tools für Build, Qualitätssicherung und Testing.
Bundler: Übersicht
Abschnitt betitelt „Bundler: Übersicht“Bundler transformieren und bündeln Source-Code für den Browser.
| Bundler | Beschreibung | Vue-Support |
|---|---|---|
| Vite | Schnell, ESM-basiert, von Vue-Team | Erstklassig |
| Webpack | Etabliert, sehr konfigurierbar | Via vue-loader |
| Parcel | Zero-Config | Via Plugin |
| esbuild | Extrem schnell, Go-basiert | Limitiert |
| Rollup | Library-Bundling | Via Plugin |
Vorteile
Abschnitt betitelt „Vorteile“- Blitzschneller Dev-Server (ESM)
- Hot Module Replacement (HMR)
- Optimierter Production Build
- TypeScript out-of-the-box
- Von Vue-Core-Team entwickelt
Installation
Abschnitt betitelt „Installation“npm create vue@latest# odernpm create vite@latest --template vuevite.config.js
Abschnitt betitelt „vite.config.js“import { defineConfig } from 'vite'import vue from '@vitejs/plugin-vue'
export default defineConfig({ plugins: [vue()], resolve: { alias: { '@': '/src' } }, server: { port: 3000 }})Linting: Übersicht
Abschnitt betitelt „Linting: Übersicht“Linter analysieren Code statisch und finden Fehler, Bugs und Style-Probleme.
| Tool | Sprache | Geschwindigkeit | Vue-Support |
|---|---|---|---|
| ESLint | JavaScript | Mittel | eslint-plugin-vue |
| oxlint | Rust | Sehr schnell | Ja |
| Biome | Rust | Sehr schnell | Experimentell |
| typescript-eslint | - | Mittel | Via ESLint |
Installation
Abschnitt betitelt „Installation“npm install -D eslint @eslint/jsnpm install -D eslint-plugin-vuenpm install -D typescript-eslint # Für TSScripts
Abschnitt betitelt „Scripts“{ "scripts": { "lint": "eslint .", "lint:fix": "eslint . --fix" }}eslint.config.js (Flat Config)
Abschnitt betitelt „eslint.config.js (Flat Config)“import js from '@eslint/js'import vue from 'eslint-plugin-vue'import ts from 'typescript-eslint'
export default [ js.configs.recommended, ...ts.configs.recommended, ...vue.configs['flat/recommended'], { rules: { 'vue/multi-word-component-names': 'off' } }]Formatting: Übersicht
Abschnitt betitelt „Formatting: Übersicht“Formatter sorgen für konsistenten Code-Stil im gesamten Projekt.
| Tool | Beschreibung | Vue-Support |
|---|---|---|
| Prettier | Standard-Formatter | Vollständig |
| Biome | Linter + Formatter | Experimentell |
| dprint | Rust, konfigurierbar | Via Plugin |
Prettier
Abschnitt betitelt „Prettier“Installation
Abschnitt betitelt „Installation“npm install -D prettierScripts
Abschnitt betitelt „Scripts“{ "scripts": { "format": "prettier --write .", "format:check": "prettier --check ." }}.prettierrc
Abschnitt betitelt „.prettierrc“{ "semi": false, "singleQuote": true, "tabWidth": 2, "trailingComma": "es5", "printWidth": 100, "vueIndentScriptAndStyle": true}ESLint + Prettier zusammen
Abschnitt betitelt „ESLint + Prettier zusammen“ESLint und Prettier können sich in die Quere kommen. Lösung:
npm install -D eslint-config-prettierimport js from '@eslint/js'import vue from 'eslint-plugin-vue'import prettier from 'eslint-config-prettier'
export default [ js.configs.recommended, ...vue.configs['flat/recommended'], prettier, // Muss als letztes kommen! { rules: { // Eigene Regeln } }]Testing: Übersicht
Abschnitt betitelt „Testing: Übersicht“| Tool | Typ | Geschwindigkeit | Vue-Support |
|---|---|---|---|
| Vitest | Unit/Integration | Sehr schnell | Erstklassig |
| Jest | Unit/Integration | Mittel | Via Config |
| Cypress | E2E | - | Component Testing |
| Playwright | E2E | - | Via Setup |
Vitest vs Jest
Abschnitt betitelt „Vitest vs Jest“npm install -D vitest @vue/test-utilsexport default defineConfig({ test: { environment: 'happy-dom', globals: true }})- Nutzt Vite-Config
- Native ESM
- HMR für Tests
- Jest-kompatible API
npm install -D jest @vue/vue3-jestnpm install -D babel-jest @babel/preset-envmodule.exports = { testEnvironment: 'jsdom', transform: { '^.+\\.vue$': '@vue/vue3-jest' }}- Mehr Setup nötig
- Etabliertes Ecosystem
- CommonJS-basiert
Komplettes Setup: Empfehlung
Abschnitt betitelt „Komplettes Setup: Empfehlung“npm create vue@latest my-project
# Auswahl:# TypeScript? Yes# JSX? No# Vue Router? Yes# Pinia? Yes# Vitest? Yes# E2E Testing? Playwright# ESLint? Yes# Prettier? Yes# Vue DevTools? YesErgebnis:
Abschnitt betitelt „Ergebnis:“- Bundler: Vite
- Linting: ESLint + eslint-plugin-vue
- Formatting: Prettier
- Testing: Vitest + Playwright
Minimales Setup: create-vite
Abschnitt betitelt „Minimales Setup: create-vite“Für kleinere Projekte oder schnelle Prototypen bietet create-vite einen leichtgewichtigen Start:
npm create vite@latest my-app -- --template vue# oder mit TypeScriptnpm create vite@latest my-app -- --template vue-ts- Nur Vite + Vue
- Minimale Abhängigkeiten
- ~15 MB node_modules
- Kein Router, Pinia, Testing
npm create vue@latest my-app- Interaktive Auswahl
- Router, Pinia, Vitest optional
- ESLint, Prettier optional
- ~80-150 MB node_modules
- Für vollständige Apps
Pre-Commit Hooks mit lint-staged
Abschnitt betitelt „Pre-Commit Hooks mit lint-staged“npm install -D husky lint-stagednpx husky initnpx lint-staged{ "lint-staged": { "*.{js,ts,vue}": [ "eslint --fix", "prettier --write" ], "*.{css,scss,md,json}": [ "prettier --write" ] }}Tool-Vergleich: Zusammenfassung
Abschnitt betitelt „Tool-Vergleich: Zusammenfassung“| Kategorie | Standard | Schnelle Alternative |
|---|---|---|
| Bundler | Vite | - |
| Linting | ESLint | oxlint, Biome* |
| Formatting | Prettier | Biome* |
| Unit Testing | Vitest | Jest |
| E2E Testing | Playwright | Cypress |
| Type Checking | TypeScript | - |
* Vue-Support noch experimentell
Dokumentation
Abschnitt betitelt „Dokumentation“Offizielle Dokumentation:
Alternative Tools:
- oxlint - Schneller Linter
- Biome - Linter + Formatter
- Playwright - E2E Testing