mirror of
https://gitee.com/bootx/dax-pay-ui.git
synced 2025-09-06 04:09:36 +00:00
feat: added brotli|gzip compression and related test commands
This commit is contained in:
@@ -23,13 +23,6 @@ export function isReportMode(): boolean {
|
||||
return process.env.REPORT === 'true';
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to generate gzip for packaging
|
||||
*/
|
||||
export function isBuildGzip(): boolean {
|
||||
return process.env.VITE_BUILD_GZIP === 'true';
|
||||
}
|
||||
|
||||
export interface ViteEnv {
|
||||
VITE_PORT: number;
|
||||
VITE_USE_MOCK: boolean;
|
||||
@@ -40,7 +33,7 @@ export interface ViteEnv {
|
||||
VITE_GLOB_APP_SHORT_NAME: string;
|
||||
VITE_USE_CDN: boolean;
|
||||
VITE_DROP_CONSOLE: boolean;
|
||||
VITE_BUILD_GZIP: boolean;
|
||||
VITE_BUILD_COMPRESS: 'gzip' | 'brotli' | 'none';
|
||||
VITE_DYNAMIC_IMPORT: boolean;
|
||||
VITE_LEGACY: boolean;
|
||||
VITE_USE_IMAGEMIN: boolean;
|
||||
|
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