mirror of
https://github.com/vbenjs/vue-vben-admin.git
synced 2025-08-27 14:13:40 +08:00
feat: added brotli|gzip compression and related test commands
This commit is contained in:
29
build/vite/plugin/compress.ts
Normal file
29
build/vite/plugin/compress.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
/**
|
||||
* Used to package and output gzip. Note that this does not work properly in Vite, the specific reason is still being investigated
|
||||
*/
|
||||
import type { Plugin } from 'vite';
|
||||
|
||||
import compressPlugin from 'vite-plugin-compression';
|
||||
|
||||
export function configCompressPlugin(compress: 'gzip' | 'brotli' | 'none'): Plugin | Plugin[] {
|
||||
const compressList = compress.split(',');
|
||||
|
||||
const plugins: Plugin[] = [];
|
||||
|
||||
if (compressList.includes('gzip')) {
|
||||
plugins.push(
|
||||
compressPlugin({
|
||||
ext: '.gz',
|
||||
})
|
||||
);
|
||||
}
|
||||
if (compressList.includes('brotli')) {
|
||||
plugins.push(
|
||||
compressPlugin({
|
||||
ext: '.br',
|
||||
algorithm: 'brotliCompress',
|
||||
})
|
||||
);
|
||||
}
|
||||
return plugins;
|
||||
}
|
@@ -1,17 +0,0 @@
|
||||
/**
|
||||
* Used to package and output gzip. Note that this does not work properly in Vite, the specific reason is still being investigated
|
||||
*/
|
||||
import type { Plugin } from 'vite';
|
||||
|
||||
import gzipPlugin from 'rollup-plugin-gzip';
|
||||
import { isBuildGzip } from '../../utils';
|
||||
|
||||
export function configGzipPlugin(isBuild: boolean): Plugin | Plugin[] {
|
||||
const useGzip = isBuild && isBuildGzip();
|
||||
|
||||
if (useGzip) {
|
||||
return gzipPlugin();
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
@@ -9,14 +9,14 @@ import { ViteEnv } from '../../utils';
|
||||
import { configHtmlPlugin } from './html';
|
||||
import { configPwaConfig } from './pwa';
|
||||
import { configMockPlugin } from './mock';
|
||||
import { configGzipPlugin } from './gzip';
|
||||
import { configCompressPlugin } from './compress';
|
||||
import { configStyleImportPlugin } from './styleImport';
|
||||
import { configVisualizerConfig } from './visualizer';
|
||||
import { configThemePlugin } from './theme';
|
||||
import { configImageminPlugin } from './imagemin';
|
||||
|
||||
export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
|
||||
const { VITE_USE_IMAGEMIN, VITE_USE_MOCK, VITE_LEGACY } = viteEnv;
|
||||
const { VITE_USE_IMAGEMIN, VITE_USE_MOCK, VITE_LEGACY, VITE_BUILD_COMPRESS } = viteEnv;
|
||||
|
||||
const vitePlugins: (Plugin | Plugin[])[] = [
|
||||
// have to
|
||||
@@ -52,7 +52,7 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
|
||||
VITE_USE_IMAGEMIN && vitePlugins.push(configImageminPlugin());
|
||||
|
||||
// rollup-plugin-gzip
|
||||
vitePlugins.push(configGzipPlugin(isBuild));
|
||||
vitePlugins.push(configCompressPlugin(VITE_BUILD_COMPRESS));
|
||||
|
||||
// vite-plugin-pwa
|
||||
vitePlugins.push(configPwaConfig(viteEnv));
|
||||
|
Reference in New Issue
Block a user