import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";

// https://vite.dev/config/
export default defineConfig({
  // Windows 下若 dist 被占用，清空或覆盖会 EPERM；产物默认写到 output/（与 dist 分离）。部署时请同步指向 output。
  build: {
    outDir: "output",
    emptyOutDir: true,
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      "@": resolve(__dirname, "./src"),
    },
  },
  server: {
    port: 5000,
    // 开发时前端在 5000，接口走相对路径 /platform/*、/backend/*，转发到本地 Go（当前 httpport=8081）
    proxy: {
      "/platform": {
        target: "http://127.0.0.1:8081",
        changeOrigin: true,
      },
      "/backend": {
        target: "http://127.0.0.1:8081",
        changeOrigin: true,
      },
    },
  },
});
