import { wayfinder } from '@laravel/vite-plugin-wayfinder'; import tailwindcss from '@tailwindcss/vite'; import react from '@vitejs/plugin-react'; import laravel from 'laravel-vite-plugin'; import { defineConfig } from 'vite'; const devServerHost = process.env.VITE_DEV_SERVER_HOST ?? '0.0.0.0'; const devServerPort = Number.parseInt(process.env.VITE_DEV_SERVER_PORT ?? '5173', 10); const devServerOrigin = process.env.VITE_DEV_SERVER_URL ?? `http://localhost:${devServerPort}`; const parsedOrigin = new URL(devServerOrigin); const hmrPort = parsedOrigin.port === '' ? devServerPort : Number.parseInt(parsedOrigin.port, 10); const appUrl = process.env.APP_URL ?? 'http://localhost:8000'; export default defineConfig({ server: { host: devServerHost, port: devServerPort, strictPort: true, origin: devServerOrigin, hmr: { host: parsedOrigin.hostname, protocol: parsedOrigin.protocol.replace(':','') as 'http' | 'https', clientPort: hmrPort, }, fs: { strict: true, // Erlaube nur das App-Package (ggf. Pfade anpassen) allow: [__dirname], }, cors: { origin: appUrl, credentials: true, }, watch: { // WENIGER ist mehr: Alles ausklammern, was nicht für HMR nötig ist ignored: [ '**/node_modules/**', '**/.git/**', '**/dist/**', '**/build/**', '**/.next/**', '**/coverage/**', '**/.cache/**', // Laravel-spezifisch '**/public/build/**', '**/storage/**', '**/vendor/**', '**/bootstrap/cache/**', // Monorepo-Nachbarn '../**/node_modules/**', '../**/dist/**', '../**/build/**', '../**/coverage/**', ], // Falls ihr auf gemounteten FS seid und Events fehlen: // usePolling: true, interval: 500, }, proxy: { '/fonts': { target: appUrl, changeOrigin: true, }, }, }, plugins: [ laravel({ input: ['resources/css/app.css','resources/js/app.js', 'resources/js/app.tsx', 'resources/js/guest/main.tsx', 'resources/js/admin/main.tsx'], ssr: 'resources/js/ssr.tsx', refresh: [ 'resources/views/**/*.blade.php', 'resources/lang/**/*.php', 'app/Http/Livewire/**', // falls genutzt // NICHT beobachten: storage/logs, vendor, public/build, etc. ], }), react(), tailwindcss(), wayfinder({ formVariants: true, }), ], esbuild: { jsx: 'automatic', }, optimizeDeps: { // Bei großen Monorepos hilfreich: entries: ['resources/js/**/*'], exclude: [ // füge notfalls große/selten genutzte Pakete hinzu ], }, // Build-Optionen wirken vor allem bei `vite build`, schaden aber nicht: build: { sourcemap: false, target: 'es2020', rollupOptions: { // keine externen Monster-Globs }, }, });