Registry / devops / esbuild-plugin-replace-regex

esbuild-plugin-replace-regex

JSON →
library0.0.2jsnpmunverified

A simple esbuild plugin for replacing file content during bundling using regular expressions or string patterns. Version 0.0.2, released with basic functionality allowing multiple patterns, custom file filtering, and loader specification. Differentiates from general replace plugins by focusing on regex and integration with esbuild's build process. Lightweight with no additional dependencies beyond esbuild peer.

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

default
import replacePlugin from 'esbuild-plugin-replace-regex'
const replacePlugin = require('esbuild-plugin-replace-regex')
Package is ESM-only starting from v0.0.2? Actually package.json has no module field but exports default; use ESM import for consistency.
replacePlugin
const replacePlugin = require('esbuild-plugin-replace-regex');
import { replacePlugin } from 'esbuild-plugin-replace-regex'
CommonJS require works but named import fails as it's a default export.

Shows basic usage of esbuild-plugin-replace-regex to replace version string and env variable during build.

import esbuild from 'esbuild'; import replacePlugin from 'esbuild-plugin-replace-regex'; await esbuild.build({ entryPoints: ['src/index.ts'], bundle: true, outfile: 'dist/bundle.js', plugins: [ replacePlugin({ filter: /\.(ts|js)$/, patterns: [ ['VERSION', '1.0.0'], [/process\.env\.NODE_ENV/g, '"production"'], ] }) ] });
Debug
Known issues
gotchaPatterns array items can be string pairs or regex with function replacements; using regex without global flag may replace only first occurrence
fix
Add g flag to regex or use string replacement for all occurrences
affects: >=0.0.0
gotchaThe filter option is a RegExp that matches the file path; using a string will throw an error
fix
Use a RegExp object for filter
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: replacePlugin is not a function
Using named import instead of default import in ESM
fix
Import default: import replacePlugin from 'esbuild-plugin-replace-regex'
Error: The plugin 'replace-regex' returned an error: Cannot read properties of undefined (reading 'replace')
Patterns array item is malformed or missing replacement string
fix
Ensure each pattern is either [search, replacement] or [regex, replaceFunction]
Upgrade
Version history
0.0.2latest on npm
Audit
Dependencies
esbuildrequiredpeer dependency required to use the plugin
Agent activity
4 hits · last 30 days
node
4
Resources
esbuild-plugin-replace-regex — npm install esbuild-plugin-replace-regex · libregistry