import { defineConfig } from "vite";
import { fileURLToPath, URL } from "node:url";
import uni from "@dcloudio/vite-plugin-uni";

export default defineConfig({
  plugins: [uni()],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./", import.meta.url)),
    },
  },
  build: {
    // 生产环境构建配置
    rollupOptions: {
      output: {
        // 将 vue + @dcloudio 合并到同一个 chunk，避免拆包后循环依赖导致 TDZ 错误
        // ("Cannot access '?' before initialization" in vendor-vue chunk)
        manualChunks(id) {
          if (id.includes("node_modules")) {
            if (id.includes("vue") || id.includes("@dcloudio")) {
              return "vendor-vue";
            }
            return "vendor";
          }
        },
      },
    },
    // 提高警告门槛，由默认 500kb 提至 1000kb
    chunkSizeWarningLimit: 1000,
  },
});
