-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
README: improve browser setup advice #315
Conversation
a70e6a9
to
16b517b
Compare
ha! you beat me at it and went the other way haha |
I would like to keep the |
Technically the API is not [fully] capable of being used without the external dependencies, as such, the resultant build is not really usable unless you force the user to customize |
With the current loosened type checking in |
@@ -61,7 +61,6 @@ | |||
"files": "test/*.js" | |||
}, | |||
"scripts": { | |||
"compile": "browserify ./src/index.js -s bitcoin | uglifyjs > bitcoinjs-min.js", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kyledrake I'm personally not a fan of this remaining since it provides a user with a bitcoinjs-lib
that isn't entirely usable as they would be missing particular dependencies to use some parts of our API.
We do allow duck typing which means they could include the other dependencies as individual minified files if they so wish; but it does encourage a bad practice IMHO.
Removing it forces them to use the browserify process themselves, there in learning how to use our API in its entirety from the get go.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I understand it, this PR removes it? I don't have a strong opinion about keeping it, I think Wei's instructions are better.
Browserbitcoinjs-lib works with browserify. If you want to compile a minified version with a global object in the browser, here is how. From the repository: # Checkout the latest tagged version of the source code
git clone https://github.com/bitcoinjs/bitcoinjs-lib.git
cd bitcoinjs-lib
git checkout `git describe`
# Install dependencies & compile `bitcoinjs-min.js`
npm install
npm run-script compile Alternatively, from NPM: npm install bitcoinjs-lib
cd node_modules/bitcoinjs-lib
npm run-script compile After loading the compiled bitcoinjs-min.js file in your browser, you will be able to use the global If you want to customize exported modules in the bundled, update |
The above suggested changes by @weilu (as I have quoted from her post elsewhere) don't make The entire thing boils down to "run I'm happy to add that step to what I've written as an alternative to the more advanced usage, but I think both the advanced and basic usage are important to avoid users constantly asking (#231 (comment), https://github.com/bitcoinjs/bitcoinjs-lib/pull/257/files, #308 (comment)). And so we can avoid advice such as #228 (comment) misleading people to thinking that will allow them to use the library fully without further modifications. |
ping @kyledrake |
The reason for having both the git path and npm path is as I said on IRC: "I thought some devs might be more comfortable with git for updating/upgrading. Say they change the index.js to add/remove things, they can stash then git pull to update. With npm their changes will be discarded."
Again, it's an issue caused by the lack of proper dependency manager when one uses the bundled code by itself without browserifying the rest of their code. IMHO modifying |
In the context of its only use for them being the interaction with this library. Maybe it is relevant? I don't disagree with your other points though. I'm just trying to reduce the complaining. |
We do resolve our internal dependency on |
I'm +1 with the idea of showing developers how to compile their own, and provide their own dependencies as needed. If we show them an example of this in the README so they can quickly get started compiling a version that has the interfaces they need, that seems fine. Perhaps in the future, things may cool down a bit and then we could provide access to the internals if we expect them to be stable for a long time. But really, I think people should be learn how to use Browserify and know how to use it properly, and know how to compile the deps they need themselves.
+1 to letting them complain. If it keeps happening, let's just add something to the README about it how we're not changing it. Debate is great, but the color of the bike shed is not really the kind of debate that moves the library forward. We're using Node.js and Browserify for developing this, it runs on everything, it's easy to test, we think it's great for producing high quality JS software, we're not changing it, you'll eventually need to know how to use it anyways, so learn how to use it. |
I just ran up against the "no Buffer in browser" issue and wanted to add my 2 cents. After reading through the discussion related to using bitcoinjs-lib in a browser, I think the overarching issue is that the docs suggest that running "npm run-script compile" will leave you with a fully functionaly library which isn't the case. I think re-writing the "Browser" section on the README to reflect the points discussed in the issues related to browser use along with a note mentioning that core NodeJS modules wont be exported by default with the "full export" code from #308 (comment) included would help immensely. |
Which is one of the main reasons I feel that providing |
@dcousens @kyledrake If you guys are happy with the changes in this PR go ahead merge it. My problems remain as
I feel strongly about keeping
|
@weilu I've updated the instructions. I believe I've kept true to your intentions,
see df50393
see 1d9bc2c I think the above makes it abundantly clear we are just helping the user understand how to use browserify, and not just providing a convenient hack. |
``` javascript | ||
var foobar = { | ||
base58: require('bs58'), | ||
bitcoin: require('bitcoinjs-lib'), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it will complain that bitcoinjs-lib
is not found as it has not yet been installed through npm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same with bs58
, and any others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So? the instruction is still incomplete
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, it has been installed.
This is under the ## Setup
header, with ## Installation
above it.
Therefore, at this stage, it is assumed they have bitcoinjs-lib
installed.
ce9c614
to
c11f505
Compare
Alternatively, they could also just do the standard `require('./')` if they really wanted to do this.
|
||
From NPM: | ||
$ browserify foobar.js -s foobar > dist/foobar.js |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mkdir node_sandbox
cd node_sandbox/
npm init
npm install bitcoinjs-lib
browserify foobar.js -s foobar > dist/foobar.js
-bash: dist/foobar.js: No such file or directory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
browserify foobar.js -s foobar > bundle.js
Error: Cannot find module 'bs58' from '/Users/luwei/workspace/node_sandbox'
at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:50:17
at process (/usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:119:43)
at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:128:21
at load (/usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:60:43)
at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:66:22
at /usr/local/lib/node_modules/browserify/node_modules/resolve/lib/async.js:21:47
at Object.oncomplete (fs.js:107:15)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dcousens Did I fail at reading the readme?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is a good point. I guess it becomes obvious in your examples, but this problem is independent of this PR as it also affects the node set up advice. How do we control users using |
I'm going to merge this, but the point brought up by @weilu is quite valid. How do we control users using bigi@latest in conjunction with our API instead of what we use internally?
The best we can do is either simplify our API such that common JS types are used for data interchange or we ask the users to verify their dependencies against what we use internally. |
README: improve browser setup advice
As per #314, this updates the README to include more up-to-date and idiomatic build advice for users who want to use the library from the browser.
Suggestions welcome and appreciated.