# What is the size impact of importing Day.js

In this article, I'll take a look at how much the build size increases when you add [Day.js](https://day.js.org/) library for date object manipulation. 

# Library

Day.js is an interesting library that implements a similar API as [moment.js](https://momentjs.com/) but with a smaller overhead. Because it's implementing the same [fluent interface](https://en.wikipedia.org/wiki/Fluent_interface), tree-shaking is not possible with it, but the library looks promising size-wise anyway.

# Code

The code I use in the benchmark is:
```js
import dayjs from "dayjs";

console.log("Yesterday was", dayjs().subtract(1, "day").toDate());
```

It's the same logic I have in the [luxon](https://how-to.dev/what-is-the-size-impact-of-importing-luxon-a-date-manipulation-library) & [date-fns](https://how-to.dev/what-is-the-size-impact-of-importing-one-method-from-date-fns) example.

# Build scripts

The build scripts I use are:
```sh
$ webpack --mode=production
```

```sh
$ esbuild src/index.js --outfile=dist/main.js --bundle --minify
```

# Benchmark

And the results are as follow:

## Webpack
```sh
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.

## Esbuild
```sh
$ 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.

# Links

The benchmark [repository](https://github.com/marcin-wosinek/day-js-bundle-size).

# Summary

In this article, I have shown the size impact of day.js on the build size.
