import { defineConfig } from "vite";
import { defineConfigTemplate } from "@hitplay/ads_common";
import { dependencies } from "./package.json";

const rootDev = "src";
const rootBuild = "src";

export default defineConfig((config) => {
  // The template builds the full config (plugins, build, base server.hmr…).
  const templateConfig = defineConfigTemplate({
    rootDev,
    rootBuild,
    config,
    dependenciesArr: Object.keys(dependencies),
  });

  return {
    ...templateConfig,
    server: {
      ...templateConfig.server, // keep the template's settings (hmr, etc.)
      // host:true → listen on 0.0.0.0 (all network interfaces), not just
      // localhost. Vite then prints a "Network:" URL you can open on a phone
      // on the same Wi-Fi. Needs the PC firewall to allow incoming port 5173.
      host: true,
      port: 5173,
      strictPort: true, // fail loudly instead of silently hopping to another port
    },
  };
});
