import fs from 'node:fs'
import path from 'node:path'
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'

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