UNPKG

1.84 kBMarkdownView Raw
1# Browser Builds
2
3Bitcore and most official submodules work in the browser, thanks to [browserify](http://browserify.org/) (some modules are not fully compatible with web browsers).
4
5The easiest and recommended way to use them, is via [Bower](http://bower.io/), a browser package manager, and get the release bundles. For example, when building an app that uses `bitcore` and `bitcore-mnemonic`, you do:
6
7```sh
8bower install bitcore-lib
9bower install bitcore-mnemonic
10```
11
12You can also use a `bower.json` file to store the dependencies of your project:
13
14```json
15{
16 "name": "Your app name",
17 "version": "0.0.1",
18 "license": "MIT",
19 "dependencies": {
20 "bitcore-lib": "^0.13.7",
21 "bitcore-mnemonic": "^1.0.1"
22 }
23}
24```
25
26and run `bower install` to install the dependencies.
27
28After this, you can include the bundled release versions in your HTML file:
29
30```html
31<!DOCTYPE html>
32<html lang="en">
33
34<head>
35 <meta charset="utf-8">
36 <script src="bower_components/bitcore/bitcore-lib.min.js"></script>
37 <script src="bower_components/bitcore-mnemonic/bitcore-mnemonic.min.js"></script>
38</head>
39
40<body>
41
42 <script type="text/javascript">
43 var bitcore = require('bitcore-lib');
44 var Mnemonic = require('bitcore-mnemonic');
45 // etc...
46 </script>
47
48</body>
49
50</html>
51```
52
53## Building Custom Bundles
54
55If you want to use a specific version of a module, instead of a release version (not recommended), you must run browserify yourself. You can get a minified browser bundle by running the following on the project root folder.
56
57```sh
58browserify --require ./index.js:bitcore-lib | uglifyjs > bitcore-lib.min.js
59```
60
61```sh
62browserify --require ./index.js:bitcore-mnemonic --external bitcore-lib | uglifyjs > bitcore-mnemonic.min.js
63```
64
65In many of the modules you can also run the command to build a browser bundle:
66
67```sh
68gulp browser
69```