Off the back of this discussion we should probably consider adding the gzipped size to the --stat output, to better reflect the network cost of importing packages.
This package should prove useful: https://www.npmjs.com/package/gzip-size
We should also consider showing different compression algorithms like brotli.
@kristoferbaxter any interest in adding a JS interface to @ampproject/filesize? I'd love if we could leverage what it's already doing to power our output
There's a "secret" API present within the package. Happy to expose it more directly (its published as an ES module when released dist/api.mjs).
https://github.com/ampproject/filesize/blob/master/src/api.ts
At the minimum, I'd use the same approach it leverages for compression (https://github.com/ampproject/filesize/blob/master/src/compress.ts). This splits up work across as many cores as you'll allow and uses the native implementation of Brotli and Gzip within Node.
Can I give a shot to this with gzip-size?
Is the output formatting OK like this?

@rajasegar Looking great! Do you think you'd be able to implement brotli sizes as well?
Sure why not, do have any package in mind that give the brotli size just like gzip-size. I found two
With Brotli size: using brotli-fsize

The value of brotli-size and gzip-size is quite minimal at this point. I'd just write it directly. Especially if you're already grabbing the default size off the fs.
Brotli (https://github.com/ampproject/filesize/blob/master/src/compress.ts#L89)
Gzip (https://github.com/ampproject/filesize/blob/master/src/compress.ts#L95)
One question , if we are using the native zlib api for brotliCompressSync we need to specify the node engine >= 11 in our package.json right? Otherwise it would error out for older node version. Currently we don't have any engine specification in our package.json.
Hmm, we still support Node v10 (in our test suite) and we should for a little while longer. But I'd be fine with skipping this behavior for Node if (zlib.brotliCompress) {
// run brotliCompress on the file, report its output
} else {
// skip
}
Makes sense to me. Will update the PR accordingly.
I think I completely forget about the integration tests here
https://github.com/pikapkg/snowpack/tree/master/test/integration/stat-output
How are we going to handle it for old (< 11) and newer (>= 11) versions of node?
Will it make sense to show brotli stats with an option from cli like --brotli
snowpack --stat
✔ snowpack installed: htm, preact. [0.15s]
⦿ web_modules/
├─ htm.js [1.29 KB] [ gzip: 0.68 KB ]
└─ preact.js [9.21 KB] [ gzip: 3.69 KB ]
will only show file size and gzip stats where as
snowpack --stat --brotli
✔ snowpack installed: htm, preact. [0.15s]
⦿ web_modules/
├─ htm.js [1.29 KB] [ gzip: 0.68 KB ] [ brotli: 0.62 KB ]
└─ preact.js [9.21 KB] [ gzip: 3.69 KB ] [ brotli: 3.38 KB ]
will only show file size, gzip stats and brotli stats ( if brotli compression is available in node)
Also, the --stat flag is missing from cli help, should I create a new issue for that?
Native Brotli support was also backported to the 10.x LTS line. You could require >= 10.16 and avoid additional logic.
I think specifying node >= 10.16 sounds like a reasonable compromise.
@rajasegar if @FredKSchott agrees with the above, you should be free to keep brotli output as the default when running with --stat
Also, the --stat flag is missing from cli help, should I create a new issue for that?
Good spot! I'd be happy for you to include it as part of your current PR if you'd like, else feel free to create a new issue.
@kristoferbaxter oh that's great! If Brotli was back-ported to Node v10, then every version in our test suite should include Brotli support and you should be fine / not be blocked by testing.
It's good to keep the check for support if it's not too much work, just in case.
@alex-saunders Created a new issue for --stat option in help
Is there a way to actually produce the .gz and .br packages in web_modules/ using the install command? Something like npx snowpack install --with-gz --with-br or by config option?
Nope, sorry! This is purely for logging purposes.
If we ever ship a programatic JS API for the install command, you could run brotli/gzip after-the-fact on every installed file.
Most helpful comment
The value of
brotli-sizeandgzip-sizeis quite minimal at this point. I'd just write it directly. Especially if you're already grabbing the default size off the fs.Brotli (https://github.com/ampproject/filesize/blob/master/src/compress.ts#L89)
Gzip (https://github.com/ampproject/filesize/blob/master/src/compress.ts#L95)