{"id":22260,"library":"rollup-plugin-tree-shakeable","title":"rollup-plugin-tree-shakeable","description":"A Rollup plugin (v2.0.0, latest) that automatically adds @__PURE__ annotations to top-level expressions in your JavaScript/TypeScript modules, convincing bundlers like Rollup, esbuild, and webpack that the module is side-effect free and enabling effective tree-shaking. Unlike setting `sideEffects: false` in package.json, which cannot handle function calls at module scope, this plugin annotates each call individually. Requires Node >= 22 and Rollup. Lightweight, zero-config, and actively maintained with few dependencies.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/TomerAberbach/rollup-plugin-tree-shakeable","tags":["javascript","bundle","pure","rollup","rollup-plugin","tree-shaking"],"install":[{"cmd":"npm install rollup-plugin-tree-shakeable","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-tree-shakeable","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-tree-shakeable","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Rollup plugin API is required; plugin won't work without it.","package":"rollup","optional":false}],"imports":[{"note":"Plugin has a default export; CommonJS require() may not work if the package is ESM-only (check your Rollup config). v2.0.0 likely ESM-only.","wrong":"const treeShakeable = require('rollup-plugin-tree-shakeable')","symbol":"default","correct":"import treeShakeable from 'rollup-plugin-tree-shakeable'"},{"note":"The plugin does not export a Plugin type; you need to import it from Rollup itself.","wrong":"import { Plugin } from 'rollup-plugin-tree-shakeable'","symbol":"Plugin","correct":"import type { Plugin } from 'rollup'"},{"note":"treeShakeable is a function that must be called; omitting parentheses will not produce a plugin instance.","wrong":"export default { plugins: [treeShakeable] }","symbol":"application","correct":"import treeShakeable from 'rollup-plugin-tree-shakeable'; export default { plugins: [treeShakeable()] }"}],"quickstart":{"code":"// install: npm i rollup rollup-plugin-tree-shakeable\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// src/index.js (before plugin)\nconst withLogging = fn => (...args) => {\n  console.log('start');\n  try { return fn(...args); } finally { console.log('end'); }\n};\nexport const f1 = withLogging(() => 1);\nexport const f2 = withLogging(() => 2);\n\n// After plugin: each top-level call gets @__PURE__\n// export const f1 = /* @__PURE__*/ withLogging(() => 1);\n// export const f2 = /* @__PURE__*/ withLogging(() => 2);","lang":"javascript","description":"Shows basic Rollup config using treeShakeable and demonstrates how top-level function calls get annotated with @__PURE__."},"warnings":[{"fix":"Verify that your module does not have side-effectful top-level expressions that depend on other exports.","message":"Only use if your package is actually tree-shakeable: each export works independently when others are stripped.","severity":"breaking","affected_versions":">=1.0.0"},{"fix":"Manually add @__PURE__ or refactor code that produces side effects inside functions.","message":"Does NOT handle all cases: side effects inside exported function bodies are not annotated.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Upgrade to Node 22 or stay on v1.0.3.","message":"v2.0.0 requires Node >= 22; older versions of Node are unsupported.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Update to latest: npm install rollup-plugin-tree-shakeable@latest","message":"v1.x may not be receiving further updates; upgrade to v2 for ongoing maintenance.","severity":"deprecated","affected_versions":"<2.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use import syntax or set \"type\": \"module\" in package.json and consume as ES module.","cause":"Package uses ESM; require() is not supported without special configuration.","error":"Require is not defined in ES module scope"},{"fix":"Run npm install rollup-plugin-tree-shakeable --save-dev and ensure import path is correct.","cause":"Plugin not installed or path incorrect.","error":"Cannot find module 'rollup-plugin-tree-shakeable'"},{"fix":"Call treeShakeable() in the plugins array: plugins: [treeShakeable()]","cause":"treeShakeable() returns a plugin object, but treeShakeable alone is the function, not a plugin.","error":"TypeError: treeShakeable is not a plugin function"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}