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

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueDevTools from 'vite-plugin-vue-devtools'
import Components from 'unplugin-vue-components/vite'
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers'

// https://vite.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    vueDevTools(),
    Components({
      resolvers: [
        AntDesignVueResolver({
          importStyle: false, // css in js
        }),
      ],
    }),
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url)),
    },
  },
  server: {
    proxy: {
      // http://8.130.28.21:31090
      // https://api.radar-power.asia:4443
      '/wap': {
        target: 'https://radar-power.cn',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path,
      },
      '/portal-service-server': {
        target: 'https://radar-power.cn',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path,
      },
      '/pub': {
        target: 'https://radar-power.cn',
        changeOrigin: true,
        secure: false,
        rewrite: (path) => path,
      },
    },
    cors: true,
  },
})
