Commit 7dac446761ecf1db8f2fad4da4a5307889a7499d
1 parent
e84ad439
feat: add gzip
Showing
2 changed files
with
11 additions
and
1 deletions
yudao-ui-admin-vue3/package.json
yudao-ui-admin-vue3/vite.config.ts
| ... | ... | @@ -11,6 +11,7 @@ import { createSvgIconsPlugin } from 'vite-plugin-svg-icons' |
| 11 | 11 | import PurgeIcons from 'vite-plugin-purge-icons' |
| 12 | 12 | import DefineOptions from 'unplugin-vue-define-options/vite' |
| 13 | 13 | import { createHtmlPlugin } from 'vite-plugin-html' |
| 14 | +import viteCompression from 'vite-plugin-compression' | |
| 14 | 15 | |
| 15 | 16 | // 当前执行node命令时文件夹的地址(工作目录) |
| 16 | 17 | const root = process.cwd() |
| ... | ... | @@ -80,11 +81,19 @@ export default ({ command, mode }: ConfigEnv): UserConfig => { |
| 80 | 81 | }), |
| 81 | 82 | PurgeIcons(), |
| 82 | 83 | DefineOptions(), |
| 84 | + viteCompression({ | |
| 85 | + verbose: true, // 是否在控制台输出压缩结果 | |
| 86 | + disable: true, // 是否禁用 | |
| 87 | + threshold: 10240, // 体积大于 threshold 才会被压缩,单位 b | |
| 88 | + algorithm: 'gzip', // 压缩算法,可选 [ 'gzip' , 'brotliCompress' ,'deflate' , 'deflateRaw'] | |
| 89 | + ext: '.gz', // 生成的压缩包后缀 | |
| 90 | + deleteOriginFile: false //压缩后是否删除源文件 | |
| 91 | + }), | |
| 83 | 92 | createHtmlPlugin({ |
| 84 | 93 | inject: { |
| 85 | 94 | data: { |
| 86 | 95 | title: env.VITE_APP_TITLE, |
| 87 | - injectScript: `<script src="./inject.js"></script>`, | |
| 96 | + injectScript: `<script src="./inject.js"></script>` | |
| 88 | 97 | } |
| 89 | 98 | } |
| 90 | 99 | }) | ... | ... |