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