What is the size impact of importing luxon - a date manipulation library
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 how much the build size increases when you add Day.js library for date object manipulation. Library Day.js is an interesting library that implements a similar API as moment.js but with a smaller overhead. Because...
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 the size impact of importing luxon. I'll check with both webpack & esbuild.
Similar to the date-fns article in this series, I'm testing with a rather simple code:
// import trick from https://github.com/moment/luxon/issues/854
import { DateTime } from "luxon/src/luxon";
console.log("Yesterday was", DateTime.now().minus({ day: 1 }).toJSDate());
The import is modified from import { DataeTime } from 'luxon'; that you can find in the documentation. It improved the build size a bit, but not enough.
For my benchmark, I build code with:
webpack --mode=production
production mode set explicitly in webpack, and
esbuild src/index.js --outfile=dist/main.js --bundle --minify
Minification on in esbuild.
Both bundlers performed similarly in regards to size; of course, esbuild is much faster.
$ webpack --mode=production
asset main.js 58.3 KiB [emitted] [minimized] (name: main)
orphan modules 217 KiB [orphan] 24 modules
./src/index.js + 23 modules 216 KiB [built] [code generated]
webpack 5.47.1 compiled successfully in 1749 ms
$ stat dist/main.js
File: dist/main.js
Size: 59710
The output size is 58.3 KiB
$ npm run esbuild
> luxon-bundle-size@1.0.0 esbuild
> esbuild src/index.js --outfile=dist/main.js --bundle --minify
dist/main.js 58.5kb
⚡ Done in 18ms
$ stat dist/main.js
File: dist/main.js
Size: 59929
The output size is 58.5KiB
You can find my test repository here.
In this article, we have seen a size impact of importing luxon to our project. Unfortunately, luxon doesn't support tree shaking, so for doing only 1 operation with it, we need to import the whole library. And for doing so, we get a serious size penalty to our project. I will not consider this library for my projects, and I'm really curious about use-cases when it's doing better than other libs discussed in this series - if you have any, please let me know in the comments.