UNPKG

1.76 kBMarkdownView Raw
1# Browser Builds
2keyLib and most official submodules work in the browser, thanks to [browserify](http://browserify.org/) (some modules are not fully compatible with web browsers).
3
4The 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 `key-lib` and `btc-lib`, you do:
5
6```sh
7bower install key-lib
8bower install btc-lib
9```
10
11You can also use a `bower.json` file to store the dependencies of your project:
12
13```json
14{
15 "name": "Your app name",
16 "version": "0.0.1",
17 "license": "MIT",
18 "dependencies": {
19 "@owstack/key-lib": "^0.0.1",
20 "@owstack/btc-lib": "^0.13.7",
21 }
22}
23```
24
25and run `bower install` to install the dependencies.
26
27After this, you can include the bundled release versions in your HTML file:
28
29```html
30<!DOCTYPE html>
31<html lang="en">
32
33<head>
34 <meta charset="utf-8">
35 <script src="bower_components/key-lib/key.min.js"></script>
36 <script src="bower_components/btc-lib/btc.min.js"></script>
37</head>
38
39<body>
40
41 <script type="text/javascript">
42 var keyLib = require('@owstack/key-lib');
43 var btcLib = require('@owstack/btc-lib');
44 // etc...
45 </script>
46
47</body>
48
49</html>
50```
51
52## Building Custom Bundles
53If 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.
54
55```sh
56browserify --require ./index.js:key-lib | uglifyjs > key-lib.min.js
57```
58
59```sh
60browserify --require ./index.js:btc-lib --external btc-lib | uglifyjs > btc-lib.min.js
61```
62
63In many of the modules you can also run the command to build a browser bundle:
64```sh
65gulp browser
66```