import path from 'node:path';
import { fileURLToPath } from 'node:url';
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { VitePWA } from 'vite-plugin-pwa';

const __dirname = path.dirname(fileURLToPath(import.meta.url));

export default defineConfig({
    plugins: [
        laravel({
            input: ['resources/css/app.css', 'resources/js/app.js'],
            refresh: true,
        }),
        VitePWA({
            registerType: 'autoUpdate',
            strategies: 'injectManifest',
            srcDir: 'resources/js',
            filename: 'sw.js',
            outDir: 'public',
            manifest: false,
            injectRegister: false,
            scope: '/',
            buildBase: '/',
            injectManifest: {
                globDirectory: path.resolve(__dirname, 'public/build'),
                globPatterns: ['**/*.{js,css,woff2}'],
                modifyURLPrefix: {
                    'assets/': '/build/assets/',
                },
            },
            devOptions: {
                enabled: false,
            },
        }),
    ],
});
