nostr-esbuild-plugin
v0.1.0
Published
esbuild plugin that resolves Nostr URIs to ESM modules
Readme
Nostr esbuild Plugin
esbuild plugin that resolves nostr: URIs to ESM modules.
This allows importing ESM modules published as
kind 1337 "code snippets"
Nostr events directly in your JavaScript or TypeScript code.
For example:
import { add } from "nostr:nevent1qqsqkjpn8l4r97tqysdh2lsmawrmpnhvnga8prk7tz48xh5js9hrk4spzemhxue69uhhyetvv9ujuurjd9kkzmpwdejhgqgkwaehxw309aex2mrp0yhxummnw3ezucnpdejqz9thwden5te0v35hgar09ec82c30wfjkccteqgsqgc0uhmxycvm5gwvn944c7yfxnnxm0nyh8tt62zhrvtd3xkj8fhgq8773y";
console.log(add(1, 2)); // Outputs: 3Installation
npm add -D esbuild-plugin-nostrUsage
Add nostrPlugin() to your esbuild configuration:
import * as esbuild from "esbuild";
import { nostrPlugin } from "esbuild-plugin-nostr";
await esbuild.build({
entryPoints: ["src/index.js"],
outfile: "./dist/main.js",
bundle: true,
plugins: [nostrPlugin({
// Optional fallback relays if not explicitly provided in the `nostr:` URI
relays: [
"wss://relay.primal.net",
"wss://relay.nostr.band",
],
timeout: 1000, // Optional timeout for fetching each event in milliseconds (default: 1000)
})],
});License
This is free and unencumbered software released into the public domain.
