/// <reference types="vitest" />

import path from 'node:path'
import { defineConfig } from 'vite'
import Vue from '@vitejs/plugin-vue'
import WindiCss from 'vite-plugin-windicss'
import Pages from 'vite-plugin-pages'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import AutoImport from 'unplugin-auto-import/vite'
import VueMacros from 'unplugin-vue-macros/vite'
import Icons from 'unplugin-icons/vite'
import IconsResolver from 'unplugin-icons/resolver'

export default defineConfig(({command}) => {
  const cfg = {
    base:'',
    resolve: {
      alias: {
        '~/': `${path.resolve(__dirname, 'src')}/`,
        '@': `${path.resolve(__dirname, 'src')}`,

      },
    },
    plugins: [
      VueMacros({
        plugins: {
          vue: Vue({
            reactivityTransform: true,
          }),
        },
      }),
      WindiCss(),
      // https://github.com/hannoeru/vite-plugin-pages
      Pages({ extensions: ['vue'] }),

      // https://github.com/antfu/unplugin-auto-import
      AutoImport({
        imports: [
          'vue',
          'vue/macros',
          'vue-router',
          '@vueuse/core',
        ],
        dts: true,
        dirs: [
          './src/composables',
        ],
        vueTemplate: true,
        resolvers: [ElementPlusResolver()],
      }),

      // https://github.com/antfu/vite-plugin-components
      Components({
        dts: true,
        resolvers: [ElementPlusResolver(), IconsResolver()],
      }),
      Icons({
        compiler: 'vue3',
        autoInstall: true,
      }),
      // https://github.com/antfu/unocss
      // see unocss.config.ts for config
    ],

    // https://github.com/vitest-dev/vitest
    test: {
      environment: 'jsdom',
    },
  }
  if(command === 'build') {
    cfg.base = '/webapps/page/liankao/'
    return cfg
  } else {
    return cfg
  }

})
