import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
import removeConsole from 'vite-plugin-remove-console';
import compression from 'vite-plugin-compression';

//1、 导入 path 模块，帮助我们解析路径
import { resolve } from 'path'

//2-1 自动导入vue中hook reactive ref等
import AutoImport from 'unplugin-auto-import/vite'
//2-2 自动导入ui-组件 比如说ant-design-vue  element-plus等
import Components from 'unplugin-vue-components/vite'

//3、vue3语法糖
import VueSetupExtend from 'vite-plugin-vue-setup-extend'

// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
  const config = loadEnv(mode, './');
  if (mode === 'development') console.debug('Loaded env:', config);

  return {
    base: "./",
    plugins: [
      vue(),
      removeConsole(),
      compression(),
      AutoImport({
        imports: ['vue', 'vue-router'],
        dts: "src/auto-import.d.ts",
      }),
      Components({
        dts: "src/components.d.ts",
      }),
      VueSetupExtend(),
    ],
    resolve: {
      alias: {
        '@': resolve('src'),
        '@views': resolve('src/views')
      }
    },
    server: {
      proxy: {
        '/api': {
          target: 'https://www.adicn.com/eps',
          secure: false,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, '')
        },
        '/eps': {
          target: 'https://www.adicn.com/eps',
          secure: false,
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/eps/, '')
        },
        '/file': {
          target: 'http://192.168.0.43:2201/',
          secure: false,
          changeOrigin: true,
          rewrite: path => path.replace(/^\/file/, '')
        },
        '/websocket': {
          target: 'http://192.168.0.104:8188',
          secure: false,
          changeOrigin: true
        },
      }
    },
    css: {
      preprocessorOptions: {
        scss: {
          // optional: global SCSS variables/mixins
          // additionalData: `@import "@/styles/variables.scss";`
        }
      }
    }
  };
});