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

// 根据环境设置 base 路径
const getBase = (mode: string) => {
  switch (mode) {
    case "test":
      return "/web-test/"
    case "production":
      return "/web/"
    default:
      return "/"
  }
}

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  return {
    base: getBase(mode),
    plugins: [vue()],
    resolve: {
      alias: {
        "@": resolve(__dirname, "src"),
      },
    },
    server: {
      port: 3000,
      proxy: {
        "/api": {
          target: "http://localhost:3234",
          changeOrigin: true,
          // rewrite: (path) => path.replace(/^\/api/, ''),
        },
      },
    },
  }
})
