import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
import { fileURLToPath, URL } from 'node:url'

export default defineConfig(async ({mode}) => {
    const env = loadEnv(mode, process.cwd(), '')

    return {
        plugins: [
            vue(),
            // пример: включаем devtools только в development/staging
            env.VITE_ENABLE_DEVTOOLS === 'true'
                ? (await import('vite-plugin-vue-devtools')).default()
                : undefined
        ].filter(Boolean),
        resolve: {
            alias: {
                '@': fileURLToPath(new URL('./src', import.meta.url)),
            },
        },
        optimizeDeps: {
            exclude: ['chart.js'],
        },
    }
})