import { fileURLToPath, URL } from "node:url";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { VantResolver } from "@vant/auto-import-resolver";
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";

export default defineConfig({
    server: {
        host: "0.0.0.0",
        port: 3000,
        strictPort: true,
    },
    build: {
        target: 'es2015',
        minify: 'terser',
        terserOptions: {
            compress: {
                drop_console: true,
                drop_debugger: true,
            },
        },
        rollupOptions: {
            output: {
                manualChunks: {
                    vendor: ['vue', 'vue-router'],
                    vant: ['vant'],
                    utils: ['axios', 'lodash'],
                    charts: ['echarts', 'vue-echarts'],
                },
            },
        },
        cssCodeSplit: true,
        assetsInlineLimit: 4096,
    },
    plugins: [
        vue(),
        AutoImport({
            imports: [
                "vue",
                "vue-router",
                "@vueuse/core",
            ],
            dts: "src/auto-imports.d.ts",
            dirs: [
                "src/composables",
                "src/components",
            ],
            resolvers: [VantResolver()],
        }),
        Components({
            resolvers: [VantResolver()],
        }),
        vueJsx(),
    ],
    resolve: {
        alias: {
            "@": fileURLToPath(new URL("./src", import.meta.url)),
        },
    },
    optimizeDeps: {
        include: ['vue', 'vue-router', 'vant', 'axios'],
    },
});

