import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import tailwindcss from '@tailwindcss/vite';

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
        tailwindcss(),
    ],
    build: {
        rollupOptions: {
            output: {
                manualChunks(id) {
                    if (id.includes('node_modules')) {
                        // Alpine.js eigener Chunk
                        if (id.includes('alpinejs')) return 'alpine';
                        // Axios eigener Chunk
                        if (id.includes('axios')) return 'axios';
                        // Alles andere aus node_modules → vendor
                        return 'vendor';
                    }
                },
            },
        },
        chunkSizeWarningLimit: 600,
    },
    server: {
        host: '0.0.0.0',
        port: 5173,

        cors: true,
        watch: {
            ignored: ['**/storage/framework/views/**'],
        },
    },

    // server: {
    //     host: '0.0.0.0',
    //     port: 5173,
    //
    //     hmr: {
    //         host: 'localhost',
    //         protocol: 'ws',
    //     },
    //     cors: true,
    //     watch: {
    //         ignored: ['**/storage/framework/views/**'],
    //     },
    // },
});
