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

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  },
  server: {
    host: '0.0.0.0',
    port: 8088,
    open: false,
    cors: true,
    // 关键修正：将proxy移到server内部
    proxy: {
      '/api': {
        target: 'http://10.97.245.96', // 后端API地址
        changeOrigin: true, // 重要：模拟同源请求
        // 可选：如果后端接口本身不带/api前缀，需要去掉
        // rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
  }
})