import { resolve } from 'path'
import { defineConfig } from 'electron-vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
import tailwindcss from '@tailwindcss/vite'

export default defineConfig({
  main: {
    build: {
      rollupOptions: {
        input: {
          index: resolve(__dirname, 'electron/main/index.ts')
        }
      }
    }
  },
  preload: {
    build: {
      rollupOptions: {
        input: {
          index: resolve(__dirname, 'electron/preload/index.ts')
        }
      }
    }
  },
  renderer: {
    root: '.',
    build: {
      rollupOptions: {
        input: {
          index: resolve(__dirname, 'index.html')
        }
      }
    },
    resolve: {
      alias: {
        '@': resolve('src')
      }
    },
    plugins: [
      vue(),
      tailwindcss(),
      AutoImport({
        resolvers: [
          // 自动导入 Element Plus 相关函数，如：ElMessage, ElMessageBox... (带样式)
          ElementPlusResolver()
        ],
        imports: ['vue', 'vue-router', '@vueuse/core'],
        dts: 'src/types/auto-imports.d.ts' // 自动生成 auto-imports.d.ts
      }),
      Components({
        resolvers: [ElementPlusResolver()],
        dirs: ['src/components', 'src/**/components', 'src/**/components/**/*.vue'],
        dts: 'src/types/auto-components.d.ts' // 自动生成 components.d.ts
      })
    ],
    optimizeDeps: {
      include: ['vue', 'vue-router', 'axios', '@vueuse/core', 'nprogress']
    }
  }
})
