{"id":13774833,"url":"https://github.com/wmzy/rollup-plugin-by-output","last_synced_at":"2025-05-11T07:30:42.762Z","repository":{"id":34871865,"uuid":"185951170","full_name":"wmzy/rollup-plugin-by-output","owner":"wmzy","description":"Apply plugins according to special output option, reduce config and save time.","archived":true,"fork":false,"pushed_at":"2023-01-04T21:45:29.000Z","size":1275,"stargazers_count":5,"open_issues_count":12,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-12T16:10:01.661Z","etag":null,"topics":["output","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/wmzy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-05-10T08:35:37.000Z","updated_at":"2023-03-04T04:43:22.000Z","dependencies_parsed_at":"2023-01-15T09:46:53.208Z","dependency_job_id":null,"html_url":"https://github.com/wmzy/rollup-plugin-by-output","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmzy%2Frollup-plugin-by-output","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmzy%2Frollup-plugin-by-output/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmzy%2Frollup-plugin-by-output/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/wmzy%2Frollup-plugin-by-output/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/wmzy","download_url":"https://codeload.github.com/wmzy/rollup-plugin-by-output/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224175643,"owners_count":17268390,"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":["output","rollup-plugin"],"created_at":"2024-08-03T17:01:30.799Z","updated_at":"2024-11-17T09:31:26.156Z","avatar_url":"https://github.com/wmzy.png","language":"JavaScript","funding_links":[],"categories":["Plugins"],"sub_categories":["Output"],"readme":"[![Build Status](https://travis-ci.org/wmzy/rollup-plugin-by-output.svg?branch=master)](https://travis-ci.org/wmzy/rollup-plugin-by-output)\n[![Coverage Status](https://coveralls.io/repos/github/wmzy/rollup-plugin-by-output/badge.svg?branch=master)](https://coveralls.io/github/wmzy/rollup-plugin-by-output?branch=master)\n# rollup-plugin-by-output\n\n\u003e Apply Rollup Plugin by OutputOptions\n\n## Install\n\n```bash\nnpm i -D rollup-plugin-by-output\n```\n\n## Usage\n\n```bash\n// rollup.config.js\nimport babel from 'rollup-plugin-babel';\nimport terser from 'rollup-plugin-terser';\nimport plugins, {file} from 'rollup-plugin-by-output';\n\n\nexport default {\n  // ...\n  plugins: plugins(babel(), [file(pkg.browser), terser()]),\n  output: [\n    {\n      globals: {\n        lodash: '_'\n      },\n      name: pkg.name,\n      file: pkg.browser,\n      format: 'umd'\n    },\n    {\n      file: pkg.main,\n      format: 'cjs'\n    },\n    {\n      file: pkg.module,\n      format: 'es'\n    }\n  ]\n};\n\n```\n\n## What\n\nRollup support multiple outputs with the same input. But sometime we want to apply different plugins for these outputs.\nThe most common scenario is apply the [terser](https://github.com/TrySound/rollup-plugin-terser) plugin for a minify bundle.\nBefore we can write a config array, but there are a lot of duplicate code and operations.\n\nThis plugin (maybe not a plugin) gives you a slightly elegant and efficient solution for this scene.\n\n## APIs\n\n```js\nimport plugins, {when, whenAll, prop, format, file} from 'rollup-plugin-by-output';\n```\n\n### Plugins\n\n```js\n{\n  //...\n  plugins: [pluginA, when(filter, pluginB), pluginsC, ..., ...whenAll(anotherFilter, pluginD, pluginE)]\n}\n```\n\nsame as:\n\n```js \n{\n  // ...\n  plugins: plugins(pluginA,\n    [filter, pluginB],// same as when\n    pluginsC, ..., \n    [anotherFilter, pluginD, pluginE] // same as whenAll and flat\n  )\n}\n```\n\nThe filter is a predicate function, the parameter is an output config object. If the filter return a truthy value, the rest plugins will be apply for the output.\n\n`when` and `whenAll` is convenient for few filters and `plugins` is convenient for multiple filters.\n\n### Filter helpers\n\nThere are three [simple](https://github.com/wmzy/rollup-plugin-by-output/blob/master/src/index.js#L53) but useful filter helpers: `prop`, `format`, `file`.\n\nWith them you can write like:\n```js \n// output \n[\n  {\n    name: pkg.name,\n    file: pkg.browser,\n    format: 'umd'\n    }\n]\n\nwhen(format('umd'), pluginA)\n// same as\nwhen(format(/^umd$/), pluginA)\n// same as\nwhen(format(f =\u003e f === 'umd'), pluginA)\n\nwhen(file(pkg.browser), pluginA)\n\nformat = filter =\u003e prop('format', filter)\nfile = filter =\u003e prop('file', filter)\n```\n\n## Examples\n\n* [lib-starter](https://github.com/wmzy/lib-starter/blob/master/rollup.config.js)\n\n## Workflow\n\n```bash\n# develop\nnpm start\n\n# build\nnpm run build\n\n# test\nnpm test\n\n# commit changes\nnpm run commit\n\n# publish\nnpm publish\n```\n## License\n\nMIT\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwmzy%2Frollup-plugin-by-output","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwmzy%2Frollup-plugin-by-output","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwmzy%2Frollup-plugin-by-output/lists"}