This commit is contained in:
wood911010 committed 2025-09-05 22:22:06 +08:00
1 parent f4cd61ec75
commit ba4b34b290
3 files changed
+81 -35

No files matched your search

+1 -1
View File
@@ -1,5 +1,5 @@
# 正式环境接口地址 - 自动匹配当前域名
VITE_API_BASE_URL = '/api'
VITE_API_BASE_URL = ''
# 正式环境打包名称
VITE_OUTDIR='production'
+29 -2
View File
@@ -45,9 +45,27 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
verbose: true, // 显示压缩日志
disable: !isProd, // 非生产环境禁用
deleteOriginFile: false, // 不删除源文件
threshold: 10240, // 文件大小10KB才压缩
threshold: 1024, // 文件大小1KB才压缩(降低阈值)
algorithm: 'gzip', // 压缩算法
ext: '.gz', // 压缩文件扩展名
compressionOptions: {
level: 9, // 最高压缩级别
}
}),
// 添加Brotli压缩支持(更高效的压缩算法)
isProd && viteCompression({
verbose: true,
disable: !isProd,
deleteOriginFile: false,
threshold: 1024,
algorithm: 'brotliCompress',
ext: '.br',
compressionOptions: {
params: {
[require('zlib').constants.BROTLI_PARAM_QUALITY]: 11, // 最高质量
}
}
}),
// 打包分析插件(仅在显式启用时生效;容器/CI 默认不打开浏览器)
@@ -112,10 +130,19 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
compress: {
drop_console: isProd, // 生产环境移除console
drop_debugger: isProd, // 生产环境移除debugger
pure_funcs: isProd ? ['console.log'] : [] // 移除纯函数调用
pure_funcs: isProd ? ['console.log'] : [], // 移除纯函数调用
// 额外的压缩优化
dead_code: true, // 移除无用代码
keep_infinity: true, // 保持Infinity
toplevel: isProd, // 顶级作用域压缩
},
mangle: {
toplevel: isProd, // 顶级作用域变量名压缩
}
},
rollupOptions: { // Rollup打包配置
// 启用构建缓存以提升重复构建速度
cache: isProd, // 生产环境启用Rollup缓存
output: {
// 优化的手动分块策略
manualChunks: {