esbuild-plugin-run

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

ESBuild plugin that automatically executes the output file (e.g., a Node.js script) after a successful build. Version 0.3.0 is current, with a simple API: specify the output format (cjs, esm, iife) and optionally the entry point path. It integrates seamlessly into ESBuild's plugin system and requires esbuild ^0.14.0 as a peer dependency. Differentiators: minimal configuration, built-in TypeScript types, and no external runtime deps.

error Error: Cannot find module 'esbuild-plugin-run'
cause Package not installed or not matching peer dependency version.
fix
Run npm install esbuild-plugin-run esbuild@^0.14.0
error TypeError: run is not a function
cause Using wrong import syntax (CommonJS require for ESM-only package).
fix
Use import { run } from 'esbuild-plugin-run' instead of require().
gotcha The plugin only runs after a successful build; errors will prevent execution.
fix Ensure your build completes without errors.
gotcha The 'format' option must match the output format of ESBuild; otherwise execution may fail.
fix Set the plugin's format to the same value as ESBuild's format.
npm install esbuild-plugin-run
yarn add esbuild-plugin-run
pnpm add esbuild-plugin-run

Shows how to use the run plugin in an ESBuild build pipeline with TypeScript entry point.

import { run } from 'esbuild-plugin-run';
import * as esbuild from 'esbuild';

await esbuild.build({
  entryPoints: ['src/index.ts'],
  bundle: true,
  outfile: 'dist/index.js',
  format: 'cjs',
  plugins: [run({
    format: 'cjs',
    pattern: '**/*.js'
  })]
});