Rollup plugin for find-and-replace transformations on output bundles. Version 3.0.0 is current and stable, with no major release cadence. Supports both string/regex find with string/function replace, and a terse object syntax for multiple replacements. Uses magic-string under the hood for source map preservation. Unlike @rollup/plugin-replace, this plugin operates on the entire output file content rather than on AST nodes, making it suitable for regex-based codemods.
npm install rollup-plugin-modifyVerified import paths — ran on the pinned version, not inferred.
Replaces process.env.* variables with actual environment variables in the output bundle, using a dynamic replace function.
Update Node.js to >=12 and use ESM imports. For CJS projects, use dynamic import() or stick to v2.
If you were using a single options object with 'find' and 'replace' keys, that still works. No migration needed unless you used undocumented API.
Use the explicit syntax for RegExp: modify({ find: /pattern/, replace: 'replacement' })Use (match, ...args) => { ... } and extract groups as needed.Use dynamic import: const modify = (await import('rollup-plugin-modify')).default;Use import modify from 'rollup-plugin-modify' (no braces).
Ensure find is either a string or RegExp. For multiple patterns, use the terse object syntax or multiple plugins.