{"id":25402,"library":"esbuild-plugin-replace-regex","title":"esbuild Plugin Replace Regex","description":"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.","status":"active","version":"0.0.2","language":"javascript","source_language":"en","source_url":"https://github.com/fakundo/esbuild-plugin-replace-regex","tags":["javascript","esbuild","plugin","replace","regex"],"install":[{"cmd":"npm install esbuild-plugin-replace-regex","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-replace-regex","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-replace-regex","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency required to use the plugin","package":"esbuild","optional":false}],"imports":[{"note":"Package is ESM-only starting from v0.0.2? Actually package.json has no module field but exports default; use ESM import for consistency.","wrong":"const replacePlugin = require('esbuild-plugin-replace-regex')","symbol":"default","correct":"import replacePlugin from 'esbuild-plugin-replace-regex'"},{"note":"CommonJS require works but named import fails as it's a default export.","wrong":"import { replacePlugin } from 'esbuild-plugin-replace-regex'","symbol":"replacePlugin","correct":"const replacePlugin = require('esbuild-plugin-replace-regex');"}],"quickstart":{"code":"import esbuild from 'esbuild';\nimport replacePlugin from 'esbuild-plugin-replace-regex';\n\nawait esbuild.build({\n  entryPoints: ['src/index.ts'],\n  bundle: true,\n  outfile: 'dist/bundle.js',\n  plugins: [\n    replacePlugin({\n      filter: /\\.(ts|js)$/,\n      patterns: [\n        ['VERSION', '1.0.0'],\n        [/process\\.env\\.NODE_ENV/g, '\"production\"'],\n      ]\n    })\n  ]\n});","lang":"typescript","description":"Shows basic usage of esbuild-plugin-replace-regex to replace version string and env variable during build."},"warnings":[{"fix":"Add g flag to regex or use string replacement for all occurrences","message":"Patterns array items can be string pairs or regex with function replacements; using regex without global flag may replace only first occurrence","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use a RegExp object for filter","message":"The filter option is a RegExp that matches the file path; using a string will throw an error","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Import default: import replacePlugin from 'esbuild-plugin-replace-regex'","cause":"Using named import instead of default import in ESM","error":"TypeError: replacePlugin is not a function"},{"fix":"Ensure each pattern is either [search, replacement] or [regex, replaceFunction]","cause":"Patterns array item is malformed or missing replacement string","error":"Error: The plugin 'replace-regex' returned an error: Cannot read properties of undefined (reading 'replace')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}