diff --git a/.gitignore b/.gitignore index 34c6b93..3a90a94 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ node_modules dist yarn.lock package-lock.json +nostr.js diff --git a/README.md b/README.md index 19cdfed..4733267 100644 --- a/README.md +++ b/README.md @@ -70,3 +70,20 @@ pool.addRelay('') All functions expect bytearrays as hex strings and output bytearrays as hex strings. For other utils please read the source (for now). + +### Using from the browser (if you don't want to use a bundler) + +You can import nostr-tools as an ES module. Just add a script tag like this: + +```html + +``` + +And import whatever function you would import from `"nostr-tools"` in a bundler. + +## License + +Public domain. diff --git a/build.js b/build.js new file mode 100755 index 0000000..d2f852d --- /dev/null +++ b/build.js @@ -0,0 +1,25 @@ +#!/usr/bin/env node + +const esbuild = require('esbuild') +const alias = require('esbuild-plugin-alias') +const nodeGlobals = require('@esbuild-plugins/node-globals-polyfill').default + +const buildOptions = { + entryPoints: ['index.js'], + outfile: 'nostr.js', + bundle: true, + format: 'esm', + plugins: [ + alias({ + stream: require.resolve('readable-stream') + }), + nodeGlobals({buffer: true}) + ], + define: { + window: 'self', + global: 'self' + }, + loader: {'.js': 'jsx'} +} + +esbuild.build(buildOptions).then(() => console.log('build success.')) diff --git a/package.json b/package.json index cafef9f..91a5321 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "nostr-tools", - "version": "0.23.0", + "version": "0.23.1", "description": "Tools for making a Nostr client.", "repository": { "type": "git", @@ -30,7 +30,15 @@ "client" ], "devDependencies": { + "@esbuild-plugins/node-globals-polyfill": "^0.1.1", + "esbuild": "^0.14.38", + "esbuild-plugin-alias": "^0.2.1", "eslint": "^8.5.0", - "eslint-plugin-babel": "^5.3.1" + "eslint-plugin-babel": "^5.3.1", + "events": "^3.3.0", + "readable-stream": "^3.6.0" + }, + "scripts": { + "prepublish": "node build.js" } }