{"id":25925315,"url":"https://github.com/umamiappearance/rollup-plugin-your-function","last_synced_at":"2025-03-03T18:47:55.297Z","repository":{"id":52637752,"uuid":"520777514","full_name":"UmamiAppearance/rollup-plugin-your-function","owner":"UmamiAppearance","description":"A very simple rollup-plugin, which gives you the opportunity to manipulate your build files as you like. Dead simple. The last plugin you need (for small tasks).","archived":false,"fork":false,"pushed_at":"2023-07-05T19:36:06.000Z","size":264,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-01T05:35:09.037Z","etag":null,"topics":["build","change","function","manipulate","manual","modify","replace","rollup-plugin"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/UmamiAppearance.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-08-03T07:19:04.000Z","updated_at":"2023-03-17T12:43:23.000Z","dependencies_parsed_at":"2024-06-21T20:22:45.246Z","dependency_job_id":"a8d9b5ac-0696-471b-80eb-aeb2100bfc96","html_url":"https://github.com/UmamiAppearance/rollup-plugin-your-function","commit_stats":{"total_commits":52,"total_committers":4,"mean_commits":13.0,"dds":"0.21153846153846156","last_synced_commit":"c0ae5434227afadb963d234cd3a6bde18cf2f045"},"previous_names":[],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UmamiAppearance%2Frollup-plugin-your-function","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UmamiAppearance%2Frollup-plugin-your-function/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UmamiAppearance%2Frollup-plugin-your-function/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/UmamiAppearance%2Frollup-plugin-your-function/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/UmamiAppearance","download_url":"https://codeload.github.com/UmamiAppearance/rollup-plugin-your-function/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241723132,"owners_count":20009412,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["build","change","function","manipulate","manual","modify","replace","rollup-plugin"],"created_at":"2025-03-03T18:47:54.189Z","updated_at":"2025-03-03T18:47:55.285Z","avatar_url":"https://github.com/UmamiAppearance.png","language":"JavaScript","readme":"# rollup-plugin-your-function\n[![License](https://img.shields.io/github/license/UmamiAppearance/rollup-plugin-your-function?color=009911\u0026style=for-the-badge)](./LICENSE)\n[![npm](https://img.shields.io/npm/v/rollup-plugin-your-function?color=009911\u0026style=for-the-badge)](https://www.npmjs.com/package/rollup-plugin-your-function)\n\nA very simple rollup-plugin, which gives you the opportunity to manipulate your build files as you like. Dead simple. The last plugin you need (for small tasks).\n\n\n## Idea\nThere are many plugins for rollup available. And many times the only thing you would like to perform is a little change, just some regex magic, only a small string replacement, etc. Now the big research begins: _which plugin fits the best?_  \n\nEventually you will find what you need, but now you'll have to figure out the particularities of the plugin. And you find yourself thinking: _\"Why was that so complicated? I could have done this to a regular file in seconds!\"_.  \n\nThis is where **rollup-plugin-your-function** comes into play. The _only!_ thing it does, is to take a function, that you create by yourself. Your function needs to take one argument, that is the source file, it must return the output code as the first parameter, optionally a sourcemap as a second (otherwise it gets generated automatically and includes the performed changes). And that's it.  \n\n\n## Install\nUsing npm:\n```console\nnpm install rollup-plugin-your-function --save-dev\n```\n\n\n## Usage\nCreate a `rollup.config.js` [configuration file](https://www.rollupjs.org/guide/en/#configuration-files) and import the plugin.\n\n```js\nimport { yourFunction } from \"rollup-plugin-your-function\";\n\nexport default {\n    input: \"src/index.js\",\n    output: {   \n        format: \"es\",\n        name: \"myBuild\",\n        file: \"./dist/build.js\",\n    },\n    plugins: [\n        yourFunction({\n            fn: source =\u003e {\n                let code = source.replace(\"foo\", \"bar\");\n                code += \"baz\";\n                return code;\n            }\n        })\n    ]\n}\n```\n\n#### ...or use it as an output plugin\n```js\nimport { yourFunction } from \"rollup-plugin-your-function\";\n\nconst myPlugin = yourFunction({\n    output: true,\n    name: \"myPlugin\",\n    fn: async (source, options) =\u003e ...\n});\n\nexport default {\n    input: \"src/index.js\",\n    output: {   \n        format: \"es\",\n        name: \"myBuild\",\n        file: \"./dist/build.js\",\n        plugins: [myPlugin()]\n    }\n}\n```\n\nThen call `rollup` either via the [CLI](https://www.rollupjs.org/guide/en/#command-line-reference) or the [API](https://www.rollupjs.org/guide/en/#javascript-api).\n\n\n## Options\n\n### `include`  \nType: `String` | `Array[...String]`  \nDefault: `null`  \n\nA [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should operate on. By default all files are targeted.\n\n\n### `exclude`  \nType: `String` | `Array[...String]`  \nDefault: `null`  \n\nA [minimatch pattern](https://github.com/isaacs/minimatch), or array of patterns, which specifies the files in the build the plugin should _ignore_. By default no files are ignored.\n\n\n### `fn`\nType: `Function`  \nDefault: `null`  \n\nThis is **your function**. Create a function _(sync or async)_ that takes one argument (the source input), optionally a second parameter can be provided to have access to the [options](#options).  \n    \n_The manipulated code can be returned as a:_\n - **string**\n - an **array** with the code at index ``0`` and an optional sourcemap at index ``1``\n - ``code`` and the optional ``map`` inside of an **object** (``{code: \u003ccode\u003e, map: \u003cmap\u003e}``).\n\n```js\n// Example A:\nfn: source =\u003e {\n    let code = source.replace(\"foo\", \"bar\");\n    return code;\n}\n\n// Example B:\nfn: (source, options) =\u003e {\n    let code = source.replace(\"foo\", \"bar\");\n    let map = mySourcemapGeneratingFN();\n\n    if (options.id === \"my-file\") {\n        console.log(\"my-file is currently getting processed\");\n    }\n    \n    return [ code, map ];\n}\n\n// Example C:\nfn: source =\u003e {\n    let code = source.replace(\"foo\", \"bar\");\n    let map = mySourcemapGeneratingFN();\n    return { code, map };\n}    \n```\n#### `options`\nFor global plugins, only the ``id`` is available (which is the filename). Output plugins also have access to the following parameters:\n - ``chunk``\n - ``outputOptions``\n - ``meta``  \n  \nMore information on those parameters can be found at the [rollup documentation](https://github.com/rollup/rollup/blob/master/docs/05-plugin-development.md#renderchunk).\n\n\n### `output`\nType: `Boolean`  \nDefault: `false`  \n\nSet to ``true`` if you want **your function** to be passed to the output file.\n\n\n### `showDiff`  \nType: `String`  \nDefault: `null`  \n\nA debugging method. If set to anything other than the string `\"file\"` a console output of [diff](https://github.com/kpdecker/jsdiff) is shown. It is modified a little and looks much like the default output of diff from the [GNU diffutils](https://www.gnu.org/software/diffutils/), with colors on top. If set to `\"file\"` the whole file with insertions and deletions is shown. Either way it only gets logged if there are any changes at all. \n\n\n## License\n\n[MIT](https://opensource.org/licenses/MIT)\n\nCopyright (c) 2022, UmamiAppearance\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumamiappearance%2Frollup-plugin-your-function","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fumamiappearance%2Frollup-plugin-your-function","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumamiappearance%2Frollup-plugin-your-function/lists"}