import legacy from '@vitejs/plugin-legacy';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'node:path';
import UnoCSS from 'unocss/vite';
import { FileSystemIconLoader } from 'unplugin-icons/loaders';
import IconsResolver from 'unplugin-icons/resolver';
import Icons from 'unplugin-icons/vite';
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers';
import Components from 'unplugin-vue-components/vite';
import { defineConfig } from 'vite';
// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    legacy({
      targets: ['defaults', 'Chrome >= 100', 'Edge >= 100', 'FireFox >= 110'],
      modernPolyfills: true,
    }),
    vue(),
    Components({
      resolvers: [
        ElementPlusResolver(),
        IconsResolver({
          prefix: 'icon',
          enabledCollections: ['ep'],
          customCollections: ['cs'],
        }),
      ],
      globs: [
        '!./src/components/*.vue',
        '!./src/components/**/*.vue',
        '!./src/views/*.vue',
        '!./src/views/**/*.vue',
      ],
    }),
    Icons({
      autoInstall: true,
      customCollections: {
        cs: FileSystemIconLoader('./src/assets/icons'),
      },
    }),
    UnoCSS(),
  ],
  resolve: {
    alias: {
      '@': resolve('./src'),
    },
  },
  server: {
    host: '0.0.0.0',
    port: 18081,
  },
});
