rollup-plugin-esbuild-transform

raw JSON →
1.5.0 verified Mon Apr 27 auth: no javascript

Rollup plugin that leverages esbuild's transform API to process files of any supported type (JS, JSX, TS, TSX, JSON, CSS, etc.) before bundling. Version 1.5.0 is the latest stable release, actively maintained. Unlike rollup-plugin-esbuild, this plugin allows multiple loader configurations with per-pattern esbuild options, supports both pre-bundle and post-bundle (output) transforms, and exposes all esbuild TransformOptions including tsconfig path resolution. Ships TypeScript declarations. Requires esbuild >=0.10.1 and Rollup 1.x/2.x.

error Error: Cannot find module 'esbuild'
cause esbuild is a peer dependency but not installed.
fix
Run npm install -D esbuild alongside this plugin.
error TypeError: esbuild is not a function
cause Importing incorrectly (e.g., using named import instead of default).
fix
Use import esbuild from 'rollup-plugin-esbuild-transform' (default import).
error The plugin 'esbuild' is not allowed to emit files after bundle generation
cause Using `output: true` in an array entry but the plugin is not the last plugin or does not work with Rollup's output phase.
fix
Ensure the entry with output: true is intended for post-bundle transforms and that the plugin is properly set up to handle both phases; check Rollup plugin ordering.
breaking Plugin options `output` changes behavior: when `true`, `include` and `exclude` apply to the output chunk filename, not individual module files.
fix Ensure to set `output: true` only for options intended for post-bundle transformation; separate pre-bundle and post-bundle configurations into distinct entries in the array.
gotcha When multiple array entries match the same file, options are shallowly merged — `loader` from the first matching entry is kept, other options from later entries can override without warning.
fix Order entries carefully; the first matching entry's `loader` takes precedence, but other options (e.g., `target`, `tsconfig`) will be overwritten by later matches.
gotcha `tsconfig` option is ignored if `tsconfigRaw` is provided in the same options entry.
fix Provide either `tsconfig` (path string) or `tsconfigRaw` (object), not both. If both are given, `tsconfigRaw` takes precedence.
deprecated Rollup 1.x support is deprecated; plugin peer dependency allows ^1.20.0 but future versions may drop it.
fix Migrate to Rollup 2.x or 3.x as soon as possible.
npm install rollup-plugin-esbuild-transform
yarn add rollup-plugin-esbuild-transform
pnpm add rollup-plugin-esbuild-transform

Configures the plugin to transform .ts files using a tsconfig, handle .js files, and minify the final bundle output.

import esbuild from 'rollup-plugin-esbuild-transform';

export default {
  input: 'src/index.ts',
  output: { file: 'dist/bundle.js', format: 'esm' },
  plugins: [
    esbuild([
      { loader: 'ts', include: /\.ts$/, tsconfig: './tsconfig.json' },
      { loader: 'js' },
      { output: true, minify: true, target: 'es2015' },
    ]),
  ],
};