README: improve browserify instructions
This commit is contained in:
parent
abf870fb37
commit
7ee8a85eb0
1 changed files with 23 additions and 6 deletions
29
README.md
29
README.md
|
@ -51,16 +51,33 @@ From the repo:
|
||||||
|
|
||||||
### Browser
|
### 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
|
From your repository, create a `bitcoin.js` file
|
||||||
$ browserify -r bitcoinjs-lib -s bitcoin | uglifyjs > bitcoinjs.min.js
|
|
||||||
|
|
||||||
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
|
## Examples
|
||||||
|
|
Loading…
Reference in a new issue