From df06baeb434e69f868f30f43a6949ab4a58d2cd9 Mon Sep 17 00:00:00 2001 From: xuegan Date: Thu, 14 Sep 2023 10:55:03 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E8=B0=83=E6=95=B4size=20report=20preWarni?= =?UTF-8?q?ngSize=20=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/size-report/README.md | 7 +++++-- packages/size-report/src/SizeReportPlugin.js | 6 +++--- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/packages/size-report/README.md b/packages/size-report/README.md index 5f92bd7c92..90fdcbf31e 100644 --- a/packages/size-report/README.md +++ b/packages/size-report/README.md @@ -64,8 +64,11 @@ const MpxSizeReportPlugin = require('@mpxjs/size-report') }, { name: 'pageGroup', - // 每个分组中可分别配置阈值,如果不配置则表示 - threshold: '500KB', + // 每个分组中可分别配置阈值,如果不配置则表示没任何限制 + threshold: { + size: '500KB', + preWarningSize: true// 可选项,开启分组体积阈值预警,会以warning的形式在每次构建后输出当前分组的剩余体积 + }, entryRules: { include: ['src/pages/index', 'src/pages/user'] } diff --git a/packages/size-report/src/SizeReportPlugin.js b/packages/size-report/src/SizeReportPlugin.js index a09ec553c9..f388f4d215 100644 --- a/packages/size-report/src/SizeReportPlugin.js +++ b/packages/size-report/src/SizeReportPlugin.js @@ -656,15 +656,15 @@ class SizeReportPlugin { function checkThreshold (threshold, size, sizeInfo, reportGroupName) { const sizeThreshold = normalizeThreshold(threshold.size || threshold) - const preWarningThreshold = normalizeThreshold(threshold.preWarningSize || threshold) + const preWarningSize = threshold.preWarningSize const packagesThreshold = threshold.packages const prefix = reportGroupName ? `${reportGroupName}体积分组` : '总包' if (sizeThreshold && size && size > sizeThreshold) { compilation.errors.push(`${prefix}的总体积(${size}B)超过设定阈值(${sizeThreshold}B),共${(size - sizeThreshold) / 1024}kb,请检查!`) } - if (preWarningThreshold && size && size > preWarningThreshold) { - compilation.warnings.push(`${prefix}的总体积(${size}B)超过设定预警阈值(${preWarningThreshold}B),共${(size - preWarningThreshold) / 1024}kb,请注意!`) + if (preWarningSize && size && size < sizeThreshold) { + compilation.warnings.push(`当前${prefix}的总体积 ${size / 1024}kb,${prefix}的体积阈值为${sizeThreshold / 1024}kb, 共剩余${(sizeThreshold - size) / 1024}kb,请注意!`) } if (packagesThreshold && sizeInfo) {