import { defineConfig } from '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 Pages from 'vite-plugin-pages'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    Pages({
      dirs: [
        { dir: 'src/page', baseRoute: '' },
        { dir: 'src/views', baseRoute: '' }
      ],
      exclude: ['**/component/*.vue'] // 排除组件
    }),
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      dts: true,
      resolvers: [ElementPlusResolver()]
    })
  ],
  resolve: {
    alias: {
      '@': path.resolve(path.resolve(), 'src')
    }
  },
  minify: 'terser',
  server: {
    open: true,
    proxy: {
      '/api': {
        // 正式环境地址
        // target: 'https://dev.wutongresearch.club/api',
        target: 'https://bizdata.wutongshucloud.com/api',
        // target: 'http://192.168.31.181:8110',
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '')
      }
    }
  }
})
