import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import tailwindcss from '@tailwindcss/vite'
import svgLoader from 'vite-svg-loader'

// https://vite.dev/config/
export default defineConfig({
  plugins: [vue(), tailwindcss(), vueDevTools(), svgLoader()],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  server: {
    proxy: {
      // 将所有以 /api 开头的请求转发到目标服务器
      // 1. 匹配所有以 /public 开头的请求
      '/api/v1': {
        target: 'https://tapi.hifast.biz/',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, ''),
        autoRewrite: true,
      },
    },
  },
})
