DEV Community

Alex Aslam
Alex Aslam

Posted on

JavaScript Setup: Import Maps vs. esbuild/Shakapacker – Cut the Build Tool Chaos

Tired of JavaScript tooling debates that sound like this?

“Just use Vite! Wait, no – Webpack 5 with Treeshaking! Actually, Bun is the future!”

Let’s cut through the noise. We’ll compare Import Maps (zero-build simplicity) and esbuild/Shakapacker (powerhouse bundling) – no evangelism, just pragmatism.


1. Import Maps: The “No Build Step” Revolution

What it is: Native browser feature that maps import "react" to real URLs.

Perfect for: Apps using minimal dependencies or HTTP/2.

<!-- Your index.html -->  
<script type="importmap">  
{  
  "imports": {  
    "react": "https://cdn.skypack.dev/react",  
    "react-dom": "https://cdn.skypack.dev/react-dom"  
  }  
}  
</script>  

<!-- Your app.js -->  
<script type="module">  
  import React from 'react'; // ← Browser resolves via importmap!  
</script>  
Enter fullscreen mode Exit fullscreen mode

Pros

  • 0-second builds (refresh = reload)
  • No node_modules (CDN dependencies)
  • Dead simple (Rails 7’s default)

Cons

  • No optimizations (minification, treeshaking)
  • CDN reliance (offline? slow networks?)
  • Limited to modern browsers

2. esbuild + Shakapacker: The Bundling Power Duo

What it is:

  • esbuild: Blazing-fast JS bundler (Go-based)
  • Shakapacker: Webpack’s successor for Rails (esbuild integration)
// shakapacker.config.js  
module.exports = {  
  compiler: {  
    // Minify, treeshake, bundle 100x faster than Webpack  
  },  
  resolve: {  
    extensions: ['.js', '.jsx']  
  }  
}  
Enter fullscreen mode Exit fullscreen mode

Pros

  • Production optimizations (treeshaking, minification, code splitting)
  • Handle ANY asset (Sass, TS, JSX, SVG)
  • Local dependencies (no CDN needed)

Cons

  • Build step required (even if fast)
  • Configuration nuance (esbuild plugins, Rails integration)
  • Mental overhead (another toolchain)

3. Side-by-Side: Choose Your Weapon

Import Maps esbuild/Shakapacker
Build Speed Instant (none) ⚡ 10-100x faster than Webpack
Dependencies CDN node_modules
Browser Support Modern browsers only All (via transpilation)
Production Ready? For simple apps Yes (optimized bundles)
Rails Integration Default in Rails 7 Via shakapacker gem

4. When to Use Which?

Choose Import Maps If:

  • You’re building a lightweight app (≤5 dependencies)
  • You hate build steps (hello, Rails 7)
  • Your audience uses modern browsers

Choose esbuild/Shakapacker If:

  • You need production optimizations
  • You use TypeScript, JSX, or advanced CSS
  • Your app has complex dependencies

5. Real-World Example

App A: Internal admin dashboard (3 dependencies, modern browsers)

Import Maps: 0 config, 0 build headaches.

App B: E-commerce site (React, TypeScript, CSS modules)

esbuild/Shakapacker: Optimized assets, code splitting.


Try It Yourself

Import Maps in Rails:

rails new my-app --javascript=importmap  
Enter fullscreen mode Exit fullscreen mode

Shakapacker + esbuild:

bundle add shakapacker --version ">=7"  
./bin/shakapacker install esbuild  
Enter fullscreen mode Exit fullscreen mode

Final Wisdom

JavaScript tooling isn’t one-size-fits-all.

  • Want simplicity? → Import Maps
  • Need power? → esbuild/Shakapacker

Stop over-engineering. Choose what fits your app – not Twitter’s opinion.

Which camp are you in? Share your battle stories below! 👇

Top comments (0)