Skip to content
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

Browserify UMD #56

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Browserify UMD #56

wants to merge 4 commits into from

Conversation

xcthulhu
Copy link
Contributor

@xcthulhu xcthulhu commented Nov 7, 2015

This changes the output of the gulp browser:uncompressed to generate a Universal Module Definition (UMD) as described here.

I have verified that the generated UMD file can be loaded in phantomjs with the following command:

var bitauth = require('./bitauth');

Along with ClojureScript's UMD support (discussed here), this obviates my need for Google Closure support and thus closes #55 and cljsjs/packages#255.

@braydonf
Copy link
Contributor

Now getting an error with this:

<script src="bitauth.js"></script>
<script>
var bitauth = require('bitauth');
</script>
ReferenceError: require is not defined

However this will work:

<script src="bitauth.js"></script>
<script>
console.log(window.bitauth);
</script>

The use of require makes it much more Node.js and Browserify compatible, as there isn't a need to use:

if (!process.browser) {
  var bitauth = require('bitauth');
};

Could this be another build, e.g. bitauth.standalone.js ?

@xcthulhu
Copy link
Contributor Author

Good call, I'll go make a second build

@xcthulhu
Copy link
Contributor Author

Okay, I've added a second build.

To clarify, the second "standalone" build creates a UMD that can be required with systems that already have a require module system like phantomjs and node.js. For example:

phantomjs> var bitauth = require('./bitauth.standalone.js');
undefined
phantomjs> bitauth
{
   "PREFIX": {
      "type": "Buffer",
      "data": [
         15,
         2
      ]
   },
   "_generateRandomPair": "[Function]",
   "_getPublicKeyFromPrivateKey": "[Function]",
   "_sign": "[Function]",
   "_verifySignature": "[Function]",
   "generateSin": "[Function]",
   "getPublicKeyFromPrivateKey": "[Function]",
   "getSinFromPublicKey": "[Function]",
   "sign": "[Function]",
   "validateSin": "[Function]",
   "verifySignature": "[Function]"
}

But browserify has it's own module loading system that it creates and injects when you don't specify --standalone on the command line, which may be preferred.

The default browserify bundle doesn't work at all with Google Closure; this is kind of an obscure defect and maybe should be documented somewhere...

I hope things are clear to any onlookers what is going on here. My downstream ClojureScript code needs Closure support so it means a lot to me that you guys are willing to support two different browser bundles :D

@braydonf
Copy link
Contributor

Looks like the browserify build bitauth.js is committed in, can you rebase without the bitauth.js bundled file?

@xcthulhu
Copy link
Contributor Author

@braydonf Hey, it's been a long time and I completely forgot about this.

I originally included the bitauth.js file because CLJSJS are leery of building artifacts they package.

Are you still interested in this? If so I suppose I can get rid of the bitauth.js file and skip CLJSJS and just package my own ClojureScript distribution of this library.

@braydonf
Copy link
Contributor

bitauth.js build is included in tagged releases 90ac1f5 without being included in the master branch.

Simplifying externs (still doesn't work with advanced compilation)
Isn't functional with the Google Closure Compiler
@xcthulhu
Copy link
Contributor Author

Okay, I got rid of bitauth.js.

I tried to revise my google extern file for this but for whatever reason I cannot get the closure compiler to work with your library, so I deleted it.

If you want I can squash these commits.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Version 0.3.1 Breaks Google Closure Compiler Support
2 participants