/** @maestro-core-managed — mirror stubs/vite.config.js in consuming Laravel apps */
import { fileURLToPath, URL } from "node:url";
import { PrimeVueResolver } from "@primevue/auto-import-resolver";
import tailwindcss from "@tailwindcss/vite";
import vue from "@vitejs/plugin-vue";
import laravel from "laravel-vite-plugin";
import Components from "unplugin-vue-components/vite";
import { defineConfig } from "vite";

const excludeNodeModulesExceptMaestro =
  /[/\\]node_modules[/\\](?!.*@maestro[/\\+]core)/;

export default defineConfig({
  /** Same rationale as stubs/vite.config.js — one Vue runtime for the app + SFCs. */
  optimizeDeps: {
    exclude: ["@maestro/core"],
    include: ["laravel-echo", "pusher-js"],
  },
  plugins: [
    laravel({
      input: ["resources/css/app.css", "resources/js/app.js"],
      refresh: true,
    }),
    vue(),
    tailwindcss(),
    Components({
      resolvers: [PrimeVueResolver()],
      dirs: [],
      exclude: [
        excludeNodeModulesExceptMaestro,
        /[/\\]\.git[/\\]/,
        /[/\\]\.nuxt[/\\]/,
      ],
    }),
  ],
  resolve: {
    dedupe: ["vue", "vue-router"],
    alias: {
      "@": fileURLToPath(new URL("./resources/js", import.meta.url)),
      "@core": fileURLToPath(new URL("./resources/js", import.meta.url)),
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        api: "modern-compiler",
      },
    },
  },
});
