Registry / devops / esbuild-plugin-replace

esbuild-plugin-replace

JSON →
library1.4.0jsnpmunverified

An esbuild plugin for replacing strings in files during bundling, inspired by @rollup/plugin-replace. Current stable version is 1.4.0. Release cadence appears sporadic with occasional bug fixes and feature additions. Key differentiators: provides include/exclude file filtering, configurable delimiters, and supports both flat replacement objects and a `values` option to separate replacements from plugin options. Delimiters default to word boundaries. Requires Node.js and esbuild. Ships TypeScript declarations.

npm install esbuild-plugin-replace
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-REP
E
esbuild-plugin-replace
devopsjavascriptv1.4.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.

replace
import { replace } from 'esbuild-plugin-replace'
import replace from 'esbuild-plugin-replace'
Named export, not default. CommonJS: const { replace } = require('esbuild-plugin-replace')

Demonstrates basic usage of esbuild-plugin-replace to replace __version__ and __author__ with JSON-stringified values during a bundle build.

const esbuild = require('esbuild'); const { replace } = require('esbuild-plugin-replace'); esbuild.build({ entryPoints: ['src/index.js'], bundle: true, outfile: 'dist/bundle.js', plugins: [ replace({ '__version__': JSON.stringify('1.0.0'), '__author__': JSON.stringify('author'), }), ], }).then(() => console.log('Build succeeded')).catch(() => process.exit(1));
Debug
Known issues
gotchaValues must be primitives or functions returning a string. Complex values must be JSON.stringify'd.
fix
Use JSON.stringify for objects/arrays: replace({ '__key__': JSON.stringify({foo: 'bar'}) })
affects: >=1.0.0
breakingv1.0.8 introduced a change that may break builds using the `values` option incorrectly.
fix
If using `values` with existing flat replace keys, ensure keys are not duplicated between the top-level and values object.
affects: >=1.0.8 <1.1.0
deprecatedSpecifying replacements as top-level keys alongside plugin options is discouraged in favor of the `values` option.
fix
Use the `values` option: replace({ values: { ... } })
affects: >=1.2.0
Errors
Common errors & fixes
Error: The replace plugin expects replacement values to be strings or functions, got object
Passing an object directly instead of using JSON.stringify
fix
replace({ '__config__': JSON.stringify({ key: 'value' }) })
TypeError: Cannot read properties of undefined (reading 'replace')
Passing a non-string value as replacement (e.g., number) without converting to string
fix
Ensure replacement values are either strings or functions that return strings, e.g., JSON.stringify(123)
Upgrade
Version history
1.4.0latest on npm
Audit
Dependencies
esbuildoptionalpeer dependency - plugin is designed for esbuild's build system
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
esbuild-plugin-replace — npm install esbuild-plugin-replace · libregistry