bitpay / bitcore-lib

A pure and powerful JavaScript Bitcoin library
https://bitcore.io/
Other
611 stars 1.03k forks source link

browser_flo.md #212

Closed spshah closed 6 years ago

spshah commented 6 years ago

Browser Builds

Florincore and most official submodules work in the browser, thanks to browserify (some modules are not fully compatible with web browsers).

The easiest and recommended way to use them, is via Bower, a browser package manager, and get the release bundles. For example, when building an app that uses florincore and bitcore-mnemonic, you do:

bower install florincorecore-lib
bower install bitcore-mnemonic

You can also use a bower.json file to store the dependencies of your project:

{
  "name": "Your app name",
  "version": "0.0.1",
  "license": "MIT",
  "dependencies": {
    "florincore-lib": "^0.13.7",
    "bitcore-mnemonic": "^1.0.1"
  }
}

and run bower install to install the dependencies.

After this, you can include the bundled release versions in your HTML file:

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8">
  <script src="bower_components/florincore/florincore-lib.min.js"></script>
  <script src="bower_components/bitcore-mnemonic/bitcore-mnemonic.min.js"></script>
</head>

<body>

  <script type="text/javascript">
    var litecore = require('florincore-lib');
    var Mnemonic = require('bitcore-mnemonic');
    // etc...
  </script>

</body>

</html>

Building Custom Bundles

If 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.

browserify --require ./index.js:florincore-lib | uglifyjs > florincore-lib.min.js
browserify --require ./index.js:florincore-mnemonic --external florincore-lib | uglifyjs > bitcore-mnemonic.min.js

In many of the modules you can also run the command to build a browser bundle:

gulp browser
gabegattis commented 6 years ago

You made this targeting the wrong repo.