使用Esbuild压缩、移除Legacy插件、增加optimizeDeps、取消chunk大小计算、提高超大静态资源临界值优化打包速度

This commit is contained in:
fmk1023
2025-12-25 16:11:27 +08:00
parent 29fa1a2199
commit f3b63fdfd9

View File

@@ -3,8 +3,8 @@ import { defineConfig, type PluginOption, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import { visualizer } from "rollup-plugin-visualizer";
import dayjs from "dayjs";
import basicSSL from '@vitejs/plugin-basic-ssl';
import legacy from '@vitejs/plugin-legacy'
// import basicSSL from '@vitejs/plugin-basic-ssl';
// import legacy from '@vitejs/plugin-legacy'
const fs = require('node:fs')
export default (config: any) => {
@@ -20,10 +20,10 @@ export default (config: any) => {
}
}
}),
// 浏览器兼容性
legacy({
targets: ['defaults', 'chrome >= 78', 'safari >= 14'],
}),
// // 浏览器兼容性
// legacy({
// targets: ['defaults', 'chrome >= 78', 'safari >= 14'],
// }),
visualizer({
open: config.mode === 'analysis',
}) as PluginOption,
@@ -66,16 +66,23 @@ export default (config: any) => {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
optimizeDeps: {
include: ['vue', 'dayjs', 'axios'], // 强制预构建常用包
},
build: {
outDir: 'SAP', // 将打包后的文件夹名改为 openRepoPortal
// sourcemap: config.mode !== 'production',
minify: 'terser', // 确保使用 terser 进行压缩
terserOptions: {
compress: {
drop_console: true, // 移除 console.log
},
},
// 减少 chunk 大小计算,加快打包速度
reportCompressedSize: false,
// 提高超大静态资源临界值
assetsInlineLimit: 4096,
minify: 'esbuild',
// minify: 'terser', // 确保使用 terser 进行压缩
// terserOptions: {
// compress: {
// drop_console: true, // 移除 console.log
// },
// },
},
define: {