What is the size impact of importing one method from date-fns
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 take a look at the size impact of importing luxon. I'll check with both webpack & esbuild. The code Similar to the date-fns article in this series, I'm testing with a rather simple code: // import trick from https://github.com/m...
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 quick look at the build size of a simple code that imports a method from date-fns. I check results from both, webpack & esbuild.
The code I use in this test is as follows:
import { sub } from "date-fns";
const today = new Date();
console.log("Yesterday was", sub(today, { days: 1 }));
In this way, I can:
The builds are run with:
webpack --mode=production
Standard webpack build, with production mode, set explicitly.
esbuild src/index.js --outfile=dist/main.js --bundle --minify
Fairly simple esbuild command, with --minify on & required --bundle flag.
Both wepback & esbuild performed pretty much the same.
$ npm run webpack
> date-fns-bundle-size@1.0.0 webpack
> webpack --mode=production
asset main.js 1.59 KiB [compared for emit] [minimized] (name: main)
orphan modules 546 KiB [orphan] 264 modules
./src/index.js + 8 modules 11.6 KiB [built] [code generated]
webpack 5.47.1 compiled successfully in 858 ms
$ stat dist/main.js
File: dist/main.js
Size: 1633 ...
The output size is about 1.6 KiB.
$ npm run esbuild
> date-fns-bundle-size@1.0.0 esbuild
> esbuild src/index.js --outfile=dist/main.js --bundle --minify
dist/main.js 1.6kb
⚡ Done in 40ms
# stat dist/main.js
File: dist/main.js
Size: 1624 ...
The test repo I've been using in this article is here.
In this article, we have seen the isolated impact of imports of one method from date-fns. In the following articles in this series, I'll look at other popular date manipulation libraries.