Registry / devops / rollup-plugin-tree-shakeable

rollup-plugin-tree-shakeable

JSON →
library2.0.0jsnpmunverified

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.

npm install rollup-plugin-tree-shakeable
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-TREE
R
rollup-plugin-tree-shakeable
devopsjavascriptv2.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import treeShakeable from 'rollup-plugin-tree-shakeable'
✗ const treeShakeable = require('rollup-plugin-tree-shakeable')
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.
Plugin
✓ import type { Plugin } from 'rollup'
✗ import { Plugin } from 'rollup-plugin-tree-shakeable'
The plugin does not export a Plugin type; you need to import it from Rollup itself.
application
✓ import treeShakeable from 'rollup-plugin-tree-shakeable'; export default { plugins: [treeShakeable()] }
✗ export default { plugins: [treeShakeable] }
treeShakeable is a function that must be called; omitting parentheses will not produce a plugin instance.

Shows basic Rollup config using treeShakeable and demonstrates how top-level function calls get annotated with @__PURE__.

// install: npm i rollup rollup-plugin-tree-shakeable import treeShakeable from 'rollup-plugin-tree-shakeable'; export default { input: 'src/index.js', output: { dir: 'output', format: 'esm', }, plugins: [treeShakeable()], }; // src/index.js (before plugin) const withLogging = fn => (...args) => { console.log('start'); try { return fn(...args); } finally { console.log('end'); } }; export const f1 = withLogging(() => 1); export const f2 = withLogging(() => 2); // After plugin: each top-level call gets @__PURE__ // export const f1 = /* @__PURE__*/ withLogging(() => 1); // export const f2 = /* @__PURE__*/ withLogging(() => 2);
Debug
Known issues
breakingOnly use if your package is actually tree-shakeable: each export works independently when others are stripped.
fix
Verify that your module does not have side-effectful top-level expressions that depend on other exports.
affects: >=1.0.0
gotchaDoes NOT handle all cases: side effects inside exported function bodies are not annotated.
fix
Manually add @__PURE__ or refactor code that produces side effects inside functions.
affects: >=1.0.0
breakingv2.0.0 requires Node >= 22; older versions of Node are unsupported.
fix
Upgrade to Node 22 or stay on v1.0.3.
affects: >=2.0.0
deprecatedv1.x may not be receiving further updates; upgrade to v2 for ongoing maintenance.
fix
Update to latest: npm install rollup-plugin-tree-shakeable@latest
affects: <2.0.0
Errors
Common errors & fixes
Require is not defined in ES module scope
Package uses ESM; require() is not supported without special configuration.
fix
Use import syntax or set "type": "module" in package.json and consume as ES module.
Cannot find module 'rollup-plugin-tree-shakeable'
Plugin not installed or path incorrect.
fix
Run npm install rollup-plugin-tree-shakeable --save-dev and ensure import path is correct.
TypeError: treeShakeable is not a plugin function
treeShakeable() returns a plugin object, but treeShakeable alone is the function, not a plugin.
fix
Call treeShakeable() in the plugins array: plugins: [treeShakeable()]
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
rolluprequiredRollup plugin API is required; plugin won't work without it.
Agent activity
7 hits · last 30 days
node
6
Amazon
1
Resources
rollup-plugin-tree-shakeable — npm install rollup-plugin-tree-shakeable · libregistry