Registry / devops / esbuild-plugin-modify-entrypoints

esbuild-plugin-modify-entrypoints

JSON →
library0.2.0jsnpmunverified

esbuild plugin (v0.2.0) that allows modifying the contents of entrypoint files before they are processed by esbuild. It provides a callback function that receives the current entrypoint contents and can return modified contents along with an optional loader. Version 0.2.0 is the latest stable release, requires esbuild >=0.15 and Node.js >=18.12.0. Key differentiator: simple, focused plugin for editing entrypoint content without needing to manipulate esbuild's internal pipeline, unlike more complex alternatives.

npm install esbuild-plugin-modify-entrypoints
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-MOD
E
esbuild-plugin-modify-entrypoints
devopsjavascriptv0.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

modifyEntrypointsPlugin
import { modifyEntrypointsPlugin } from 'esbuild-plugin-modify-entrypoints'
import modifyEntrypointsPlugin from 'esbuild-plugin-modify-entrypoints'
Named export; default export is not available.
modifyEntrypointsPlugin
const { modifyEntrypointsPlugin } = require('esbuild-plugin-modify-entrypoints')
const modifyEntrypointsPlugin = require('esbuild-plugin-modify-entrypoints')
CommonJS require returns an object with the named export.
ModifyEntrypointsPluginOptions
import type { ModifyEntrypointsPluginOptions } from 'esbuild-plugin-modify-entrypoints'
TypeScript users may want to import the options type for type-safe callbacks.

Demonstrates using the plugin with esbuild's CommonJS API to modify entrypoint contents by prepending a log statement.

const esbuild = require('esbuild'); const { modifyEntrypointsPlugin } = require('esbuild-plugin-modify-entrypoints'); esbuild.build({ entryPoints: ['src/app.ts'], bundle: true, outfile: 'dist/bundle.js', plugins: [ modifyEntrypointsPlugin(({ contents, path }) => { // Prepend a console log to all entrypoint files return { contents: `console.log('Entry: ${path}');\n${contents}`, loader: 'ts', }; }), ], }).catch(() => process.exit(1));
Debug
Known issues
gotchaThe callback receives an object with only `contents` and `path`. Ensure you check for all expected properties.
fix
Upgrade to 0.2.0 or later which provides both `contents` and `path`.
affects: <0.2.0
gotchaReturning an object without a `loader` property may cause esbuild to use default loader, potentially mismatched.
fix
Explicitly set the `loader` field in the return value to match your content's syntax (e.g., 'ts', 'js', 'tsx').
affects: >=0.0.0
gotchaThis plugin only affects entrypoints listed in the `entryPoints` option; it does not affect imported modules.
fix
Use the plugin on explicit entrypoints; for other files, use other esbuild plugins like svgr or CSS modules.
affects: >=0.0.0
deprecatedThe `loader` option in the return value is optional; if omitted, the original loader from the entrypoint is used. However, in some versions misbehavior may occur.
fix
Always set the `loader` to avoid confusion; upgrade to 0.2.0+ for safer defaults.
affects: <0.2.0
Errors
Common errors & fixes
Error: The plugin 'modify-entrypoints' must return an object with a `contents` property.
The callback returned undefined or an object without the required `contents`.
fix
Ensure your callback always returns an object with a `contents` string at minimum.
TypeError: Cannot destructure property 'contents' of 'undefined' or 'null'.
The callback parameter is undefined, usually because the plugin was not added correctly.
fix
Verify the plugin is properly imported and passed in the `plugins` array.
Error: esbuild: Failed to resolve entry point: Entry point 'foo' not found.
The entryPoints array references a file that doesn't exist.
fix
Double-check the file path in `entryPoints` and ensure it is correct relative to the working directory.
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies
esbuildrequiredpeer dependency: provides esbuild build system and plugin API
Agent activity
2 hits · last 30 days
node
2
Resources
esbuild-plugin-modify-entrypoints — npm install esbuild-plugin-modify-entrypoints · libregistry