Expand description
A WASM bundle size budget checker.
wasmcheck measures the raw, gzip and brotli size of .wasm
bundles, keeps a committed baseline with deltas, and fails CI when a budget
is exceeded. It is the WASM equivalent of size-limit, not a profiler:
twiggy explains why a binary is big, wasmcheck decides whether you may
merge it.
§Example
use wasmcheck::{Budget, Metric, SizeReport};
let mut budget = Budget::new();
budget.set_limit(Metric::Gzip, Some("250 KB".parse()?));
let report = SizeReport::new("app.wasm", 675_212, 240_928, 205_110);
assert!(budget.exceeded_metrics(&report).is_empty());Sizes are given as strings such as "280 KB" or "2.5 MB" and parsed into
a validated Size, so a bad budget is rejected while the config is read
instead of while a bundle is measured.
§Exit codes
The wasmcheck binary exits with 0 when every file is under budget and
1 when a budget is exceeded or an error occurred. Use
WasmCheckError::is_budget_exceeded to tell those two cases apart when
embedding the library.
Structs§
- Baseline
- The recorded sizes of every checked file, keyed by the
filesentry that selected it. - Compression
- The gzip level and brotli quality used to measure a bundle.
- Config
- The contents of a
.wasmcheck.jsonfile. - Limits
- Limits of some kind, one optional value per
Metric. - Percent
- A percentage with up to two decimal places, stored in hundredths of a
percent —
5%is500,0.5%is50. - Resolved
File - A
.wasmfile selected for checking. - Size
- A non-negative byte count.
- Size
Delta - The signed difference between a measurement and its baseline, in bytes.
- Size
Report - The raw, gzip and brotli size of one bundle, in bytes.
Enums§
- Metric
- One of the three sizes measured for every bundle.
- Threshold
- How much a bundle is allowed to grow over its baseline.
- Wasm
Check Error - Everything that can go wrong while reading a config, measuring a bundle or parsing a wasm module.
Constants§
- CONFIG_
FILE - The config file name
wasmchecklooks for when--configis not given. - DEFAULT_
BASELINE_ FILE - The baseline file name used when the config does not name one.
Functions§
- delta_
str - Formats the difference between a measured value and its baseline, e.g.
"+5.64 KB"or"±0 B". - find_
wasm_ files - The
.wasmfiles directly insidedir, sorted by path. - format_
size - Formats a byte count for humans:
"675.21 KB","1.50 MB","500 B". - resolve_
files - Decides which
.wasmfiles a run should measure. - top_
functions - The
nlargest functions in the module atpath, as(size, name)pairs sorted by descending size.