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'
const isDev = process.env.NODE_ENV === 'development';
const appType = process.env.APP_TYPE;
const SERVICE = process.env.SERVICE;
export default defineNuxtConfig({
  ssr: false,
  nitro: {
    output: {
      dir: isDev ? undefined : `.output-${appType}`
    },
    preset: 'static'
  },
  postcss: {
    plugins: {
      'postcss-px-to-viewport': {
        viewportWidth: 1920, // 设计稿宽度
        unitPrecision: 3,
        viewportUnit: 'vw',
        // selectorBlackList: ['ignore', 'no-vw'], // 不转换的类名
        minPixelValue: 1,
        mediaQuery: false,
      }
    }
  },
  css: [
    "@/assets/style/variable.scss",
    "@/assets/style/reset.scss",
    appType === 'user' ? "@/assets/style/base-en.scss" : '@/assets/style/base-zh.scss',
    "@/assets/style/base.scss",
    "@/assets/iconfont/iconfont.css",
    // "element-plus/dist/index.css",
  ],
  modules: ["@pinia/nuxt"],
  vite: {
    // Vite 在开发模式下会对第三方依赖（node_modules）做一次 预打包（pre-bundling），以便提高运行时性能。
    optimizeDeps: {
      include: [
        "element-plus",
        "axios",
        "qs",
        "pinia",
        "pinia-plugin-persistedstate",
        "@gtm-support/vue-gtm",
        "vue3-google-map",
        "vue3-slide-verify",
        "qrcanvas",
      ],
    },
    // SSR 打包时被内联进产物，而不是被当成外部依赖由 Node 直接加载
    ssr: {
      noExternal: ["@popperjs/core", "element-plus"],
    },
    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/',
          // target: "http://xinke-alb-1217859923.ap-southeast-1.elb.amazonaws.com:18001",
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ""),
        },
      },
      hmr: {
        overlay: false, // 关闭 HMR 警告/错误弹窗
      },
    },
    build: {
      rollupOptions: {
        // 开启产物文件分析
        // plugins: [visualizer({ open: true })],
      },
    },
  },
  runtimeConfig: {
    public: {
      appType,
      supplierUrl: SERVICE === 'test' ? 'http://54.46.9.88:82/user/login' : 'https://seller.njnaexport.com/user/login',
      serverPath: SERVICE === 'test' ? 'http://54.46.9.88:8001/' : 'http://xinke-alb-1217859923.ap-southeast-1.elb.amazonaws.com:18001'
    }
  },
  app: {
    head: {
      htmlAttrs: {
        lang: "en",
      },
    },
  },
});
