esbuild-plugin-bookmarklet

raw JSON →
1.1.0 verified Fri May 01 auth: no javascript

An ESM-only, Deno-first esbuild plugin that generates bookmarklet code from JavaScript entry points. Current stable version 1.1.0 (2024) is covered by semver. It wraps esbuild output into a URL-encoded bookmarklet, requiring `iife` format and `write: false`. Differentiators: Deno-first (supports Node), simple setup, supports multiple entry points since v1.1.0.

error Error: Cannot find module 'esbuild-plugin-bookmarklet'
cause Package not installed or import path incorrect in Node.
fix
Run 'npm install esbuild-plugin-bookmarklet' and use correct import: import bookmarkletPlugin from 'esbuild-plugin-bookmarklet'
error TypeError: bookmarkletPlugin is not a function
cause Used default import incorrectly (e.g., destructured non-default export).
fix
Use default import: import bookmarkletPlugin from 'esbuild-plugin-bookmarklet' (no braces).
error Error: The plugin "esbuild-plugin-bookmarklet" rejected the build because the format is not 'iife'
cause Build format missing or not set to 'iife'.
fix
Add format: 'iife' to esbuild options.
error Error: "write" must be false when using this plugin
cause The write option in esbuild is true (default) or not set.
fix
Add write: false to esbuild options.
breaking Requires esbuild's `write: false` option; output is handled by plugin, not filesystem.
fix Set write: false in esbuild options.
gotcha Plugin only works with `format: 'iife'`; other formats may produce invalid bookmarklets.
fix Specify format: 'iife' in esbuild config.
deprecated Deno import without version pin may break with future releases.
fix Use import with version tag: https://deno.land/x/esbuild_plugin_bookmarklet@1.1.0/mod.js
gotcha ESM-only package; using require() results in error: require() of ES Module not supported.
fix Use import syntax. If in Node, ensure 'type': 'module' in package.json or rename file to .mjs.
gotcha Multiple entry points are supported since v1.1.0; earlier versions only handle single entry.
fix Upgrade to v1.1.0 or later for multiple entry points.
npm install esbuild-plugin-bookmarklet
yarn add esbuild-plugin-bookmarklet
pnpm add esbuild-plugin-bookmarklet

Minimal Node ESM build script that outputs a bookmarklet from index.js.

import * as esbuild from 'esbuild';
import bookmarkletPlugin from 'esbuild-plugin-bookmarklet';

await esbuild.build({
  entryPoints: ['index.js'],
  bundle: true,
  minify: true,
  outfile: 'bookmarklet.js',
  write: false,
  format: 'iife',
  plugins: [bookmarkletPlugin],
  target: ['chrome58', 'firefox57', 'safari11', 'edge16']
});

console.log('Bookmarklet generated as bookmarklet.js');