import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import vueDevTools from 'vite-plugin-vue-devtools'

export default defineConfig({
    root: fileURLToPath(new URL('.', import.meta.url)),
    cacheDir: './node_modules/.vite/build',
    server: {
        port: 5173,
        host: 'localhost',
        strictPort: true,
        watch: {
            usePolling: true,
            interval: 300,
        },
        hmr: {
            clientPort: 5173,
            protocol: 'ws',
        },
    },
    preview: {
        port: 4300,
        host: 'localhost',
    },
    plugins: [vue(), vueJsx(), vueDevTools()],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url)),
        },
    },
    build: {
        outDir: './build',
        emptyOutDir: true,
        reportCompressedSize: true,
        commonjsOptions: {
            transformMixedEsModules: true,
        },
    },
})
