AboutBlogContact
FrontendMarch 12, 2021 2 min read 27

SWC and esbuild: The End of Slow Bundling (2021)

AunimedaAunimeda
📋 Table of Contents

SWC and esbuild: The End of Slow Bundling

For years, we've accepted that a large React or Vue project takes minutes to build. We've optimized Webpack, we've used babel-loader with caching, we've tried thread-loader. But the bottleneck remains: JavaScript. Compiling JavaScript using JavaScript is inherently slower than using a compiled language.

In 2021, two new players are changing the game: esbuild (written in Go) and SWC (written in Rust).

esbuild: The Performance King

esbuild is so fast it feels like a mistake. It's often 10x to 100x faster than Webpack or Rollup. It handles TypeScript and JSX out of the box.

# Example bundling a massive project
npx esbuild app.jsx --bundle --minify --sourcemap --outfile=out.js
# Time: ~0.05 seconds

The secret to esbuild's speed is its use of Go's parallelism and careful memory management. It avoids many of the GC (Garbage Collection) pauses that plague Node-based tools.

SWC: The Rust Alternative to Babel

SWC (Speedy Web Compiler) is aiming to be a drop-in replacement for Babel. It's built in Rust and powers Next.js 12.

Example .swcrc configuration:

{
  "jsc": {
    "parser": {
      "syntax": "typescript",
      "tsx": true
    },
    "target": "es2015"
  },
  "minify": true
}

The New Architecture: Vite and Next.js

We are seeing a massive shift in meta-frameworks. Vite uses esbuild for dependency pre-bundling and development, which is why your dev server starts in less than 300ms. Next.js has replaced Babel with SWC, cutting build times by 3x on large projects.

Transitioning

If you are starting a new project in 2021, you shouldn't be using Babel directly. Whether it's through Vite, Snowpack, or the new Next.js, your toolchain should be powered by Rust or Go.

Wait times are a choice. In 2021, we choose to build instantly.

Read Also

Vue 3: Migration and the New Composition API (2018)aunimeda
Frontend

Vue 3: Migration and the New Composition API (2018)

Vue 3 is on the horizon. In 2018, we're already seeing the future of component organization with the Composition API.

AngularJS: Mastering the Directive Lifecycle and Scope (2014)aunimeda
Frontend

AngularJS: Mastering the Directive Lifecycle and Scope (2014)

Directives are the soul of AngularJS. In 2014, we're diving deep into compile, link, and the mysterious Digest Cycle.

MooTools 1.0: Elegant Prototypal Inheritance (2006)aunimeda
Frontend

MooTools 1.0: Elegant Prototypal Inheritance (2006)

Is Prototype.js too messy for you? Enter MooTools. Learn how to use its powerful Class system and Mutators to build structured JavaScript applications.

Need IT development for your business?

We build websites, mobile apps and AI solutions. Free consultation.

Get Consultation All articles