import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
  plugins: [vue()],
  // 生产环境基础路径（服务器访问根目录，必须写 ./）
  base: './',
  resolve: {
    alias: {
      '@': '/src'
    }
  },
  // 优化依赖配置
  optimizeDeps: {
    include: ['vue', 'axios', 'ant-design-vue', 'xlsx', 'marked', 'highlight.js', 'docx-preview', 'file-saver', 'epubjs']
  },
  // 本地开发代理（仅本地生效，打包后自动忽略）
  server: {
    port: 5173,
    strictPort: false,
    host: 'localhost',
    proxy: {
      '/api': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        configure: (proxy) => {
          proxy.on('proxyReq', (proxyReq) => {
            proxyReq.setTimeout(0)
          })
        },
        proxyTimeout: 0
      },
      '/exam': {
        target: 'http://localhost:8080',
        changeOrigin: true,
        configure: (proxy) => {
          proxy.on('proxyReq', (proxyReq) => {
            proxyReq.setTimeout(0)
          })
        },
        proxyTimeout: 0
      }
    }
  }
})
