What is the size impact of importing Day.js
I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
Search for a command to run...
I'm JS developer with 13 years of professional experience. I'm always happy to teach my craft.
No comments yet. Be the first to comment.
In this series, I'll check how various date manipulation libraries perform in the build - especially in regards to output size.
In this article, I'll look at how much our application is growing when we add Moment.js. As Moment.js is not supporting tree shaking, it makes no difference if we use many or 1 methods from it. Library Moment.js is a popular but deprecated library - ...
I’ve been working in programming for the last 16 years. Let’s see what changes I see in our industry that are enabled by generative AI. Rapid prototyping The last few months, I’ve been working on a set of WordPress plugins, related to event organizat...
Writing unit tests takes time and effort. Nonetheless, many teams insist on writing them anyway—that’s because of the benefits they bring to a project. Those benefits are mainly the following: fast feedback—unit tests speed up each iteration of twea...

Pure functions are the perfect case for unit testing. For a given input, we always expect the same output—there is no internal state involved. Let’s take a look at a few examples and some simple tests that check if the methods work as expected. Jasmi...

Let’s say you have a job interview in a few days. How should you prepare for it so that you can make an informed decision about joining the company, as well as make sure that your interests are taken care of? Prepare your questions An interview is a ...

Creating example projects is a common way of showing your skills to potential employers. Let’s take a look at what’s important to keep in mind when building personal projects with an eye toward impressing prospective employers. Simplicity Building ap...

In this article, I'll take a look at how much the build size increases when you add Day.js library for date object manipulation.
Day.js is an interesting library that implements a similar API as moment.js but with a smaller overhead. Because it's implementing the same fluent interface, tree-shaking is not possible with it, but the library looks promising size-wise anyway.
The code I use in the benchmark is:
import dayjs from "dayjs";
console.log("Yesterday was", dayjs().subtract(1, "day").toDate());
It's the same logic I have in the luxon & date-fns example.
The build scripts I use are:
$ webpack --mode=production
$ esbuild src/index.js --outfile=dist/main.js --bundle --minify
And the results are as follow:
npm run webpack
> day-js-bundle-size@1.0.0 webpack
> webpack --mode=production
asset main.js 6.64 KiB [emitted] [minimized] (name: main)
runtime modules 663 bytes 3 modules
cacheable modules 6.43 KiB
./src/index.js 95 bytes [built] [code generated]
./node_modules/dayjs/dayjs.min.js 6.34 KiB [built] [code generated]
$ stat dist/main.js
File: dist/main.js
Size: 6802 ...
The build output is 6.64 KiB. The webpack build is still pretty quick, contrary to the luxon benchmark, which was noticeably slower than esbuild.
$ npm run esbuild
> day-js-bundle-size@1.0.0 esbuild
> esbuild src/index.js --outfile=dist/main.js --bundle --minify
dist/main.js 7.0kb
⚡ Done in 4ms
$ stat dist/main.js
File: dist/main.js
Size: 7191 ...
The esbuild output is 7.0KiB, which is about 5% bigger than the webpack one.
The benchmark repository.
In this article, I have shown the size impact of day.js on the build size.