{"id":25373,"library":"esbuild-plugin-modify-entrypoints","title":"esbuild-plugin-modify-entrypoints","description":"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.","status":"active","version":"0.2.0","language":"javascript","source_language":"en","source_url":"https://github.com/webdeveric/esbuild-plugin-modify-entrypoints","tags":["javascript","esbuild","plugin","modify","entrypoints"],"install":[{"cmd":"npm install esbuild-plugin-modify-entrypoints","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-modify-entrypoints","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-modify-entrypoints","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: provides esbuild build system and plugin API","package":"esbuild","optional":false}],"imports":[{"note":"Named export; default export is not available.","wrong":"import modifyEntrypointsPlugin from 'esbuild-plugin-modify-entrypoints'","symbol":"modifyEntrypointsPlugin","correct":"import { modifyEntrypointsPlugin } from 'esbuild-plugin-modify-entrypoints'"},{"note":"CommonJS require returns an object with the named export.","wrong":"const modifyEntrypointsPlugin = require('esbuild-plugin-modify-entrypoints')","symbol":"modifyEntrypointsPlugin","correct":"const { modifyEntrypointsPlugin } = require('esbuild-plugin-modify-entrypoints')"},{"note":"TypeScript users may want to import the options type for type-safe callbacks.","wrong":"","symbol":"ModifyEntrypointsPluginOptions","correct":"import type { ModifyEntrypointsPluginOptions } from 'esbuild-plugin-modify-entrypoints'"}],"quickstart":{"code":"const esbuild = require('esbuild');\nconst { modifyEntrypointsPlugin } = require('esbuild-plugin-modify-entrypoints');\nesbuild.build({\n  entryPoints: ['src/app.ts'],\n  bundle: true,\n  outfile: 'dist/bundle.js',\n  plugins: [\n    modifyEntrypointsPlugin(({ contents, path }) => {\n      // Prepend a console log to all entrypoint files\n      return {\n        contents: `console.log('Entry: ${path}');\\n${contents}`,\n        loader: 'ts',\n      };\n    }),\n  ],\n}).catch(() => process.exit(1));","lang":"javascript","description":"Demonstrates using the plugin with esbuild's CommonJS API to modify entrypoint contents by prepending a log statement."},"warnings":[{"fix":"Upgrade to 0.2.0 or later which provides both `contents` and `path`.","message":"The callback receives an object with only `contents` and `path`. Ensure you check for all expected properties.","severity":"gotcha","affected_versions":"<0.2.0"},{"fix":"Explicitly set the `loader` field in the return value to match your content's syntax (e.g., 'ts', 'js', 'tsx').","message":"Returning an object without a `loader` property may cause esbuild to use default loader, potentially mismatched.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use the plugin on explicit entrypoints; for other files, use other esbuild plugins like svgr or CSS modules.","message":"This plugin only affects entrypoints listed in the `entryPoints` option; it does not affect imported modules.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Always set the `loader` to avoid confusion; upgrade to 0.2.0+ for safer defaults.","message":"The `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.","severity":"deprecated","affected_versions":"<0.2.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Ensure your callback always returns an object with a `contents` string at minimum.","cause":"The callback returned undefined or an object without the required `contents`.","error":"Error: The plugin 'modify-entrypoints' must return an object with a `contents` property."},{"fix":"Verify the plugin is properly imported and passed in the `plugins` array.","cause":"The callback parameter is undefined, usually because the plugin was not added correctly.","error":"TypeError: Cannot destructure property 'contents' of 'undefined' or 'null'."},{"fix":"Double-check the file path in `entryPoints` and ensure it is correct relative to the working directory.","cause":"The entryPoints array references a file that doesn't exist.","error":"Error: esbuild: Failed to resolve entry point: Entry point 'foo' not found."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}