esbuild-plugin-inline-functions
raw JSON → 0.2.0 verified Fri May 01 auth: no javascript
An esbuild plugin that inlines JavaScript functions annotated with /* @inline */ hints, eliminating function call overhead. Version 0.2.0 (stable, active development). Unlike manual inlining or other tools, it automatically handles imports, dependencies, control flow (early returns, conditionals), variable scoping, and execution order. Supports both regular functions and arrow functions. Includes a /* @pure */ annotation to enable hoisting of duplicate pure function calls. Ships TypeScript declarations. Requires @babel/parser, @babel/traverse, @babel/types as peer dependencies. Works in any esbuild context (e.g., tsup, Vite, pure esbuild).
Common errors
error Error: Cannot find module '@babel/parser' ↓
cause Missing peer dependency @babel/parser.
fix
Run npm install @babel/parser@^7.26.3
error TypeError: inlineFunctionsPlugin is not a function ↓
cause Default import used instead of named import.
fix
Use import { inlineFunctionsPlugin } from 'esbuild-plugin-inline-functions';
error Error: The plugin must be called with no arguments? ↓
cause Inline functions plugin expects no arguments (or an options object?). Current docs show no arguments.
fix
Call inlineFunctionsPlugin() without arguments. If options are needed in future, check docs.
Warnings
gotcha The plugin uses @babel/parser which requires TypeScript files to have the syntax plugin? Double check: When using with TypeScript, ensure @babel/parser is configured to parse TypeScript. The plugin may not support TypeScript syntax out of the box. ↓
fix Set esbuild plugins after ensuring esbuild handles TypeScript (type stripping) or use the plugin only on JavaScript files. Alternatively, verify if plugin version supports TypeScript via @babel/preset-typescript.
deprecated If using an older version of esbuild (pre-0.12), the plugin API may not be compatible. Always use esbuild >= 0.12. ↓
fix Update esbuild to version 0.12 or later.
gotcha The /* @inline */ hint is a comment, not a decorator or pragma. It must appear exactly before a function declaration (not expression) and in the exact /* @inline */ format, including the leading /* and trailing */ ↓
fix Use /* @inline */ exactly; avoid // @inline or other whitespace variations.
breaking In version 0.1.0, the plugin used a different API? (Check changelog). Version 0.2.0 changed how hints are parsed? Currently no known breaking changes, but be aware of potential future ones. ↓
fix Pin to 0.2.0 or check release notes for breaking changes.
Install
npm install esbuild-plugin-inline-functions yarn add esbuild-plugin-inline-functions pnpm add esbuild-plugin-inline-functions Imports
- inlineFunctionsPlugin wrong
import inlineFunctionsPlugin from 'esbuild-plugin-inline-functions'correctimport { inlineFunctionsPlugin } from 'esbuild-plugin-inline-functions' - default wrong
import inlineFunctionsPlugin from 'esbuild-plugin-inline-functions'correctimport { inlineFunctionsPlugin } from 'esbuild-plugin-inline-functions' - require
const { inlineFunctionsPlugin } = require('esbuild-plugin-inline-functions')
Quickstart
import { inlineFunctionsPlugin } from 'esbuild-plugin-inline-functions';
import * as esbuild from 'esbuild';
await esbuild.build({
entryPoints: ['input.js'],
outfile: 'output.js',
plugins: [inlineFunctionsPlugin()],
});
// input.js should contain functions annotated with /* @inline */ comment
/* @inline */
function add(a, b) {
return a + b;
}
console.log(add(1, 2));