import { defineConfig } from "vite";
import react from "@vitejs/plugin-react";
import { viteSingleFile } from "vite-plugin-singlefile";
import { fileURLToPath } from "url";
import { dirname, resolve } from "path";

const __dirname = dirname(fileURLToPath(import.meta.url));

const INPUT = process.env.INPUT;
if (!INPUT) {
  throw new Error("INPUT environment variable is not set");
}

export default defineConfig({
  plugins: [react(), viteSingleFile()],
  root: __dirname,
  build: {
    outDir: resolve(__dirname, "../../../dist/app-ui"),
    emptyOutDir: false,
    rollupOptions: {
      input: resolve(__dirname, INPUT),
    },
  },
});
