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.

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().
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.
npm install rollup-plugin-bookmarklet
yarn add rollup-plugin-bookmarklet
pnpm add rollup-plugin-bookmarklet

Shows how to configure Rollup with the bookmarklet plugin to produce a minified bookmarklet.

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()
  ]
};