Fast JavaScript bundling with esbuild
Tags: javascript
Published: 2020-04-29 17:42:59

---
title: Fast JavaScript bundling with esbuild
published: true
date: 2020-04-02 17:30:07 UTC
tags: javascript
canonical_url: https://blog.logrocket.com/fast-javascript-bundling-with-esbuild/
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/x8jbijcw1dmwstiyqcft.png
---
**Written by [Ibrahima Ndaw](https://blog.logrocket.com/author/ibrahimandaw/)**✏️

[Modular programming](https://www.cs.cornell.edu/courses/cs3110/2019sp/textbook/modules/modular_programming.html) is a software design technique whereby a program’s various functions are subdivided into code modules that are developed separately. Modern programming relies heavily on modularity, which is why you need a module bundler to merge all separate files into a single one.

There are a few bundlers available in the JavaScript community, such as [WebPack](https://webpack.js.org/), [Rollup](https://rollupjs.org/guide/en/), and [Parcel](https://parceljs.org/). However, these are not fast enough because they are built with JavaScript, which, as well all know, leaves much to be desired in terms of performance. Fortunately, there is a new bundler built with Go that works faster than other bundlers.

In this guide, we’ll explore [esbuild](https://github.com/evanw/esbuild), a JavaScript bundler and minifier that packages JS code for distribution on the web. We’ll examine how it’s able to work so fast and discuss why you should keep an eye on this tool in 2020 and beyond.

[![LogRocket Free Trial Banner](https://i0.wp.com/blog.logrocket.com/wp-content/uploads/2017/03/f760c-1gpjapknnuyhu8esa3z0jga.png?resize=1200%2C280&ssl=1)](https://logrocket.com/signup/)

## What is esbuild, and why is it so fast?

esbuild is a JavaScript bundler created by [Evan Wallace](https://twitter.com/evanwallace). The code itself is written in Go with speed in mind, and it’s clear that the developer endeavored to avoid unnecessary allocations as much as possible.

## Comparing esbuild to other bundlers (Benchmark)

esbuild fully parallelizes parsing, printing, and source map generation. All these features combine to make esbuild extremely fast. That said, to help you choose the best bundler for your next JavaScript project, let’s compare esbuild to other tools on the market.

To benchmark these bundlers, I’ll use the same criteria Wallace published to his [GitHub repo](https://github.com/evanw/esbuild). These figures may vary somewhat depending on the computer, but not by much.

The use case here is to duplicate the [Three.js](https://threejs.org/) library 10 times and bundle it into one single file without any caches. The tests were done on a six-core 2019 MacBook Pro with 16gb of RAM.

![Benchmark Comparison of JavaScript Bundlers](https://i1.wp.com/blog.logrocket.com/wp-content/uploads/2020/03/javascript-bundler-benchmarking.png?resize=655%2C229&ssl=1)

The result of the benchmarking is mind-blowing: esbuild is 10 to 100 times faster than other bundlers, thanks to the [Go language](https://dev.to/bnevilleoneill/functional-programming-in-go-46gl).

By the way, you can run this benchmark on your machine and see it for yourself. Install the [Go language toolchain](https://golang.org/doc/install) and run the following command:

```jsx
make bench-three
```

## Is esbuild production-ready?

There’s no disputing this bundler’s speed. But is it production-ready?

For now, esbuild is a small open-source project; it’s developed and maintained by one man. This is largely by design. Per the author: “I don’t personally want to run a large open-source project, so I’m not looking for contributions at this time.”

Although this will inevitably slow the development of the tool, it’s already a great bundler with robust support for common JS modules, JSX-to-JavaScript conversion, etc. However, it has yet to be used in production; doing so right now would be risky and would likely unearth some bugs.

That said, esbuild has tremendous potential to streamline the traditionally sluggish task of bundling modules in JavaScript, and it’s worth trying out in your next project.

## Conclusion

If nothing else, esbuild is proof that our current JavaScript build tools are not fast enough. Given that the gap between esbuild and other bundlers is so wide in terms of performance, I hope this tool will help improve build tools in general across the JS ecosystem.

Even if esbuild is not yet production-ready, it’s something to keep an eye on. I highly recommend checking out the [Github repo](https://github.com/evanw/esbuild) to dive deeper into the documentation.

* * * 
## Plug: [LogRocket](https://logrocket.com/signup/), a DVR for web apps
 
![LogRocket Dashboard Free Trial Banner](https://i2.wp.com/blog.logrocket.com/wp-content/uploads/2017/03/1d0cd-1s_rmyo6nbrasp-xtvbaxfg.png?resize=1200%2C677&ssl=1)
 
[LogRocket](https://logrocket.com/signup/) is a frontend logging tool that lets you replay problems as if they happened in your own browser. Instead of guessing why errors happen, or asking users for screenshots and log dumps, LogRocket lets you replay the session to quickly understand what went wrong. It works perfectly with any app, regardless of framework, and has plugins to log additional context from Redux, Vuex, and @ngrx/store.
 
In addition to logging Redux actions and state, LogRocket records console logs, JavaScript errors, stacktraces, network requests/responses with headers + bodies, browser metadata, and custom logs. It also instruments the DOM to record the HTML and CSS on the page, recreating pixel-perfect videos of even the most complex single-page apps.
 
[Try it for free](https://logrocket.com/signup/).
* * *

The post [Fast JavaScript bundling with esbuild](https://blog.logrocket.com/fast-javascript-bundling-with-esbuild/) appeared first on [LogRocket Blog](https://blog.logrocket.com).