关闭按需 Element Plus 样式与构建期 dts、限制 rollup 并行、CI 跳过 gzip; 新增 npm run build:ci,供 Drone 在小内存机器上打包。 Co-authored-by: Cursor <cursoragent@cursor.com>
33 lines
960 B
TypeScript
33 lines
960 B
TypeScript
import compression from 'vite-plugin-compression';
|
|
|
|
export default (env: any) => {
|
|
// CI 可通过空值或空格关闭:VITE_BUILD_COMPRESS=
|
|
const raw = String(env?.VITE_BUILD_COMPRESS ?? '').trim();
|
|
const plugin: any[] = [];
|
|
if (raw) {
|
|
const compressList = raw.split(',').map((s: string) => s.trim()).filter(Boolean);
|
|
if (compressList.includes('gzip')) {
|
|
// http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩静态文件
|
|
plugin.push(
|
|
compression({
|
|
ext: '.gz',
|
|
deleteOriginFile: false,
|
|
// 小于 10KB 的分包压缩收益很小,跳过可明显缩短收尾时间
|
|
threshold: 10 * 1024,
|
|
verbose: false
|
|
})
|
|
);
|
|
}
|
|
if (compressList.includes('brotli')) {
|
|
plugin.push(
|
|
compression({
|
|
ext: '.br',
|
|
algorithm: 'brotliCompress',
|
|
deleteOriginFile: false
|
|
})
|
|
);
|
|
}
|
|
}
|
|
return plugin;
|
|
};
|