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

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import checker from 'vite-plugin-checker'
import mkcert from 'vite-plugin-mkcert'

// https://vitejs.dev/config/
export default defineConfig((mode) => ({
  base: mode === 'prod' ? 'https://webapp-pub.ezijing.com/website/prod/login/' : '/',
  plugins: [
    mkcert(),
    vue(),
    AutoImport({ imports: ['vue', 'vue-router'] }),
    checker({ eslint: { lintCommand: 'eslint "./src/**/*.{vue,js,jsx,ts,tsx}"' } }),
  ],
  server: {
    open: true,
    host: 'dev.ezijing.com',
    proxy: {
      '/api': 'https://login.ezijing.com',
    },
  },
  build: {
    outDir: 'client-dist',
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
}))
