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

export default defineConfig({
    enforce: "default",
    plugins: [
        laravel({
            input: [
                'resources/sass/app.scss',
                'resources/sass/admin.scss',
                'resources/js/app.js'
            ],
            refresh: true
        })
    ],
    build: {
        sourcemap: false,
        emptyOutDir: true,
        rollupOptions: {
            output: {
                entryFileNames(chunk) {
                    if (/mobile/.test(chunk.name)) {
                        return 'mobile/[name].js'
                    }
                    return '[name].js';
                },
                chunkFileNames(chunk) {
                    if (/mobile/.test(chunk.name)) {
                        return 'mobile/[name].js'
                    }
                    return '[name].js';
                },
                assetFileNames(chunk) {
                    if (/mobile/.test(chunk.name)) {
                        return 'mobile/[name].[ext]'
                    }
                    return '[name].[ext]';
                },
                // entryFileNames: '[name].js',
                // chunkFileNames: '[name].js',
                // assetFileNames: '[name].[ext]'
            }
        },
        commonjsOptions: {
            include: [/node_modules/]
        }
    },
    resolve: {
        alias: {
            '$':  'jQuery',
            '@': '/resources/js',
            'bootstrap': path.resolve(__dirname, 'node_modules/bootstrap')
        },
    },
    css: {
        preprocessorOptions: {
            scss: {
                quietDeps: true,
                loadPaths: ['node_modules', path.resolve(__dirname, 'node_modules')]
            }
        }
    }
});
