vben
authored
|
1
2
|
/**
* Used to package and output gzip. Note that this does not work properly in Vite, the specific reason is still being investigated
|
vben
authored
|
3
|
* https://github.com/anncwb/vite-plugin-compression
|
vben
authored
|
4
|
*/
|
vben
authored
|
5
|
import type { PluginOption } from 'vite';
|
vben
authored
|
6
7
|
import compressPlugin from 'vite-plugin-compression';
|
vben
authored
|
8
9
|
export function configCompressPlugin({
compress,
|
vben
authored
|
10
|
deleteOriginFile = false,
|
vben
authored
|
11
12
13
14
|
}: {
compress: string;
deleteOriginFile?: boolean;
}): PluginOption[] {
|
vben
authored
|
15
16
|
const compressList = compress.split(',');
|
vben
authored
|
17
|
const plugins: PluginOption[] = [];
|
vben
authored
|
18
19
20
21
22
|
if (compressList.includes('gzip')) {
plugins.push(
compressPlugin({
ext: '.gz',
|
|
23
|
deleteOriginFile,
|
vben
authored
|
24
|
}),
|
vben
authored
|
25
26
|
);
}
|
vben
authored
|
27
|
|
vben
authored
|
28
29
30
31
32
|
if (compressList.includes('brotli')) {
plugins.push(
compressPlugin({
ext: '.br',
algorithm: 'brotliCompress',
|
|
33
|
deleteOriginFile,
|
vben
authored
|
34
|
}),
|
vben
authored
|
35
36
37
38
|
);
}
return plugins;
}
|