Babel plugin (v0.5.0) that automatically inserts #__PURE__ annotations on top-level call expressions and new expressions in assignment contexts, enabling UglifyJS and Terser to perform dead code elimination for improved bundle sizes. Targeted at libraries where top-level calls are generally side-effect-free, but may break code if misapplied. Current stable version is 0.5.0 with Node >= 18 and peer dependency on @babel/core ^7.0.0. The plugin is actively maintained but the API is simple and stable. Compared to alternatives like 'annotate-pure-call-in-variable-declarator', this plugin covers broader contexts (IIFEs, nested IIFEs) and is more widely adopted.
npm install babel-plugin-annotate-pure-callsVerified import paths — ran on the pinned version, not inferred.
Shows installation, configuration, and a simple example of the plugin annotating a pure call.
Use only for libraries where top-level calls are predominantly side-effect-free; manually review or use additional linting.
Understand the plugin's scope: only variable declarations and assignment expressions at top level are annotated.
Upgrade Node to version 18 or later, or use an older version of the plugin (if available).
Run npm install --save-dev babel-plugin-annotate-pure-calls in the project directory.
Install @babel/core: npm install --save-dev @babel/core (ensure version ^7.0.0).
Use require('babel-plugin-annotate-pure-calls') instead of a string in Babel transform options.