feat: add gzip

This commit is contained in:
xingyu 2022-07-20 16:47:51 +08:00
parent e84ad439a4
commit 7dac446761
2 changed files with 11 additions and 1 deletions

View File

@ -93,6 +93,7 @@
"typescript": "4.7.4",
"unplugin-vue-define-options": "^0.6.2",
"vite": "3.0.2",
"vite-plugin-compression": "^0.5.1",
"vite-plugin-eslint": "^1.7.0",
"vite-plugin-html": "^3.2.0",
"vite-plugin-purge-icons": "^0.8.1",

View File

@ -11,6 +11,7 @@ import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import PurgeIcons from 'vite-plugin-purge-icons'
import DefineOptions from 'unplugin-vue-define-options/vite'
import { createHtmlPlugin } from 'vite-plugin-html'
import viteCompression from 'vite-plugin-compression'
// 当前执行node命令时文件夹的地址工作目录
const root = process.cwd()
@ -80,11 +81,19 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
}),
PurgeIcons(),
DefineOptions(),
viteCompression({
verbose: true, // 是否在控制台输出压缩结果
disable: true, // 是否禁用
threshold: 10240, // 体积大于 threshold 才会被压缩,单位 b
algorithm: 'gzip', // 压缩算法,可选 [ 'gzip' , 'brotliCompress' ,'deflate' , 'deflateRaw']
ext: '.gz', // 生成的压缩包后缀
deleteOriginFile: false //压缩后是否删除源文件
}),
createHtmlPlugin({
inject: {
data: {
title: env.VITE_APP_TITLE,
injectScript: `<script src="./inject.js"></script>`,
injectScript: `<script src="./inject.js"></script>`
}
}
})