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

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),    
    // require('unplugin-element-plus/webpack')(),
    // ...
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    legacy({
      polyfills: ["es.promise.finally", "es/map", "es/set"],
      targets: ["chrome<60","and_uc 9"],
      modernPolyfills: ["es.promise.finally"]
    }),
  ],
  base: '/',
  resolve: {
    alias: {
      "@": path.resolve(__dirname, "./src/"),
      // "@": path.resolve(__dirname, "src"),
    }
  },
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          hack: `true; @import (reference) "${path.resolve(__dirname, 'src/assets/config.less')}";`,
        },
        javascriptEnabled: true,
      }
    }
  },
  server: {
    proxy: {
      '/service': {
        target: 'https://test.4dkankan.com/',
        changeOrigin: true,
        // rewrite: (path) => path.replace(/^\/api/, '')
      },
      '/ucenter': {
        target: 'https://test.4dkankan.com/',
        changeOrigin: true,
        // rewrite: (path) => path.replace(/^\/api/, '')
      }
    }
 },

})