Files
1818web_web/vite.config.js
2026-02-13 18:30:18 +08:00

69 lines
1.9 KiB
JavaScript

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { resolve } from 'path'
import basicSsl from '@vitejs/plugin-basic-ssl'
// https://vite.dev/config/
export default defineConfig({
plugins: [vue(), basicSsl()],
resolve: {
alias: {
'@': resolve(__dirname, 'src')
}
},
optimizeDeps: {
include: ['mp4box'],
esbuildOptions: {
// 设置全局变量以支持 CommonJS 模块
define: {
global: 'globalThis'
}
}
},
build: {
// 生产环境构建配置
minify: 'terser', // 使用 terser 进行代码压缩
terserOptions: {
compress: {
// 移除 console.*
drop_console: true,
// 移除 debugger
drop_debugger: true,
// 移除未使用的代码
pure_funcs: ['console.log', 'console.info', 'console.debug', 'console.warn']
}
},
// 确保CSS按正确顺序打包
cssCodeSplit: false,
rollupOptions: {
output: {
// 确保关键的CSS文件优先级
manualChunks: {
'element-plus': ['element-plus'],
'vue3-puzzle-vcode': ['vue3-puzzle-vcode']
}
}
}
},
server: {
host: '0.0.0.0', // 允许通过IP地址访问
// https: true,
proxy: {
'/user': {
target: 'http://127.0.0.1:8082', // 使用本地开发服务器
// target: 'http://101.35.131.61:8082',
changeOrigin: true,
rewrite: (path) => path.replace(/^\/user/, '/user'),
// 如果必须使用生产服务器,可以添加以下配置防护
configure: (proxy, options) => {
proxy.on('proxyRes', (proxyRes, req, res) => {
// 移除可能导致浏览器弹出认证对话框的响应头
if (proxyRes.statusCode === 401) {
delete proxyRes.headers['www-authenticate']
}
})
}
}
}
}
})