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

const projectRoot = fileURLToPath(new URL(".", import.meta.url));
const stratoRoot = resolve(projectRoot, "strato");
const blueprintRoot = resolve(projectRoot, "app/blueprint-public");
const outputRoot = process.env.FACTORIO_STATIC_OUTPUT
  ? resolve(projectRoot, process.env.FACTORIO_STATIC_OUTPUT)
  : resolve(projectRoot, "strato-dist");

export default defineConfig({
  root: stratoRoot,
  publicDir: resolve(projectRoot, "public"),
  appType: "mpa",
  css: {
    postcss: projectRoot,
  },
  resolve: {
    alias: {
      "@": projectRoot,
      "@blueprint": blueprintRoot,
    },
  },
  plugins: [react()],
  build: {
    outDir: outputRoot,
    emptyOutDir: true,
    rollupOptions: {
      input: {
        index: resolve(stratoRoot, "index.html"),
      },
    },
  },
});
