/* * @Author: shuishen 1109946754@qq.com * @Date: 2024-10-25 10:56:27 * @LastEditors: shuishen 1109946754@qq.com * @LastEditTime: 2024-11-01 11:15:36 * @FilePath: \bigScreen\vite.config.js * @Description: * * Copyright (c) 2024 by shuishen, All Rights Reserved. */ import { defineConfig, loadEnv } from 'vite' import { resolve } from 'path' import vue from '@vitejs/plugin-vue' import DC from "@dvgis/vite-plugin-dc" import AutoImport from 'unplugin-auto-import/vite' import basicSsl from '@vitejs/plugin-basic-ssl' import { fa } from 'element-plus/es/locales.mjs' export default ({ mode, command }) => { const env = loadEnv(mode, process.cwd()) const { VITE_APP_ENV, VITE_APP_BASE } = env // 判断是打生产环境包 const isProd = VITE_APP_ENV === 'production' // 根据是否生产环境,动态设置压缩配置 const buildConfig = { outDir: 'zhyq', target: 'esnext', minify: isProd ? 'terser' : 'esbuild', // 根据环境选择压缩工具 } // 如果是生产环境,添加Terser的配置 if (isProd) { buildConfig.terserOptions = { compress: { drop_console: true, // 删除 console drop_debugger: true, // 删除 debugger }, format: { comments: false, // 删除所有注释 }, } } return defineConfig({ base: VITE_APP_BASE, build: buildConfig, plugins: [ vue(), DC(), basicSsl(), AutoImport({ imports: ["vue", "vue-router"], // 自动导入vue和vue-router相关函数 }) ], css: { preprocessorOptions: { scss: { api: 'modern-compiler', // 修改api调用方式 additionalData: `@use "@/styles/variables.scss" as *;` } } }, resolve: { alias: { '~': resolve(__dirname, './'), '@': resolve(__dirname, './src'), components: resolve(__dirname, './src/components'), styles: resolve(__dirname, './src/styles'), utils: resolve(__dirname, './src/utils'), store: resolve(__dirname, './src/store'), hooks: resolve(__dirname, './src/hooks'), }, }, server: { port: 668, https: true, host: '0.0.0.0', // hmr:{ // overlay:false // }, proxy: { '/zhyq/mx': { // target: 'http://localhost', target: 'https://wrj.shuixiongit.com/zhyq/mx', changeOrigin: true, rewrite: path => path.replace(/^\/zhyq\/mx/, ''), }, '/zhyqapi': { // target: 'http://localhost', target: 'https://wrj.shuixiongit.com/zhyqapi', changeOrigin: true, rewrite: path => path.replace(/^\/zhyqapi/, ''), }, }, }, }) } // https://vite.dev/config/