import { defineConfig } from "vite";
import { svelte } from "@sveltejs/vite-plugin-svelte";
import { resolve } from "node:path";

export default defineConfig({
  plugins: [svelte()],
  build: {
    outDir: resolve(import.meta.dirname, process.env.PICOBOT_WEBUI_OUT_DIR ?? "dist"),
    emptyOutDir: true,
    rollupOptions: {
      output: {
        entryFileNames: "app.js",
        chunkFileNames: "chunks/[name]-[hash].js",
        assetFileNames: (asset) => asset.names?.some((name) => name.endsWith(".css"))
          ? "styles.css"
          : "assets/[name]-[hash][extname]"
      }
    }
  },
  server: {
    proxy: {
      "/api": "http://127.0.0.1:19876",
      "/ws": { target: "ws://127.0.0.1:19876", ws: true }
    }
  }
});
