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

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd(), "");
  // console.log(env.ENV);

  return {
    server: {
      proxy: {
        "/api": {
          target: env.VITE_API_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
        "/php": {
          target: env.VITE_API_PHP_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/php/, ""),
        },
        "/kp": {
          target: env.VITE_API_KP_URL,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/kp/, ""),
        },
      },
    },
    plugins: [
      vue(),
      electron({
        entry: "electron/main.js",
      }),
      electronRender(),
    ],
    resolve: {
      alias: {
        "@": path.resolve(__dirname, "./src"),
      },
    },
    esbuild: {
      drop: env.ENV == "production" ? ["console"] : [],
    },
  };
});
