Registry / devops / rollup-plugin-pure

rollup-plugin-pure

JSON →
library0.4.0jsnpmunverified

Rollup/Vite plugin that automatically injects /*#__PURE__*/ annotations before specific function calls and /*@__NO_SIDE_EFFECTS__*/ before function declarations, enabling better tree-shaking for libraries with definition functions like Vue's defineComponent. Current stable version is 0.4.0, actively maintained. Supports regex function names, uses AST-based approach, and handles Rollup's awareness of pure annotations. Key differentiator: automatic annotation injection without manual marks, works with Vite and Rollup 3/4.

npm install rollup-plugin-pure
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-PURE
R
rollup-plugin-pure
devopsjavascriptv0.4.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.

PluginPure
✓ import { PluginPure } from 'rollup-plugin-pure'
✗ import PluginPure from 'rollup-plugin-pure'
Named export; default import is not available.
PluginPure as rollupPluginPure
✓ import { PluginPure as rollupPluginPure } from 'rollup-plugin-pure'
✗ const rollupPluginPure = require('rollup-plugin-pure').PluginPure;
CommonJS users should use destructured require; ESM is also supported.
PluginPure type
✓ import type { PluginPure } from 'rollup-plugin-pure'
✗ import { PluginPure } from 'rollup-plugin-pure'
Type-only import is safe but not required; PluginPure is also a runtime value.

Configures Vite to annotate defineComponent and regex-matched functions as pure, targeting files ending with 'pure.js' except those starting with 'im'.

// vite.config.ts import { PluginPure } from 'rollup-plugin-pure'; import { defineConfig } from 'vite'; export default defineConfig({ plugins: [ PluginPure({ functions: ['defineComponent', /^define(Page|Meta)$/], include: [/(?<!im)pure\.js$/], // exclude: [], // sourcemap: true, }), ], });
Debug
Known issues
breakingPlugin name changed in v0.3.0 from 'rollup-plugin-pure' to 'PluginPure' export
fix
Update import to correctly use named export PluginPure.
affects: <0.3.0
breakingAST-based approach introduced in v0.3.0; old RegExp-based approach removed
fix
Migrate to new configuration; see changelog for details.
affects: <0.3.0
gotchaWhen Rollup already marks a function as pure, the plugin may not add an annotation, leading to no effect
fix
Check if Rollup's built-in pure detection covers your functions; if not, adjust your configuration.
affects: >=0.4.0
deprecatedSupport for Rollup <3.0 may be dropped in future versions
fix
Upgrade to Rollup 3 or 4.
affects: <3.0
gotchaUsing `include` glob may not match expected files if patterns conflict with `exclude`
fix
Test patterns in the playground or use more specific include/exclude rules.
affects: >=0.4.0
Errors
Common errors & fixes
Plugin 'rollup-plugin-pure' does not provide a default export, but a named export 'PluginPure' is available.
Default import used instead of named import.
fix
Use import { PluginPure } from 'rollup-plugin-pure' instead.
TypeError: PluginPure is not a constructor
PluginPure is a function (factory), not a class. Calling new PluginPure() fails.
fix
Call PluginPure({...}) without new.
Error: Must specify at least one function name or regex in 'functions' option
Missing or empty functions array in configuration.
fix
Provide an array of function names or regex patterns in the functions option.
Upgrade
Version history
0.4.0latest on npm
Audit
Dependencies
rollupoptionalpeer dependency required for Rollup integration
Agent activity
4 hits · last 30 days
node
4
Resources
rollup-plugin-pure — npm install rollup-plugin-pure · libregistry