import { fileURLToPath, URL } from "node:url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
// import vueDevTools from "vite-plugin-vue-devtools";

// https://vite.dev/config/
export default defineConfig({
  // plugins: [vue(), vueDevTools()],
  plugins: [vue()],
  define: {
    "process.env": { TINY_MODE: "pc" },
  },
  build: {
    sourcemap: false,
    rollupOptions: {
      output: {
        manualChunks(id) {
          if (!id.includes("node_modules")) return;
          const parts = id.split("node_modules/")[1]?.split("/");
          const name = parts?.[0]?.startsWith("@") ? `${parts[0]}/${parts[1]}` : parts?.[0];
          if (!name) return "vendor";
          // Keep big UI libs separated for better caching and smaller initial chunk.
          if (name.startsWith("@opentiny/")) return "vendor-opentiny";
          if (name === "vue" || name === "vue-router") return "vendor-vue";
          return "vendor";
        },
      },
    },
  },
  resolve: {
    alias: {
       '@': '/src'
      // "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  }
});
