{"id":22296,"library":"rollup-plugin-your-function","title":"rollup-plugin-your-function","description":"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.","status":"active","version":"0.5.3","language":"javascript","source_language":"en","source_url":"https://github.com/UmamiAppearance/rollup-plugin-your-function","tags":["javascript","build","change","function","manual","manipulate","modify","replace","rollup-plugin"],"install":[{"cmd":"npm install rollup-plugin-your-function","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-your-function","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-your-function","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency – requires Rollup >=1.x to function as a Rollup plugin","package":"rollup","optional":false}],"imports":[{"note":"Default export does not exist; the library exports a named export 'yourFunction'. CommonJS: const { yourFunction } = require('rollup-plugin-your-function').","wrong":"import yourFunction from 'rollup-plugin-your-function'","symbol":"yourFunction","correct":"import { yourFunction } from 'rollup-plugin-your-function'"},{"note":"When using as output plugin, yourFunction returns a plugin generator that must be called to get the actual plugin object.","wrong":"yourFunction({ output: true, fn: ... }) directly in output.plugins (missing function call wrapper)","symbol":"yourFunction (output plugin mode)","correct":"const myPlugin = yourFunction({ output: true, name: 'myPlugin', fn: ... }); then use myPlugin() in output.plugins"},{"note":"The fn can be sync or async; Rollup handles promises. No need to await in the config.","wrong":"yourFunction({ fn: async (source) => { return code; } }) missing await in config","symbol":"yourFunctionOptions.fn","correct":"yourFunction({ fn: (source) => { return code; } })"}],"quickstart":{"code":"// rollup.config.js\nimport { yourFunction } from 'rollup-plugin-your-function';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    file: 'dist/bundle.js',\n    format: 'esm'\n  },\n  plugins: [\n    yourFunction({\n      include: '**/*.js',\n      exclude: 'node_modules/**',\n      fn: (source, options) => {\n        // Replace 'console.log' with 'console.info'\n        let code = source.replace(/console\\.log/g, 'console.info');\n        // Append a comment\n        code += '\\n// Transformed by rollup-plugin-your-function';\n        return code;\n      }\n    })\n  ]\n};\n\n// Then run: rollup -c","lang":"javascript","description":"Basic usage: transform build files by replacing console.log calls and appending a comment using a custom function."},"warnings":[{"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()] }","message":"Output plugin mode requires calling the returned function","severity":"gotcha","affected_versions":">=0.1.0"},{"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.","message":"Return value format must be exactly string, [code, map?], or {code, map?}","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"No action needed.","message":"No breaking changes recorded; minor API stability","severity":"deprecated","affected_versions":"<=0.5.3"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Check include/exclude patterns; ensure the file matches include and not exclude. Verify the plugin is added to the plugins array.","cause":"The fn function is called with source as undefined because the plugin is not properly registered or the file is excluded.","error":"TypeError: Cannot read properties of undefined (reading 'replace')"},{"fix":"Ensure the return value is one of the supported formats. Example: return processedSource; or return [processedSource, map]; or return { code: processedSource, map: map }.","cause":"The fn function returned something other than a string, [code, map], or {code, map}.","error":"Error: The plugin 'yourFunction' returned an unsupported value. Expected a string, an array, or an object with code property."},{"fix":"Use named import: import { yourFunction } from 'rollup-plugin-your-function'. In CommonJS: const { yourFunction } = require('rollup-plugin-your-function').","cause":"Import statement is incorrect; likely using default import instead of named import.","error":"TypeError: yourFunction is not a function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}