diff --git a/Gruntfile.js b/Gruntfile.js index 090f98a..8bf4826 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -16,7 +16,7 @@ module.exports = function(grunt) { stdout: true, stderr: true }, - command: 'node ./browser/browserify.js', + command: 'node ./browser/browserify.js -a', } }, watch: { @@ -25,7 +25,7 @@ module.exports = function(grunt) { tasks: ['markdown'] }, scripts: { - files: ['**/*.js', '**/*.html', '!**/node_modules/**', '!browser/bundle.js', '!browser/testdata.js'], + files: ['**/*.js', '**/*.html', '!**/node_modules/**', '!browser/bundle.js', '!browser/testdata.js', '!browser/vendor-bundle.js'], tasks: ['shell'], }, }, diff --git a/README.md b/README.md index b65dc77..ca5c591 100644 --- a/README.md +++ b/README.md @@ -257,13 +257,49 @@ Bitcore is still under heavy development and not quite ready for "drop-in" produ Bitcore needs some developer love. Please send pull requests for bug fixes, code optimization, and ideas for improvement. #Browser support -Work to enable Bitcore for use in the browser is ongoing. To build bitcore for the browser: +## Building the browser bundle +To build bitcore full bundle for the browser: +(this is automatically executed after you run `npm install`) + +``` +node browser/browserify.js -a +``` +This will generate a `browser/bundle.js` file which you can include +in your HTML to use bitcore in the browser. + +## + +##Example browser usage + +From example/simple.html ``` -npm install -g grunt-cli -grunt shell + + +
+ + + + ``` -You can check a usage example at examples/example.html +You can check a more complex usage example at examples/example.html + +## Generating a customized browser bundle +To generate a customized bitcore bundle, you can specify +which submodules you want to include in it with the -s option: + +``` +node browser/browserify.js -s Transaction,Address +``` +This will generate a `browser/bundle.js` containing only the Transaction + and Address class, with all their dependencies. +Use this option if you are not using the whole bitcore library, to optimize +the bundle size, script loading time, and general resource usage. #License diff --git a/browser/browserify.js b/browser/browserify.js index 1e8edbb..df52135 100644 --- a/browser/browserify.js +++ b/browser/browserify.js @@ -10,6 +10,7 @@ var fs = require('fs'); var browserify = require('browserify'); var browserPack = require('browser-pack'); +var program = require('commander'); // concat browser vendor files var exec = require('child_process').exec; @@ -22,6 +23,20 @@ var puts = function(error, stdout, stderr) { exec('cd browser; sh concat.sh', puts); +var list = function(val) { + return val.split(','); +}; + +program + .version('0.0.1') + .option('-a, --includeall', 'Include all submodules.') + .option('-s, --submodules