import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  //获取各种环境下的对应的变量
  let env = loadEnv(mode, process.cwd());
  return {
    plugins: [vue()],
    base: "/2024/",
    resolve: {
      alias: {
        // 相对路径别名配置，使用 @ 代替 src
        "@": path.resolve("./src"),
      },
    },
    //代理跨域
    server: {
      proxy: {
        [env.VITE_APP_BASE_API]: {
          //获取数据的服务器地址设置
          target: env.VITE_SERVE,
          //需要代理跨域
          changeOrigin: true,
          //路径重写
          rewrite: (path) => path.replace(/^\/diseaseRight/, ""),
        },
        [env.VITE_APP_BASE_API_DATA]: {
          //获取数据的服务器地址设置
          target: env.VITE_SERVE_DATA,
          //需要代理跨域
          changeOrigin: true,
          //路径重写
          rewrite: (path) => path.replace(/^\/bigData/, ""),
        },
        [env.VITE_APP_BASE_API_DATA2]: {
          //获取数据的服务器地址设置
          target: env.VITE_SERVE_DATA2,
          //需要代理跨域
          changeOrigin: true,
          //路径重写
          rewrite: (path) => path.replace(/^\/bigData2/, ""),
        },
      },
    },
  };
});
