From 7ee8a85eb0c6e33c1eaf1330d7136de3e0c53798 Mon Sep 17 00:00:00 2001 From: Daniel Cousens Date: Mon, 5 Jan 2015 12:54:03 +1100 Subject: [PATCH] README: improve browserify instructions --- README.md | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index e941e4f..be9c453 100644 --- a/README.md +++ b/README.md @@ -51,16 +51,33 @@ From the repo: ### Browser -From the repository: Compile `bitcoinjs-min.js` with the following command: +If you're familiar with how to use browserify, ignore this and proceed normally. +These steps are advisory only and allow you to use the API to its full extent. - $ npm run-script compile +[Browserify](https://github.com/substack/node-browserify) is assumed to be installed for these steps. -From NPM: - $ npm -g install bitcoinjs-lib browserify uglify-js - $ browserify -r bitcoinjs-lib -s bitcoin | uglifyjs > bitcoinjs.min.js +From your repository, create a `bitcoin.js` file -After loading this file in your browser, you will be able to use the global `bitcoin` object. +``` javascript +var bitcoin = { + base58: require('bs58'), + ecurve: require('ecurve'), + BigInteger: require('bigi'), + Buffer: require('buffer') +} + +var bitcoinjs = require('bitcoinjs-lib') +for (var a in bitcoinjs) bitcoin[a] = bitcoinjs[a] + +module.exports = bitcoin +``` + +Then, using browserify, compile `bitcoin.js` for use in the browser: + + $ browserify bitcoin.js -s bitcoin > dist/bitcoin.js + +You will then be able to load `dist/bitcoin.js` into your browser, with each of the dependencies above accessible from the global `bitcoin` object. ## Examples