vue-vben-admin/build/vite/plugin/compress.ts

36 lines
868 B
TypeScript
Raw Normal View History

/**
* Used to package and output gzip. Note that this does not work properly in Vite, the specific reason is still being investigated
* https://github.com/anncwb/vite-plugin-compression
*/
2022-02-28 00:21:26 +08:00
import type { PluginOption } from 'vite';
import compressPlugin from 'vite-plugin-compression';
export function configCompressPlugin(
compress: 'gzip' | 'brotli' | 'none',
2021-08-24 22:41:48 +08:00
deleteOriginFile = false,
2022-02-28 00:21:26 +08:00
): PluginOption | PluginOption[] {
const compressList = compress.split(',');
2022-02-28 00:21:26 +08:00
const plugins: PluginOption[] = [];
if (compressList.includes('gzip')) {
plugins.push(
compressPlugin({
ext: '.gz',
deleteOriginFile,
2021-08-24 22:41:48 +08:00
}),
);
}
2021-08-24 22:32:43 +08:00
if (compressList.includes('brotli')) {
plugins.push(
compressPlugin({
ext: '.br',
algorithm: 'brotliCompress',
deleteOriginFile,
2021-08-24 22:41:48 +08:00
}),
);
}
return plugins;
}