import { defineConfig } from "vite";
import Components from "unplugin-vue-components/vite";
import vuePluginsAutoI18n from "vite-plugin-auto-i18n";
import createVuePlugin from "@vitejs/plugin-vue";
import AutoImport from "unplugin-auto-import/vite";
import { VantResolver } from "unplugin-vue-components/resolvers";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import path from "path";

// / 注：vite-plugin-auto-i18n 只处理脚本文件因此对于.vue等类型文件，需要vuePlugin进行解析
const vuePlugin = createVuePlugin({
  include: [/\.vue$/],
  // 注：plugin-vue 对于静态节点默认不解析，因此这里需要下述配置
  template: {
    compilerOptions: {
      hoistStatic: false,
      cacheHandlers: false,
    },
  },
});

export default defineConfig({
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src"),
    },
  },
  plugins: [
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [VantResolver(), ElementPlusResolver()],
    }),
    vuePlugin,
    // vuePluginsAutoI18n({
    //   option: {
    //     globalPath: "./lang", // 配置文件生成位置
    //     namespace: "lang", // 命名空间
    //     targetLangList: ["en", "ko", "ja"], // 翻译目标语言
    //     originLang: "zh-cn", // 翻译源语言
    //     distPath: "./dist/assets", // 打包后生成文件位置
    //     distKey: "index", // 打包后主文件名称
    //   },
    // }),
  ],
  build: {
    outDir: "yonghu",
    rollupOptions: {
      output: {
        // 手动配置 chunks
        manualChunks: {
          vendor: ["lodash"],
        },
      },
    },
  },
  server: {
    host: "0.0.0.0",
    port: 8082,
    open: false,
    overlay: true,
  },
});
