import { defineConfig } from "vite";
import * as path from "@std/path";
import { svelte } from "@sveltejs/vite-plugin-svelte";

// https://vite.dev/config/
export default defineConfig({
  plugins: [svelte()],
  build: {
    rollupOptions: {
      input: [
        ...Deno.readDirSync("./src")
          .filter(({ name }) => name.endsWith(".webc.svelte"))
          .map(({ name }) => path.join("./src", name)),
      ],
      output: {
        dir: path.fromFileUrl(new URL("../js_dist", import.meta.url)),
        entryFileNames: "[name].mjs",
        chunkFileNames: "[name]-[hash].mjs",
        assetFileNames: "[name]-[hash].[ext]",
      },
    },
    sourcemap: true,
  },
});
