Repository navigation
Measure the initial bundle in CI and hold it to a budget - #44
Merged
Merged
Conversation
- scripts/bundle-size.mjs sums the gzip size of every script and stylesheet index.html names, compares it with config/bundle-budget.json and reports every other chunk with raw and gzip size - exit status 1 over the budget, 2 for missing or invalid input or an asset path outside the dist folder - the report is appended to the job summary when GITHUB_STEP_SUMMARY is set
The pr-checks job builds the production bundle and runs the size check against config/bundle-budget.json on every pull request and every push to main. The README describes the check and how to see the numbers locally.
The pull request check measures 448,486 bytes gzip on the CI runner, a few hundred bytes more than a local build. The limit is that number plus 10 percent, rounded up to the next 1,000 bytes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes
scripts/bundle-size.mjsmeasures the initial load: the gzip size (level 9) of every script and stylesheet thatdist/index.htmlnames, added up. It has no dependency beyond Node built-ins and refuses an asset path that would leave thedistfolder.initialGzipBytesinconfig/bundle-budget.json. The check exits 1 over the limit and the message names that file, so raising the limit is an explicit change in a pull request. Missing or invalid input exits 2.GITHUB_STEP_SUMMARYis set, in the job summary. They are not budgeted.pr-checksjob gets two steps afterChecks:Build UI for the bundle sizeandBundle size. It runs on every pull request and every push tomain. The smoke workflow and the required checks are unchanged.How the limit was set
The limit is the measured initial load times 1.10, rounded up to the next 1,000 bytes. The local build measures 448,089 bytes gzip (242,892 script, 205,197 stylesheet), which gives 493,000.
How it is tested
scripts/bundle-size.test.mjscovers parsing of quoted and unquoted attributes, the sum, the comparison, the refusal of a path outsidedist, the exit codes 0, 1 and 2 through the command line, and the Markdown summary. The check was also run on the real build, and with a limit 1,000 bytes below the measurement it exits 1.