Skip to content

Commit

Permalink
Merge pull request #1245 from didi/feat-size-report-add-pre-warning
Browse files Browse the repository at this point in the history
feat: size-report添加预警阈值功能
  • Loading branch information
Blackgan3 authored Jul 21, 2023
2 parents 348634d + 1c37d1d commit 74961fb
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/size-report/src/SizeReportPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -647,12 +647,16 @@ class SizeReportPlugin {

function checkThreshold (threshold, size, sizeInfo, reportGroupName) {
const sizeThreshold = normalizeThreshold(threshold.size || threshold)
const preWarningThreshold = normalizeThreshold(threshold.preWarningSize || threshold)
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 (packagesThreshold && sizeInfo) {
for (const packageName in sizeInfo) {
Expand Down

0 comments on commit 74961fb

Please sign in to comment.