Registry / web-framework / rollup-plugin-your-function

rollup-plugin-your-function

JSON →
library0.5.3jsnpmunverified

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-function
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-YOUR
R
rollup-plugin-your-function
web-frameworkjavascriptv0.5.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

yourFunction
import { yourFunction } from 'rollup-plugin-your-function'
import yourFunction from 'rollup-plugin-your-function'
Default export does not exist; the library exports a named export 'yourFunction'. CommonJS: const { yourFunction } = require('rollup-plugin-your-function').
yourFunction (output plugin mode)
const myPlugin = yourFunction({ output: true, name: 'myPlugin', fn: ... }); then use myPlugin() in output.plugins
yourFunction({ output: true, fn: ... }) directly in output.plugins (missing function call wrapper)
When using as output plugin, yourFunction returns a plugin generator that must be called to get the actual plugin object.
yourFunctionOptions.fn
yourFunction({ fn: (source) => { return code; } })
yourFunction({ fn: async (source) => { return code; } }) missing await in config
The fn can be sync or async; Rollup handles promises. No need to await in the config.

Basic usage: transform build files by replacing console.log calls and appending a comment using a custom function.

// rollup.config.js import { yourFunction } from 'rollup-plugin-your-function'; export default { input: 'src/index.js', output: { file: 'dist/bundle.js', format: 'esm' }, plugins: [ yourFunction({ include: '**/*.js', exclude: 'node_modules/**', fn: (source, options) => { // Replace 'console.log' with 'console.info' let code = source.replace(/console\.log/g, 'console.info'); // Append a comment code += '\n// Transformed by rollup-plugin-your-function'; return code; } }) ] }; // Then run: rollup -c
Debug
Known issues
gotchaOutput plugin mode requires calling the returned function
fix
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()] }
affects: >=0.1.0
gotchaReturn value format must be exactly string, [code, map?], or {code, map?}
fix
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.
affects: >=0.1.0
deprecatedNo breaking changes recorded; minor API stability
fix
No action needed.
affects: <=0.5.3
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'replace')
The fn function is called with source as undefined because the plugin is not properly registered or the file is excluded.
fix
Check include/exclude patterns; ensure the file matches include and not exclude. Verify the plugin is added to the plugins array.
Error: The plugin 'yourFunction' returned an unsupported value. Expected a string, an array, or an object with code property.
The fn function returned something other than a string, [code, map], or {code, map}.
fix
Ensure the return value is one of the supported formats. Example: return processedSource; or return [processedSource, map]; or return { code: processedSource, map: map }.
TypeError: yourFunction is not a function
Import statement is incorrect; likely using default import instead of named import.
fix
Use named import: import { yourFunction } from 'rollup-plugin-your-function'. In CommonJS: const { yourFunction } = require('rollup-plugin-your-function').
Upgrade
Version history
0.5.3latest on npm
Audit
Dependencies
rolluprequiredPeer dependency – requires Rollup >=1.x to function as a Rollup plugin
Agent activity
10 hits · last 30 days
node
8
OpenAI (training)
1
Resources
rollup-plugin-your-function — npm install rollup-plugin-your-function · libregistry