import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import UnoCSS from "unocss/vite";

export default defineConfig({
  plugins: [vue(), UnoCSS()],

  // 基础路径
  base: "/chat-ui/",

  resolve: {
    alias: {
      "@": resolve(__dirname, "src"),
    },
  },
  server: {
    host: "0.0.0.0",
    proxy: {
      "/api/chat-ui": {
        target: "http://localhost:3000",
        changeOrigin: true,
      },
    },
  },
  build: {
    // 输出目录
    outDir: "dist",

    // 静态资源目录
    assetsDir: "assets",

    // 生成 sourcemap（生产环境可关闭）
    sourcemap: false,

    // 使用 esbuild 压缩（默认，更快）
    minify: "esbuild",

    // 分包策略
    rollupOptions: {
      output: {
        manualChunks: {
          "vue-vendor": ["vue", "pinia"],
          "ui-vendor": ["lucide-vue-next"],
        },
        chunkFileNames: "assets/js/[name]-[hash].js",
        entryFileNames: "assets/js/[name]-[hash].js",
        assetFileNames: "assets/[ext]/[name]-[hash].[ext]",
      },
    },
  },

  css: {
    preprocessorOptions: {
      scss: {
        additionalData: ``,
      },
    },
  },
});
