van
van copied to clipboard
use size-limit to track gzip size of the van
I did some work on the https://github.com/nanostores/nanostores library. The library author wrote the size-limit
library to track the gzip size of the library as changes are made. It's been useful for contributors to optimize the size of the library & to track the size impact of changes.
npm test:size
# or
size-limit
devDependencies
∋ size-limit
∋ @size-limit/preset-small-lib
In publish.sh
, there is a step to generate the .min.js.gz
file along with the .min.js
file (although the .min.js.gz
is ignored by git thus not part of the repo):
https://github.com/vanjs-org/van/blob/d5c60765ef62d43fedeb6a588a40e2bf0a3946a5/src/publish.sh#L17
Every release (indeed for every meaningful change to van.js
), we're looking at the size of .min.js.gz
file to assess the size impact.
I am not sure whether the extra benefit of size-limit
library could outweigh the overhead of adding one more dev dependency.
It's beneficial for contributors to have an automated test suite that runs before commits. Something like size-limit
hooks into the test suite to ensure that the gzip size is not exceeded. Notice that the current size is in package.json
under the size-limit
prop. The commit author can increase/decrease the size-limit as needed. This encodes the current size into the project commit history, so we have a record of size changes in the commit history.
I'm not concerned either way what tech is used. But just wanted to point out the utility of the DX.
Thanks @btakita for introducing the benefit! However, I noticed that the current limit in the package.json
file (1009B) does not align with the size of the .min.js.gz
file that I'm tracking (which is 970B at the moment). Maybe size-limit
is using a different way of minifying and compressing JavaScript code that results in slightly larger size.
I'm okay with manually tracking the size changes for now (in every release announcement, I talked about the size impact if there is any). If there are tools that help automate the process, I'm open to it, but the result from the tool needs to align with the actual size we're getting for VanJS.
I think the npm script will have to run the build & call size-limit on the build output.
I updated the branch to run size-limit on public/van-latest.min.js
. The size is 962 B
. npm test
now runs (cd ./src; ./publish.sh) && npm run test:size
publish.sh
did not work on my Arch system so I updated the script to work on Linux. Hopefully it's compatible w/ OSX.