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

// https://vitejs.dev/config/
export default ({ mode }: any) =>
  defineConfig({
    base: "./",
    plugins: [vue(), svgLoader()],
    resolve: {
      alias: [
        {
          find: "@",
          replacement: resolve(__dirname, "./src"),
        },
        {
          find: "drawing-board",
          // replacement: resolve(__dirname, "./src/lib/board/4dmap.js"),
          replacement: resolve(
            __dirname,
            "../drawing-board/src/app/4dmap/index.ts"
          ),
        },
      ],
    },
    server: {
      host: "0.0.0.0",
      port: 5173,
      open: true,
      proxy: {
        // "/api": {
        //   target: "http://192.168.0.11:8324",
        //   changeOrigin: true,
        //   rewrite: (path) => path.replace(/^\/api/, ""),
        // },
        "/gear1": {
          target: `http://devimages.apple.com/iphone/samples/bipbop`,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/gear1/, "/gear1"),
        },
        "/api": {
          target: loadEnv(mode, process.cwd()).VITE_API,
          // target: `http://192.168.0.11:8324/relics/`,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, "/api"),
        },
        // "/api": {
        //   target: `https://uat-sp.4dkankan.com/`,
        //   // target: `http://192.168.0.11:8324/relics/`,
        //   changeOrigin: true,
        //   rewrite: (path) => path.replace(/^\/api/, "/api"),
        // },
      },
    },
  });
