sajad torkamani

In a nutshell

esbuild is a fast bundler for the web that comes with sensible defaults to handle common build requirements but which is also high-customisable.

esbuild is used by Vite during development and is much faster than alternatives like Webpack, Rollup or Parcel.

esbuild performance comparison

Getting started

Install:

npm i -D esbuild

Add a esbuild.mjs file:

import * as esbuild from 'esbuild'

let notifyPlugin = {
  name: 'notify-plugin',
  setup(build) {
    build.onEnd(result => {
      console.log(`Built with ${result.errors.length} errors`)
    })
  }
}

let ctx = await esbuild.context({
  entryPoints: ['app.tsx'],
  outdir: 'dist',
  bundle: true,
  sourcemap: true,
  minify: true,
  plugins: [notifyPlugin]
})

await ctx.watch()

console.log('Watching for changes...')

Run with node esbuild.mjs and the entry point file app.tsx will be bundled to a dist/app.tsx file.

See this repo for example.

Links

Leave a comment

Your email address will not be published. Required fields are marked *