grunt-esbuild

raw JSON →
1.0.1 verified Fri May 01 auth: no javascript

Grunt plugin to run esbuild builds. Version 1.0.0+ actively maintained. Configuration is passed directly to esbuild's build function, which must be provided via options.buildFunction. Unlike other Grunt bundler plugins, it does not wrap esbuild's API, giving full access to esbuild options. Requires Node.js and a compatible Grunt >=1. Releases are irregular; no known breaking changes yet.

error Warning: Task "esbuild" not found.
cause grunt-esbuild not loaded correctly.
fix
Add grunt.loadNpmTasks('grunt-esbuild') or use load-grunt-tasks in Gruntfile.
error TypeError: options.buildFunction is not a function
cause buildFunction not set or set incorrectly.
fix
Set options.buildFunction = require('esbuild').build in grunt.initConfig.
error Error: Invalid entry point. Must be an array of strings.
cause entryPoints is a string instead of an array.
fix
Change entryPoints: 'src/main.js' to entryPoints: ['src/main.js'].
gotcha buildFunction is required: you must pass require('esbuild').build in options.
fix Set options.buildFunction to require('esbuild').build in your Gruntfile.
gotcha Entry points must be an array, even for a single file.
fix Use entryPoints: ['src/main.js'] instead of entryPoints: 'src/main.js'.
gotcha The plugin does not support esbuild's watch mode or incremental builds.
fix Use a separate watch task (e.g., grunt-contrib-watch) to trigger rebuilds.
npm install grunt-esbuild
yarn add grunt-esbuild
pnpm add grunt-esbuild

Configure Grunt to run esbuild with a single bundle target.

// Gruntfile.js
module.exports = function(grunt) {
  require('load-grunt-tasks')(grunt);

  grunt.initConfig({
    esbuild: {
      options: {
        buildFunction: require('esbuild').build
      },
      dist: {
        entryPoints: ['src/main.js'],
        bundle: true,
        outfile: 'dist/main.js',
      }
    }
  });

  grunt.registerTask('default', ['esbuild']);
};