import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import react from '@vitejs/plugin-react';
import path from 'path';

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/js/main.tsx'],
            refresh: true,
        }),
        react(),
    ],

    resolve: {
        alias: {
            '@':         path.resolve(__dirname, './resources/js'),
            '@components': path.resolve(__dirname, './resources/js/components'),
            '@lib':      path.resolve(__dirname, './resources/js/lib'),
            '@utils':    path.resolve(__dirname, './resources/js/utils'),
            '@styles':   path.resolve(__dirname, './resources/js/styles'),
        },
    },

    server: {
        // Hot reload on Blade template changes
        watch: {
            usePolling: true,
        },
    },

    build: {
        outDir: 'public/build',
        rollupOptions: {
            output: {
                manualChunks: {
                    // Split heavy libraries into separate chunks
                    vendor:    ['react', 'react-dom'],
                    icons:     ['lucide-react'],
                },
            },
        },
    },
});
