A Rollup plugin that accepts a user-defined function to manipulate build output. Version 0.5.3, stable with occasional updates. Provides a minimal API for custom source transformations without learning plugin-specific DSLs. Unlike replace, string-replace, or regex plugins, it allows arbitrary JavaScript logic including async operations, conditional transformations based on file ID, and custom sourcemap generation. Supports both build and output plugin modes with include/exclude minimatch filtering. No external dependencies beyond Rollup peer.
npm install rollup-plugin-your-functionVerified import paths — ran on the pinned version, not inferred.
Basic usage: transform build files by replacing console.log calls and appending a comment using a custom function.
When using output:true, assign the result of yourFunction() to a variable and call it as a function in output.plugins: const myPlugin = yourFunction({output:true, name:'my', fn:...}); output: { plugins: [myPlugin()] }Ensure your function returns either a string, an array with code as first element (optional map as second), or an object with code property (optional map property). Returning null or undefined will cause errors.
No action needed.
Check include/exclude patterns; ensure the file matches include and not exclude. Verify the plugin is added to the plugins array.
Ensure the return value is one of the supported formats. Example: return processedSource; or return [processedSource, map]; or return { code: processedSource, map: map }.Use named import: import { yourFunction } from 'rollup-plugin-your-function'. In CommonJS: const { yourFunction } = require('rollup-plugin-your-function').