import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import fs from 'fs';

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/css/app.scss',
                'resources/js/app.js',
            ],
            refresh: true,
        }),
    ],
    css: {
        preprocessorOptions: {
            scss: {
                api: 'modern-compiler', // Use modern Sass API instead of legacy
            }
        }
    },
    build: {
        sourcemap: false, // Disable source maps to avoid missing .map file warnings
        rollupOptions: {
            output: {
                manualChunks: {
                    vendor: ['angular'],
                }
            }
        }
    },
    resolve: {
        alias: {
            // AngularJS compatibility
            'angular': '/resources/assets/vendor/angular/angular.min.js',
        },
    },
    server: {
        https: {
            key: fs.readFileSync('/var/www/certs/nginx-selfsigned.key'), // path to your key
            cert: fs.readFileSync('/var/www/certs/nginx-selfsigned.crt'), // path to your cert
        },
        host: 'localhost',
        port: 5173,
        cors: true,
        headers: {
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Methods': 'GET, POST, PUT, DELETE, OPTIONS',
            'Access-Control-Allow-Headers': 'Origin, X-Requested-With, Content-Type, Accept, Authorization',
        },
        hmr: {
            host: 'localhost',
        },
    },
});