Add minified ESM builds and a dist size budget check - #7970
Conversation
|
The intention isn't for this to be a blocker for merging, because as @robwalch mentions in #4936 features will add bundle size to the library. But more to simply be aware of it, and start to track it. At this point, the total amount of traffic this library receives and size is enough (to me) to start to want to be aware. I set the tolerance at 2% because at the current bundle sizes that is a significant total size different of >5Kb of text (after compression). Which should be quite a large feature if the dist check in CI causes any issue, and it's very easy to change by updating the JSON file it compares against. However, like mentioned above that's my intention, and I'd rather this be a project decision. I'm revisiting this because over the last year, jsdelivr served hls.js for 10PB of traffic. That's pretty nuts to me 🙂 |
This PR will...
Add minified ESM builds,
dist/hls.min.mjsanddist/hls.light.min.mjs, from two new rollup configs. Both are added to thees-checkESM group so they hold to the sameesmodules: truesyntax floor as the unminified.mjsfiles.Also adds
npm run sizeandnpm run size:check, and runs the check in CI. Budgets live indist-size-budget.jsonand are compared against brotli, since that's what CDNs serve.hls.jshls.min.jshls.mjshls.min.mjshls.light.jshls.light.min.jshls.light.mjshls.light.min.mjshls.worker.jsEvery budget is recorded at the current size, so the headroom is entirely the 2% tolerance.
Nothing changes in
main,module, orexports. The existing"./dist/*"subpath already resolves the new files.While in the README I fixed two things that were wrong: the flag is
--configType, not--env, and thedemoconfig isn't always built, it's only built when no--configTypeis passed. Also documented that the ESM builds don't inline the transmuxer Web Worker, with theworkerPathsnippet for that.Why is this Pull Request needed?
#2910 asked for ESM so modern browsers could load us from a CDN with
<script type="module">, and the naming proposal in it included minified variants. #5299 shipped one unminified target, #5484 gothls.light.mjs, and the minified ones never followed.So people are pulling them from jsDelivr anyway. In the last month
/dist/hls.min.mjson 1.6.16 took 180,597 requests for a file we don't publish, which jsDelivr generates by auto-minifyinghls.mjs(1,306,989 → 564,361 bytes served)./+esmtook another 3,840,230. That output isn't produced by our build and isn't checked byes-check.Meanwhile ~99% of file hits on 1.6.16 go to
/dist/hls.min.js. Out of 7B requests last month, effectively everyone is taking the UMD bundle and a globalHls. A real minified module is what an import map entry can point at, and it's the prerequisite for anything I'd like to do later with module-level loading.On the budget side, #3830 and #4936 both asked for size to be treated as ongoing work rather than answered once.
Are there any points in the code the reviewer needs to double check?
The tolerance is 2% and it's a judgement call, I'd rather it be the project's than mine.
Resolves issues:
Checklist