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.
Common errors
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.
Warnings
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.
Install
npm install esbuild-plugin-bookmarklet yarn add esbuild-plugin-bookmarklet pnpm add esbuild-plugin-bookmarklet Imports
- default wrong
const bookmarkletPlugin = require('esbuild-plugin-bookmarklet')correctimport bookmarkletPlugin from 'esbuild-plugin-bookmarklet' - default wrong
import bookmarkletPlugin from 'https://deno.land/x/esbuild_plugin_bookmarklet/mod.js'correctimport bookmarkletPlugin from 'https://deno.land/x/esbuild_plugin_bookmarklet@1.1.0/mod.js' - default
import bookmarkletPlugin from 'esbuild-plugin-bookmarklet' // in Node ESM
Quickstart
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');