// @ts-check
import { defineConfig, mergeConfig } from "vite";
import { baseConfig } from "./vite.config.mjs";
import { apiServerBaseURL, apiServerPort } from "./configs/vars.mjs";

const config = defineConfig(async (configEnv) => {
  /**
   * @type {import("vite").UserConfig}
   */
  const prodConfig = {
    preview: {
      host: "0.0.0.0",
      port: 5000,
      strictPort: true,
      proxy: {
        "/api": `${apiServerBaseURL}:${apiServerPort}`,
      },
    },
    build: {
      cssCodeSplit: false,
      sourcemap: true,
      outDir: "dist",
      emptyOutDir: true,
    },
  };
  const resolvedBase = await baseConfig(configEnv);
  const finalConfig = mergeConfig(resolvedBase, prodConfig);

  return finalConfig;
});

export default config;
