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

import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import VueDevTools from 'vite-plugin-vue-devtools'
import VueSetupExtend from 'vite-plugin-vue-setup-extend'
import autoImport from 'unplugin-auto-import/vite'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from '@vant/auto-import-resolver'
const createAutoImport = () => {
  return autoImport({
    imports: ['vue', 'vue-router', 'pinia'],
    dts: false
  })
}
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const plugins = [
    vue(),
    VueSetupExtend(),
    createAutoImport(),
    AutoImport({
      resolvers: [VantResolver()]
    }),
    Components({
      resolvers: [VantResolver()]
    })
  ]
  if (mode === 'development') {
    plugins.push(VueDevTools())
  }
  return {
    plugins: plugins,
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url))
      }
    },
    server: {
      host: true,
      proxy: {
        '/dev-api': {
          target: 'http://172.16.8.74:8080/prod-api',
          // target: 'https://vue.ruoyi.vip/prod-api',
          changeOrigin: true,
          rewrite: (p) => p.replace(/^\/dev-api/, '')
        }
      }
    },
    //配置sass
    css: {
      preprocessorOptions: {
        scss: {
          additionalData:
            '@import "./src/assets/scss/globalVar.scss";@import "./src/assets/scss/globalMixin.scss";'
        }
      }
    }
  }
})
