import vue from '@vitejs/plugin-vue';
import { fileURLToPath, URL } from 'node:url';
import { defineConfig } from 'vite';
import dts from 'vite-plugin-dts';
import { DiagnosticCategory } from 'typescript';

export default defineConfig({
    build: {
        rollupOptions: {
            input: fileURLToPath(new URL('./index.html', import.meta.url)),
            output: {
                entryFileNames: 'assets/[name].js',
                chunkFileNames: 'assets/[name].js',
                assetFileNames: 'assets/[name].[ext]',
            },
        },
    },
    plugins: [
        vue({
            template: {
                compilerOptions: {
                    isCustomElement: tag => ['center'].includes(tag)
                }
            }
        }),
        dts({
            insertTypesEntry: true,
            tsconfigPath: './tsconfig.app.json',
            afterDiagnostic: diagnostics => {
                if (diagnostics.some(d => d.category === DiagnosticCategory.Error)) {
                    throw new Error('Type errors found, see the diagnostics above')
                }
            },
        })
    ],
    resolve: {
        alias: {
            '@': fileURLToPath(new URL('./src', import.meta.url)),
        },
    },
})
