Blame view

internal/vite-config/src/plugins/compress.ts 882 Bytes
1
2
/**
 * Used to package and output gzip. Note that this does not work properly in Vite, the specific reason is still being investigated
3
 * https://github.com/anncwb/vite-plugin-compression
4
 */
vben authored
5
import type { PluginOption } from 'vite';
6
7
import compressPlugin from 'vite-plugin-compression';
8
9
export function configCompressPlugin({
  compress,
vben authored
10
  deleteOriginFile = false,
11
12
13
14
}: {
  compress: string;
  deleteOriginFile?: boolean;
}): PluginOption[] {
15
16
  const compressList = compress.split(',');
vben authored
17
  const plugins: PluginOption[] = [];
18
19
20
21
22

  if (compressList.includes('gzip')) {
    plugins.push(
      compressPlugin({
        ext: '.gz',
23
        deleteOriginFile,
vben authored
24
      }),
25
26
    );
  }
27
28
29
30
31
32
  if (compressList.includes('brotli')) {
    plugins.push(
      compressPlugin({
        ext: '.br',
        algorithm: 'brotliCompress',
33
        deleteOriginFile,
vben authored
34
      }),
35
36
37
38
    );
  }
  return plugins;
}