From 800d8e11ac2500e8b81f67923d6d3a4a5f039d12 Mon Sep 17 00:00:00 2001 From: april Date: Wed, 19 Jul 2023 10:56:38 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0vite-plugin-compressi?= =?UTF-8?q?on=E4=BB=A3=E7=A0=81=E5=8E=8B=E7=BC=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Former-commit-id: 7e153b8bbb58fe6aaf074a2f20f086cd3eca0002 --- package.json | 1 + vite.config.ts | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 421cf402..89ac747f 100644 --- a/package.json +++ b/package.json @@ -99,6 +99,7 @@ "unplugin-icons": "^0.16.1", "unplugin-vue-components": "^0.24.1", "vite": "^4.4.2", + "vite-plugin-compression": "^0.5.1", "vite-plugin-svg-icons": "^2.0.1", "vue-tsc": "^1.6.5 " }, diff --git a/vite.config.ts b/vite.config.ts index 6f208d78..f14d92ac 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -12,8 +12,10 @@ import IconsResolver from "unplugin-icons/resolver"; import { createSvgIconsPlugin } from "vite-plugin-svg-icons"; import UnoCSS from "unocss/vite"; - import path from "path"; + +import viteCompression from "vite-plugin-compression"; + const pathSrc = path.resolve(__dirname, "src"); export default defineConfig(({ mode }: ConfigEnv): UserConfig => { @@ -101,6 +103,15 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => { // 指定symbolId格式 symbolId: "icon-[dir]-[name]", }), + // 代码压缩 + viteCompression({ + verbose: true, // 默认即可 + disable: true, // 是否禁用压缩,默认禁用,true为禁用,false为开启,打开压缩需配置nginx支持 + deleteOriginFile: true, // 删除源文件 + threshold: 10240, // 压缩前最小文件大小 + algorithm: "gzip", // 压缩算法 + ext: ".gz", // 文件类型 + }), ], // 预加载项目必需的组件 optimizeDeps: {