import { defineConfig, loadEnv } from 'vite' import vue from '@vitejs/plugin-vue' import path from 'path' //@ts-ignore import viteCompression from 'vite-plugin-compression' import legacy from '@vitejs/plugin-legacy' // https://vitejs.dev/config/ export default defineConfig(({ command, mode }) => { //https://blog.csdn.net/huanglgln/article/details/121635053 vite获取.env.development配置环境 // 使用 import.meta.env.VITE_APP_BASE_URL loadEnv(mode, process.cwd()) return { base: './', //打包路径 plugins: [ legacy({ // targets: ['defaults'], // 需要兼容的目标列表,可以设置多个 , 'not IE 11' // additionalLegacyPolyfills: ['regenerator-runtime/runtime'] // 面向IE11时需要此插件 }), vue(), // gzip压缩 生产环境生成 .gz 文件 viteCompression({ verbose: true, disable: false, threshold: 10240, algorithm: 'gzip', ext: '.gz', }), ], // 配置别名 resolve: { alias: { '@': path.resolve(__dirname, 'src'), '/icon': './src/assets/ioc', //图片路径别名 }, }, define: { //定义 process 'process.env': process.env, }, css: { preprocessorOptions: { scss: { //引入全局样式 additionalData: '@import "@/assets/style/mian.scss";', }, }, }, entry: { index: ['babel-polyfill', './src/main.ts'], }, //启动服务配置 server: { host: '0.0.0.0', port: 8085, open: true, // 类型: boolean | string在服务器启动时自动在浏览器中打开应用程序; cors: true, // 类型: boolean | CorsOptions 为开发服务器配置 CORS。默认启用并允许任何源 // https: false, proxy: { '/common': { target: 'https://medusa.etcjz.cn',//这里填入你要请求的接口的前缀 changeOrigin: true,//虚拟的站点需要更管origin ws: true, secure: true,//是否https接口 pathRewrite: { '^/common': ''//请求的时候使用这个api就可以 }, // rewrite: (path) => path.replace(/^\/common/, ''), //重写 }, //跨域代理 '/api': { target: process.env.VUE_APP_BASE_API, changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, ''), //重写 }, '/corporateaccount': { target: process.env.VUE_APP_BASE_API, changeOrigin: true, rewrite: (path) => path.replace(/^\/api/, ''), //重写 }, }, }, // 生产环境打包配置 //去除 console debugger build: { // target: ['chrome52'], // cssTarget: ["chrome52"], minify: 'terser', terserOptions: { compress: { //生产环境移除 console drop_console: true, drop_debugger: true, }, }, }, } })