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 { fileURLToPath, URL } from 'node:url'

export default defineConfig({
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  build: {
    outDir: 'dist'
  },
  server: {
    host: '0.0.0.0',
    proxy: {
      '/api': {
          // target: 'https://test.offerpai.com.cn/',
          target: 'http://127.0.0.1:8080',
        changeOrigin: true,
      },
      '/jianshi-api': {
        target: 'https://www.jianshixingqiu.com',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/jianshi-api/, '/proxy-api'),
      },
      '/ai-api': {
          // target: 'https://test.offerpai.com.cn/',
          target: 'http://127.0.0.1:8000',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/ai-api/, ''),
      },
    },
  },
  css: {
    preprocessorOptions: {
      scss: {
        // 各 scss 文件按需 @use '../variables' as * 引入全局变量
      }
    }
  }
})