rollup-plugin-postprocess

raw JSON →
1.0.2 verified Mon Apr 27 auth: no javascript

A Rollup plugin that applies regex-based find-and-replace postprocessing to bundle output. Version 1.0.2 is the latest stable release with minimal release cadence. It works like JavaScript String replace, supporting function callbacks and sequential replacement pairs. Differentiates from other replace plugins by operating after all other plugins, allowing transformation of the final bundle.

error TypeError: postprocess is not a function
cause Named import instead of default import.
fix
Use import postprocess from 'rollup-plugin-postprocess'.
error Error: [object Object] is not a valid replacement pair
cause Passed an object instead of an array of arrays.
fix
Supply an array of [regex, replacement] arrays: postprocess([[ /pattern/, 'replacement' ]]).
gotcha Patterns are applied as String.replace, not RegExp replacement with full support for flags like 'g'.
fix Use global flag in regex: /foo/g instead of just /foo/.
gotcha When using function callback for replacement, returning undefined removes the match (empty string).
fix Return empty string '' explicitly to keep match removal behavior clear.
gotcha Patterns are executed sequentially on the entire bundle, so later patterns can match text inserted by earlier ones.
fix Design patterns carefully to avoid unintended interactions.
npm install rollup-plugin-postprocess
yarn add rollup-plugin-postprocess
pnpm add rollup-plugin-postprocess

Replaces all occurrences of FIND_ME with REPLACED in the final bundle using rollup-plugin-postprocess.

import postprocess from 'rollup-plugin-postprocess';

export default {
  input: 'src/index.js',
  output: { file: 'dist/bundle.js', format: 'iife' },
  plugins: [
    postprocess([
      [/\bFIND_ME\b/g, 'REPLACED']
    ])
  ]
};