unplugin-pure
raw JSON → 0.3.2 verified Fri May 01 auth: no javascript
Automatically inject /* #__PURE__ */ annotations before specified function calls in Rollup, Vite, esbuild, and rspack builds to improve tree-shaking. Current stable version is 0.3.2 with infrequent releases. Supports all major bundlers via unplugin interface, includes TypeScript types, and allows flexible function matching via functions array and include/exclude patterns. Unlike manual annotations, this plugin automates the process for library authors.
Common errors
error Uncaught TypeError: PluginPure is not a function ↓
cause Importing as default when using ESM but named export is required.
fix
Use
import { PluginPure } from 'unplugin-pure' error Cannot find module 'unplugin-pure' or its corresponding type declarations. ↓
cause Package not installed or TypeScript not configured to resolve node_modules types.
fix
Run
npm install -D unplugin-pure and ensure tsconfig.json includes 'moduleResolution': 'node' or 'bundler'. error The requested module 'unplugin-pure' does not provide an export named 'default' ↓
cause Using default import with ESM when package only has named exports.
fix
Use named import:
import { PluginPure } from 'unplugin-pure' error RollupError: Could not resolve 'unplugin-pure' ↓
cause Package not installed or bundler config missing node_modules resolution.
fix
Install the package and ensure bundler can resolve it.
Warnings
gotcha Default export named PluginPure, not unpluginPure. Importing unpluginPure will result in undefined. ↓
fix Use import { PluginPure } from 'unplugin-pure'
gotcha The include option uses RegExp or string patterns, not globs. Misusing glob patterns will silently match nothing. ↓
fix Use RegExp, e.g., /\.(vue|jsx?)$/ or a string for exact paths.
deprecated rollup-plugin-pure is deprecated; unplugin-pure is its successor. ↓
fix Migrate to unplugin-pure as described in the README.
gotcha Works only with named function calls; does not handle property access like module.defineComponent. ↓
fix Wrap in a local const: const defineComp = module.defineComponent; then annotate defineComp.
gotcha Rollup peer dependency is required even when using Vite or esbuild? Not required if using esbuild or rspack alone; for Vite, Rollup is bundled but peer dep may still be needed. ↓
fix Ensure rollup is installed when using Vite config.
Install
npm install unplugin-pure yarn add unplugin-pure pnpm add unplugin-pure Imports
- PluginPure wrong
import { PluginPure } from 'unplugin-pure/vite'correctimport { PluginPure } from 'unplugin-pure' - esbuildPure wrong
import esbuildPure from 'unplugin-pure'correctimport { esbuildPure } from 'unplugin-pure' - unpluginPureFactory
import { unpluginPureFactory } from 'unplugin-pure'
Quickstart
import { defineConfig } from 'vite'
import { PluginPure } from 'unplugin-pure'
export default defineConfig({
plugins: [
PluginPure({
functions: ['defineComponent', 'createApp'],
include: [/(?<!im)pure\.js$/],
exclude: ['node_modules'],
sourcemap: true,
}),
],
})