{"id":16351590,"url":"https://github.com/tomeraberbach/rollup-plugin-tree-shakeable","last_synced_at":"2025-03-21T00:31:03.498Z","repository":{"id":238037873,"uuid":"795742445","full_name":"TomerAberbach/rollup-plugin-tree-shakeable","owner":"TomerAberbach","description":"🌳 A Rollup plugin that automatically annotates your module as tree shakeable.","archived":false,"fork":false,"pushed_at":"2024-10-21T03:07:06.000Z","size":260,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-17T19:12:10.297Z","etag":null,"topics":["bundler","esbuild","node-package","rollup","rollup-plugin","tree-shakeable","tree-shaking"],"latest_commit_sha":null,"homepage":"https://npm.im/rollup-plugin-tree-shakeable","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TomerAberbach.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":null,"funding":null,"license":"license-apache","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":"2024-05-03T23:58:35.000Z","updated_at":"2024-11-26T16:47:34.000Z","dependencies_parsed_at":"2024-05-04T00:30:31.872Z","dependency_job_id":"3233bbf0-96a5-44fd-891b-28e666ea1801","html_url":"https://github.com/TomerAberbach/rollup-plugin-tree-shakeable","commit_stats":null,"previous_names":["tomeraberbach/rollup-plugin-tree-shakeable"],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomerAberbach%2Frollup-plugin-tree-shakeable","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomerAberbach%2Frollup-plugin-tree-shakeable/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomerAberbach%2Frollup-plugin-tree-shakeable/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TomerAberbach%2Frollup-plugin-tree-shakeable/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TomerAberbach","download_url":"https://codeload.github.com/TomerAberbach/rollup-plugin-tree-shakeable/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244717348,"owners_count":20498281,"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":["bundler","esbuild","node-package","rollup","rollup-plugin","tree-shakeable","tree-shaking"],"created_at":"2024-10-11T01:23:18.113Z","updated_at":"2025-03-21T00:31:03.149Z","avatar_url":"https://github.com/TomerAberbach.png","language":"TypeScript","funding_links":["https://github.com/sponsors/TomerAberbach"],"categories":[],"sub_categories":[],"readme":"\u003ch1 align=\"center\"\u003e\n  rollup-plugin-tree-shakeable\n\u003c/h1\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://npmjs.org/package/rollup-plugin-tree-shakeable\"\u003e\n    \u003cimg src=\"https://badgen.net/npm/v/rollup-plugin-tree-shakeable\" alt=\"version\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/TomerAberbach/rollup-plugin-tree-shakeable/actions\"\u003e\n    \u003cimg src=\"https://github.com/TomerAberbach/rollup-plugin-tree-shakeable/workflows/CI/badge.svg\" alt=\"CI\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/sponsors/TomerAberbach\"\u003e\n    \u003cimg src=\"https://img.shields.io/static/v1?label=Sponsor\u0026message=%E2%9D%A4\u0026logo=GitHub\u0026color=%23fe8e86\" alt=\"Sponsor\"\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  A Rollup plugin that automatically annotates your module as tree shakeable.\n\u003c/div\u003e\n\n## Install\n\n```sh\n$ npm i rollup-plugin-tree-shakeable\n```\n\n## Usage\n\n```js\nimport treeShakeable from 'rollup-plugin-tree-shakeable'\n\nexport default {\n  input: `src/index.js`,\n  output: {\n    dir: `output`,\n    format: `esm`,\n  },\n  plugins: [treeShakeable()],\n}\n```\n\n## Why?\n\nImagine you have code similar to this:\n\n**`src/index.js`**:\n\n\u003c!-- eslint-disable no-inline-comments --\u003e\n\n```js\nconst withLogging =\n  fn =\u003e\n  (...args) =\u003e {\n    console.log(`Started call!`)\n    try {\n      return fn(...args)\n    } finally {\n      console.log(`Finished call!`)\n    }\n  }\n\nexport const f1 = withLogging(/* ... */)\nexport const f2 = withLogging(/* ... */)\nexport const f3 = withLogging(/* ... */)\n// ...\n```\n\nYou might expect that if a user of your package writes\n`import { f1 } from 'your-package'`, then bundlers will\n[tree shake](https://developer.mozilla.org/en-US/docs/Glossary/Tree_shaking) and\nomit `f1`, `f2`, etc. from the final bundle. Unfortunately, bundlers will\ngenerally include _all_ of your package's code in this case\n([yes, even if you set `\"sideEffects\": false` in your `package.json`](https://github.com/evanw/esbuild/issues/1241))\nbecause `withLogging` is called at the \"top-level\" of your package and the\nbundler cannot easily tell the call is side-effect free. There are _many_ other\ncode patterns that cause the same issue.\n\nThis plugin solves the problem by automatically adding\n[`@__PURE__` annotations](https://esbuild.github.io/api/#pure) to all top-level\nexpressions in your code that prevent tree-shaking, with the assumption that\nyour package is actually [pure](https://en.wikipedia.org/wiki/Pure_function),\nbut bundlers need a little convincing of that.\n\nFor example, for the code above, running it through this plugin would result in\nthe following code:\n\n\u003c!-- eslint-disable no-inline-comments --\u003e\n\n```js\nconst withLogging =\n  fn =\u003e\n  (...args) =\u003e {\n    console.log(`Started call!`)\n    try {\n      return fn(...args)\n    } finally {\n      console.log(`Finished call!`)\n    }\n  }\n\nexport const f1 = /* @__PURE__*/ withLogging(/* ... */)\nexport const f2 = /* @__PURE__*/ withLogging(/* ... */)\nexport const f3 = /* @__PURE__*/ withLogging(/* ... */)\n// ...\n```\n\nAnd if a user of your package writes `import { f1 } from 'your-package'`, then\nbundlers _will_ tree shake and strip out all functions other than `f1` from the\nfinal bundle.\n\n\u003e [!CAUTION]\n\u003e\n\u003e Only use this plugin if your package is actually tree-shakeable, meaning that\n\u003e each export would still function correctly if all the other exports were\n\u003e stripped out.\n\u003e\n\u003e This plugin does not give your package that property. It only _convinces_\n\u003e bundlers that this is the case.\n\n## Contributing\n\nStars are always welcome!\n\nFor bugs and feature requests,\n[please create an issue](https://github.com/TomerAberbach/rollup-plugin-tree-shakeable/issues/new).\n\n## License\n\n[MIT](https://github.com/TomerAberbach/rollup-plugin-tree-shakeable/blob/main/license)\n© [Tomer Aberbach](https://github.com/TomerAberbach) \\\n[Apache 2.0](https://github.com/TomerAberbach/rollup-plugin-tree-shakeable/blob/main/license-apache) ©\n[Google](https://github.com/TomerAberbach/rollup-plugin-tree-shakeable/blob/main/notice-apache)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomeraberbach%2Frollup-plugin-tree-shakeable","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftomeraberbach%2Frollup-plugin-tree-shakeable","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftomeraberbach%2Frollup-plugin-tree-shakeable/lists"}