A Rollup plugin for dynamic find-and-replace operations in bundled output using regular expressions or string matching. Version 5.0.1 is the latest stable release, published with a moderate cadence. Unlike static string replacement plugins, it supports RegExp patterns and replacement functions, enabling codemods and dynamic content injection. Ships TypeScript types and uses magic-string for accurate sourcemap preservation. A key differentiator is the shorthand syntax allowing key-value pairs for multiple replacements.
npm install rollup-plugin-regexpVerified import paths — ran on the pinned version, not inferred.
Shows default import, a regex replacement using a function, and the shorthand multiple replacement syntax.
Use import syntax or downgrade to 'rollup-plugin-regexp@4'
Update imports from 'rollup-plugin-modify' to 'rollup-plugin-regexp'
Ensure replacement function correctly handles all parameters: match, p1, p2, ..., offset, string.
Use external filter plugins or omit; the plugin only transforms matched files.
Order plugins carefully or consolidate replacements into a single instance.
Use dynamic import: const regexpPlugin = await import('rollup-plugin-regexp'); or use import syntax. Alternatively, downgrade to v4.Ensure import is default: import regexpPlugin from 'rollup-plugin-regexp' (no curly braces).
Check that 'find' is a string or RegExp, and 'replace' is a string or function.
Ensure 'find' is a string or RegExp. If using shorthand syntax, keys must be strings.