1001Ferramentas
🚀Dev

esbuild Config Generator

Generates a ready esbuild.config.js for fast builds, with entry point, bundle, minification, sourcemap and target already set. The output format is left at the esbuild default.



  

A ready esbuild build script

esbuild is fast and has one gotcha that catches almost everyone the first time: it never looks for a config file on its own. Either you pile flags onto the command line until your package.json script turns into a paragraph, or you write a small build script in JavaScript. This page hands you that script already written.

The block is fixed, has no fields, and shows up as soon as the page loads. It calls require('esbuild') and passes esbuild.build entryPoints src/index.js, bundle true, outfile dist/bundle.js, minify true, sourcemap true, target es2020 and platform browser, ending with a catch that exits with code 1. Save it as esbuild.config.js and run node esbuild.config.js, or wire it into your build script.

Three things to check. The file uses require, so it breaks if your package.json has type: module; rename it to .cjs or convert it to import syntax. platform browser means Node builtins like fs and path will fail to resolve, so switch to node for a CLI tool. And there is no watch mode: since 0.17 that lives in the context API, with esbuild.context and ctx.watch. The text is assembled in your browser.

Frequently asked questions

Does esbuild pick this file up automatically?
No. It is a plain Node script that calls the esbuild API. You have to run it yourself, for instance with node esbuild.config.js or through npm run build.
How do I get watch mode?
Replace esbuild.build with esbuild.context using the same options object, then await ctx.watch(). The old watch: true flag was removed in 0.17.
How do I emit an ESM bundle?
Add format: 'esm' to the options and give outfile an .mjs extension. Without that key, and with platform browser, esbuild produces an IIFE.

Related Tools