import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import { viteStaticCopy } from "vite-plugin-static-copy";
import { resolve } from "path";

export default defineConfig({
  plugins: [
    vue(),
    // @ricky0123/vad-web ships ONNX + audio-worklet assets and depends on
    // onnxruntime-web's WASM binaries. Copy them into the served root so
    // MicVAD can load them at runtime via `baseAssetPath: "/"`.
    viteStaticCopy({
      targets: [
        {
          src: "node_modules/@ricky0123/vad-web/dist/*.onnx",
          dest: "",
          rename: { stripBase: true },
        },
        {
          src: "node_modules/@ricky0123/vad-web/dist/vad.worklet.bundle.min.js",
          dest: "",
          rename: { stripBase: true },
        },
        {
          src: "node_modules/onnxruntime-web/dist/*.wasm",
          dest: "",
          rename: { stripBase: true },
        },
        {
          src: "node_modules/onnxruntime-web/dist/*.mjs",
          dest: "",
          rename: { stripBase: true },
        },
      ],
    }),
  ],
  resolve: {
    alias: {
      "@": resolve(__dirname, "src"),
    },
  },
  server: {
    proxy: {
      "/api": "http://localhost:5000",
    },
  },
});
