{"id":18598145,"url":"https://github.com/agronkabashi/rollup-plugin-conditional","last_synced_at":"2025-04-10T18:30:46.612Z","repository":{"id":65412125,"uuid":"68958928","full_name":"AgronKabashi/rollup-plugin-conditional","owner":"AgronKabashi","description":"Conditionally execute rollup plugins.","archived":false,"fork":false,"pushed_at":"2019-01-24T09:06:50.000Z","size":103,"stargazers_count":19,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T01:43:29.660Z","etag":null,"topics":["build","build-tool","es2015","rollup","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/AgronKabashi.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2016-09-22T20:18:04.000Z","updated_at":"2022-02-04T23:41:59.000Z","dependencies_parsed_at":"2023-01-22T07:35:14.418Z","dependency_job_id":null,"html_url":"https://github.com/AgronKabashi/rollup-plugin-conditional","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgronKabashi%2Frollup-plugin-conditional","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgronKabashi%2Frollup-plugin-conditional/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgronKabashi%2Frollup-plugin-conditional/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AgronKabashi%2Frollup-plugin-conditional/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AgronKabashi","download_url":"https://codeload.github.com/AgronKabashi/rollup-plugin-conditional/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248271563,"owners_count":21075800,"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","build-tool","es2015","rollup","rollup-plugin"],"created_at":"2024-11-07T01:31:08.029Z","updated_at":"2025-04-10T18:30:46.191Z","avatar_url":"https://github.com/AgronKabashi.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rollup-plugin-conditional\nA proxy plugin for conditionally executing rollup plugins.\n\u003cbr\u003e\n\u003cstrong\u003eNOTE:\u003c/strong\u003e This plugin has entered maintenance only mode, meaning that only bugs will be fixed. See **`But do I really need it`** section to accomplish the same thing without a plugin.\n\n## Why\nThere are times when you only want to run a plugin if certain conditions are met. This plugin aims to simplify that setup.\n\n## But do I really need it?\nNot really, in relatively newer versions on rollup you can accomplish the same thing using a simple spread mechanic:\n\n```js\nexport default {\n  ...\n  plugins: [\n    ...isProduction ? [\n      licence(),\n      strip(),\n      uglify(),\n      gzip()\n    ] : []\n  ]\n};\n```\n\nIn the end, this syntax is better because:\n* It reduces the cost of overhead and increases performance slightly\n* It reduces your dependencies by one\n\n## Installation\n\n```bash\nnpm install rollup-plugin-conditional --save-dev\n```\n\n## Usage\n\n```js\nimport conditional from \"rollup-plugin-conditional\";\n// import other plugins\n\nconst isProduction = process.env.buildTarget === \"PROD\";\n\nexport default {\n  ...\n  plugins: [\n    ...\n    conditional(isProduction, [\n      licence(),\n      strip(),\n      uglify(),\n      gzip()\n    ]),\n\n    conditional(!isProduction, [\n      filesize()\n    ])\n  ]\n})\n```\n\nIt's also possible to nest conditionals but the recommendation is to keep the plugins as flat as possible:\n```js\nexport default {\n  ...\n  plugins: [\n    conditional(!isProduction, [\n      conditional(isLocalBuild, [\n        eslint()\n      ]),\n      watch()\n    ])\n  ]\n};\n```\n\n### Special cases\nUnfortunately some plugins, like rollup-plugin-serve, always assume that they will be executed so they perform some premature tasks before any of the life cycle hooks are called:\n\n```js\nimport serve from \"rollup-plugin-serve\";\n\nexport default {\n  ...\n  plugins: [\n    conditional(false, [ // false here will prevent any of the plugins' life cycle hooks from being executed\n      // rollup-plugin-serve will however instantiate a http(s)-server immediately and outside any of the life cycle hooks\n      // resulting in the http-server running even though we don't want it to.\n      serve()\n    ])\n  ]\n};\n```\n\nIn order to work around this we need to defer the initialisation by simply providing a callback method that returns the plugins:\n\n```js\nimport serve from \"rollup-plugin-serve\";\n\nexport default {\n  ...\n  plugins: [\n    conditional(false, () =\u003e [ // Notice the arrow function.\n      serve()\n    ])\n  ]\n};\n```\n\n## Backwards Compatibility Table\n\n| Rollup Version  | Plugin Version            |\n|-----------------|---------------------------|\n| 0.57+           | 3.x *(Recommended)*       |\n| 0.62 - 0.68.2   | 2.x                       |\n| \u003c 62            | 1.x                       |\n\n\n## Versioning\nThis project uses semantic versioning\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagronkabashi%2Frollup-plugin-conditional","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fagronkabashi%2Frollup-plugin-conditional","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fagronkabashi%2Frollup-plugin-conditional/lists"}