| 1234567891011121314151617181920212223242526272829303132 |
- import compression from 'vite-plugin-compression';
- export default (env: any) => {
- // CI 可通过空值或空格关闭:VITE_BUILD_COMPRESS=
- const raw = String(env?.VITE_BUILD_COMPRESS ?? '').trim();
- const plugin: any[] = [];
- if (raw) {
- const compressList = raw.split(',').map((s: string) => s.trim()).filter(Boolean);
- if (compressList.includes('gzip')) {
- // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩静态文件
- plugin.push(
- compression({
- ext: '.gz',
- deleteOriginFile: false,
- // 小于 10KB 的分包压缩收益很小,跳过可明显缩短收尾时间
- threshold: 10 * 1024,
- verbose: false
- })
- );
- }
- if (compressList.includes('brotli')) {
- plugin.push(
- compression({
- ext: '.br',
- algorithm: 'brotliCompress',
- deleteOriginFile: false
- })
- );
- }
- }
- return plugin;
- };
|