import type { Plugin } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
import AutoImport from 'unplugin-auto-import/vite';

export function createVitePlugins(isBuild: boolean): Plugin[] {
  return [
    vue(),
    vueJsx(),
    Components({
      dirs: ['src/components'],
      extensions: ['vue'],
      deep: true,
      resolvers: [AntDesignVueResolver({
        // 用于less变更主题用
        importStyle: 'less',
        /**
         * resolve `ant-design-vue' icons
         * requires package `@ant-design/icons-vue`
         */
        resolveIcons: true
      })],
      dts: 'src/components.d.ts'
    }),
    AutoImport({
      imports: [
        'vue',
        'vue-router',
        {
          '@vueuse/core': ['useLocalStorage', 'useClipboard']
        }
      ],
      dts: 'src/auto-imports.d.ts'
    })
  ]
}
