import mkcert from 'vite-plugin-mkcert';
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
import { resolve } from 'path';
import generateBlockStyles from './assets/js/vite/modules-plugin';
import svgoPlugin from './assets/js/vite/svgo-plugin';

export default defineConfig({
    plugins: [
        mkcert(),
        laravel({
            publicDirectory: 'dist',
            input: ['assets/js/app.js', 'assets/scss/app.scss', 'assets/js/app-admin.js', 'assets/scss/app-admin.scss', 'assets/js/app-gutenberg.js', 'assets/scss/app-gutenberg.scss'],
            refresh: ['**/**.php', 'modules/**/**/*.scss', '**/**.twig', '!modules.scss']
        }),
        generateBlockStyles(),
        svgoPlugin()
    ],
    base: '',
    build: {
        emptyOutDir: true,
        manifest: 'manifest.json',
        outDir: 'dist',
        assetsDir: 'assets'
    },
    resolve: {
        alias: {
            find: /~(.+)/,
            replacement: process.cwd() + '/node_modules/$1',
            '@img': resolve(__dirname, './assets/img'),
            '@fonts': resolve(__dirname, './assets/fonts'),
            '@node_modules': resolve(__dirname, './node_modules'),
            '@icons': resolve(__dirname, './assets/icons')
        }
    },
    css: {
        preprocessorOptions: {
            scss: {
                quietDeps: true
            }
        },
        devSourcemap: true
    },
    server: {
        cors: true,
        strictPort: true,
        port: 3000,
        https: true,
        hmr: {
            host: 'localhost'
        },
        host: true
    }
});
