Registry / devops / esbuild-x

esbuild-x

JSON →
library0.4.2jsnpmunverified

esbuild-x is a thin wrapper around esbuild (currently v0.4.2) that adds support for configuration files (esbuild.config.js) and custom pre-build / post-build function hooks. It ships with built-in post-build helpers including file copy with glob patterns, HTML injection of esbuild outputs, and CSS/HTML minification plugins. Unlike bare esbuild, it allows developers to run arbitrary tasks (like cleanup, asset copying, or bundle analysis) before and after the main build without wiring separate tools. The release cadence is low/irregular; it's a small utility rather than a major framework.

npm install esbuild-x
INSTALL
IMPORT
SIG · ESBUILD-X
E
esbuild-x
devopsjavascriptv0.4.2
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.

esbuildX
const esbuildX = require('esbuild-x');
import esbuildX from 'esbuild-x';
The package uses CommonJS exports. ESM import may fail or require a default interop.
build
const { build } = require('esbuild-x');
const { build } = require('esbuild'); // plain esbuild doesn't have pre/post hooks
esbuild-x exports a build function that accepts the same options as esbuild.build plus preBuilds/postBuilds arrays.
minifyCssPlugin
const { minifyCssPlugin } = require('esbuild-x').plugins;
const { minifyCssPlugin } = require('esbuild-x'); // top-level export does not contain plugins
Plugins are nested under the `plugins` property of the default export.
injectEsbuildResult
const { injectEsbuildResult } = require('esbuild-x').postBuilds;
const { injectEsbuildResult } = require('esbuild-x');
Post-build helpers are under the `postBuilds` property.
copy
const { copy } = require('esbuild-x').postBuilds;
const { copy } = require('esbuild-x'); // copy is not a top-level export
copy is a post-build function, not a direct export.

Shows a complete build task with pre-cleanup and post-copy with replacements, using esbuild-x hooks.

const esbuildX = require('esbuild-x'); const { copy } = esbuildX.postBuilds; esbuildX.build({ entryPoints: ['src/main.js'], outdir: 'dist', bundle: true, preBuilds: [ function clean() { const fs = require('fs'); if (fs.existsSync('dist')) fs.rmSync('dist', { recursive: true }); } ], postBuilds: [ copy('src/**/*.html dist', { replacements: [ { match: /\.html$/, find: /__VERSION__/, replace: '1.0.0' } ] }), function logResult(_, result) { console.log('Build succeeded in', result?.errors?.length ? 'ERR' : 'OK'); } ] }).catch(err => console.error(err));
Debug
Known issues
gotchaThe esbuild-x `build` function returns a Promise that resolves to the esbuild result object; errors are not caught internally. Always attach a .catch().
fix
Chain `.catch(err => ...)` after calling `esbuildX.build(...)`.
affects: >=0.0.0
gotchaThe `copy` post-build function's `replacements` option expects arrays with objects containing `match` (RegExp), `find` (RegExp), and `replace` (string). Omitting any of these or using wrong types will cause silent failures or runtime errors.
fix
Verify each replacement object has `match`, `find`, and `replace` fields. The `match` pattern must match the file path to apply the replacement.
affects: >=0.0.0
gotchaThe `injectEsbuildResult` post-build expects index.html to contain `<script src="main.js"></script>` and `<link rel="stylesheet" href="style.css" />` exactly. If the HTML is different, injection may fail silently or produce broken markup.
fix
Ensure your index.html uses the exact placeholder script/links. Alternatively, configure esbuild's outdir and use a separate copy step.
affects: >=0.0.0
deprecatedThe `esbuild-x` CLI is a thin wrapper around esbuild's CLI. It may not support all esbuild options or flags correctly in future versions.
fix
Use the Node API for reliable behavior; the CLI is undocumented beyond basic usage.
affects: >=0.4.0
Errors
Common errors & fixes
TypeError: esbuildX.build is not a function
Using default import instead of require() or destructuring incorrectly.
fix
Use `const esbuildX = require('esbuild-x');` then `esbuildX.build(...)`.
Cannot find module 'esbuild-x'
Package not installed or installed as devDependency without --save-dev.
fix
Run `npm install esbuild-x --save-dev` and ensure node_modules contains it.
Error: Cannot read property 'plugins' of undefined
Attempting to destructure `plugins` or `postBuilds` from the default export without the correct path.
fix
Access via `require('esbuild-x').plugins` or `require('esbuild-x').postBuilds`.
Error: options.outdir is required for injectEsbuildResult
Using `injectEsbuildResult` without setting `outdir` in build options.
fix
Add `outdir: 'dist'` (or your desired output directory) to the build options object.
Upgrade
Version history
0.4.2latest on npm
Audit
Dependencies
esbuildrequiredCore bundler; esbuild-x wraps esbuild's build and serve APIs
Agent activity
4 hits · last 30 days
node
4
Resources
esbuild-x — npm install esbuild-x · libregistry