rollup-plugin-bookmarklet
raw JSON → 5.0.12 verified Mon Apr 27 auth: no javascript
Rollup plugin that prepends the 'javascript:' prefix to the bundle output, converting a script into a bookmarklet. Current stable version is 5.0.12, released under a semver cadence. It supports Rollup v2, v3, and v4. Unlike manual prefixing, this plugin integrates seamlessly into the build pipeline and works with minifiers like @rollup/plugin-terser. It ships TypeScript type definitions and requires Node.js >=18. Key differentiator: minimal, focused plugin that does one thing with zero configuration.
Common errors
error Cannot find module 'rollup-plugin-bookmarklet' ↓
cause Package not installed or wrong import path
fix
Run 'npm install -D rollup-plugin-bookmarklet' and use correct import.
error The plugin 'bookmarklet' doesn't export a valid plugin object ↓
cause Using require() instead of import on ESM-only package
fix
Use 'import bookmarklet from 'rollup-plugin-bookmarklet'' in ESM context.
error Error: Unexpected token: punc ()) ↓
cause Bookmarklet plugin applied before minification
fix
Reorder plugins: put terser() before bookmarklet().
Warnings
breaking Requires Node.js >=18 ↓
fix Upgrade Node.js to version 18 or later.
breaking Drop support for Rollup v1 ↓
fix Use Rollup v2, v3, or v4.
deprecated Deprecated usage: not calling bookmarklet() as a function ↓
fix Ensure to invoke bookmarklet() as a function in your Rollup plugins array.
gotcha Output format must be 'iife' for bookmarklet to work correctly ↓
fix Set output.format to 'iife' in your Rollup configuration.
gotcha Must be placed after minification plugins like terser to avoid syntax errors ↓
fix Order plugins: minification first, then bookmarklet.
Install
npm install rollup-plugin-bookmarklet yarn add rollup-plugin-bookmarklet pnpm add rollup-plugin-bookmarklet Imports
- default (bookmarklet) wrong
const bookmarklet = require('rollup-plugin-bookmarklet')correctimport bookmarklet from 'rollup-plugin-bookmarklet' - BookmarkletOptions
import type { BookmarkletOptions } from 'rollup-plugin-bookmarklet' - bookmarklet function call wrong
new bookmarklet()correctbookmarklet()
Quickstart
import bookmarklet from 'rollup-plugin-bookmarklet';
import terser from '@rollup/plugin-terser';
export default {
input: 'src/main.js',
output: {
file: 'bundle.js',
format: 'iife'
},
plugins: [
terser(),
bookmarklet()
]
};