import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import ElementPlus from "unplugin-element-plus/vite";
// import { visualizer } from 'rollup-plugin-visualizer'

export default defineNuxtConfig({
  css: [
    "@/assets/style/variable.scss",
    "@/assets/style/reset.scss",
    "@/assets/style/base.scss",
    "@/assets/iconfont/iconfont.css",
    // "element-plus/dist/index.css",
  ],
  modules: ["@pinia/nuxt"],
  vite: {
    // cacheDir: ".vite-cache", // 指定 vite 缓存位置（默认就是这个）
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: '@use "@/assets/style/theme.scss" as *;',
          quietDeps: true, // 禁用 Deprecation Warning
        },
      },
    },

    plugins: [
      ElementPlus({}), // 自动按需引入样式
      AutoImport({
        resolvers: [ElementPlusResolver()],
      }),
      Components({
        resolvers: [ElementPlusResolver()],
      }),
    ],
    server: {
      proxy: {
        "/api": {
          target: "http://54.46.9.88:8001/",
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
      },
      hmr: {
        overlay: false, // 关闭 HMR 警告/错误弹窗
      },
    },
    // 👇 开发环境强制打成一个 chunk
    build:
      process.env.NODE_ENV === "development"
        ? {
            rollupOptions: {
              output: {
                manualChunks: () => "index.js", // 所有打进一个 chunk
              },
            },
          }
        : undefined
    // build: {
    //   rollupOptions: {
    //     plugins: [
    //       visualizer({ open: true }),
    //     ],
    //   },
    // },
  },
  runtimeConfig: {},
  app: {
    head: {
      htmlAttrs: {
        lang: "en",
      },
    },
  },
  // plugins: ["~/plugins/vue-warn-handler.js"],

  build: {
    // transpile: ["element-plus"],
  },
});
