Skip to content

Commit

Permalink
Merge pull request #1266 from didi/feat-size-report-change-prewarn-logic
Browse files Browse the repository at this point in the history
feat:调整size report preWarningSize 逻辑
  • Loading branch information
hiyuki authored Sep 19, 2023
2 parents dcf6f00 + e235190 commit bf711b3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions packages/size-report/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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']
}
Expand Down
6 changes: 3 additions & 3 deletions packages/size-report/src/SizeReportPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit bf711b3

Please sign in to comment.