import { UserConfig, ConfigEnv, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons';
import path from "path";
import basicSsl from '@vitejs/plugin-basic-ssl'

export default ({ mode }: ConfigEnv): UserConfig => {
  // 获取.env环境配置
  const env = loadEnv(mode, process.cwd());
  return {
    base: "/wms-sap/",
    plugins: [
      vue(),
      createSvgIconsPlugin({
        // 指定需要缓存的图标文件夹
        iconDirs: [path.resolve(process.cwd(), 'src/assets/icons')],
        // 指定symbolId格式
        symbolId: 'icon-[dir]-[name]'
      }),
      basicSsl()
    ],
    server: {
      host: '0.0.0.0',
      port: Number(env.VITE_APP_PORT),
      open: true, // 运行自动打开浏览器
      proxy: {
        ['/api']: {
          // API地址
          // 'http://192.168.200.112:17878/api'
          //   target: 'http://172.22.10.217:8086/api',  // 生产环境
        // target: 'http://192.168.1.73:32202/api',   //测试环境
        // target: 'http://localhost:18878',
          target: 'http://172.22.10.225:22212',
          changeOrigin: true,
          secure: true,
          rewrite: path =>
            path.replace(/^\/api/, '')
        },
      }
    },
    resolve: {
      // Vite路径别名配置
      alias: {
        '@': path.resolve('./src')
      }
    }
  }

};
