doesdev / rollup-plugin-analyzer

Mad metrics for your rollup bundles, know all the things

Home Page:http://rollup-plugin-analyzer.doesdev.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Output is off by a few bytes

politician opened this issue · comments

-----------------------------
Rollup File Analysis
-----------------------------
bundle size:    68.771 KB
original size:  123.56 KB
code reduction: 44.34 %
module count:   79
% ls -l index.js    
-rw-r--r--  1 romain  staff  71134  9 Jul 17:10 index.js

71134 bytes / 1024 = 69,466796875 KB
How did we get to 68.771 KB ? Am I missing something or is this an issue?

So it's actually off a bit more than that as we report on the decimal size (1000b === 1KB) rather than binary (1024 === 1KB).

Now, as for the why. This module is geared towards the details of the individual modules that make up the bundle and their relative impact to bundle size. That's a detailed way of saying, it doesn't really care about size on disk. There are alternatives that do focus on disk size which I would recommend if that's the primary goal of your usage.

In particular rollup-plugin-size-snapshot seems like a great option for that.

Getting a bit further into the details, rather than just intent, of why the reported size differs from that on disk. We get the module data from Rollup which reports it after chunk (module) resolution and tree-shaking, but before post-processing (such as minification and compression). We then add the sizes of each of those modules together, this is the bundle size that we report.

That means it won't account for post-processing from other plugins and also won't account for post-processing by Rollup itself, which includes boilerplate / shims depending on what the output format is (CJS, ESM, iife, etc...).

So, I'm going to leave this opened (and pinned) for now until I have the time to link to it in the Readme to provide that additional context.

Thank you for the explanation.

Thanks again for your interest and effort digging into this. I've updated the README with the above information and am closing this.