import { defineConfig } from 'vite';
import Vue from '@vitejs/plugin-vue';
import VueJsx from '@vitejs/plugin-vue-jsx';
import VueDevTools from 'vite-plugin-vue-devtools';
import VueI18nPlugin from '@intlify/unplugin-vue-i18n/vite';
import copy from 'rollup-plugin-copy';
import UnoCSS from 'unocss/vite';
import AutoImport from 'unplugin-auto-import/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';

import path from 'node:path';
import { fileURLToPath, URL } from 'node:url';

export default defineConfig({
  plugins: [
    Vue({
      template: {
        compilerOptions: {
          isCustomElement: (tag) => {
            return tag.startsWith('un-');
          },
        },
      },
    }),
    copy({
      targets: [
        {
          src: './node_modules/libpag/lib/libpag.wasm',
          dest: process.env.NODE_ENV === 'production' ? 'dist/' : 'public/',
        },
      ],
      hook: process.env.NODE_ENV === 'production' ? 'writeBundle' : 'buildStart',
    }),
    VueJsx(),
    VueDevTools(),
    VueI18nPlugin({
      include: path.resolve(__dirname, './src/i18n/locales/**'),
    }),
    AutoImport({
      dts: false,
      resolvers: [],
    }),
    Components({
      dts: false,
      resolvers: [
        AntDesignVueResolver({
          importStyle: false, // css in js
        }),
      ],
    }),
    UnoCSS(),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
});
