import path from "node:path";
import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";

const root = path.resolve(__dirname);

export default defineConfig(({ mode }) => {
  const isDesktop = mode === "desktop";
  return {
    plugins: [react()],
    root,
    publicDir: path.join(root, "public"),
    define: {
      "import.meta.env.VITE_API_BASE": JSON.stringify(
        isDesktop ? "https://blog.smyhub.com" : ""
      )
    },
    build: {
      outDir: path.resolve(__dirname, isDesktop ? "../dist-desktop" : "../dist"),
      emptyOutDir: true,
      chunkSizeWarningLimit: 1200
    },
    server: {
      port: 5173,
      proxy: {
        "/api": {
          target: "http://127.0.0.1:8787",
          changeOrigin: true
        }
      }
    }
  };
});
