-
Notifications
You must be signed in to change notification settings - Fork 0
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
Convert to CJS, compile to UMD with Browserify #1
base: add-nodejs-support
Are you sure you want to change the base?
Convert to CJS, compile to UMD with Browserify #1
Conversation
This commit standardises the code between browser and Node. Branching logic to handle the different environments is no longer necessary. Thanks to Browserify we can use Node's http module in the browser instead of using XHR directly, so 'http.js' has simply become 'makeRequest.js' and now exports what was previously the 'makeRequestForNode' function
What are your thoughts on this commit? Obviously it's a somewhat large change, but it should significantly simplify the process of maintaining support for both Node and the browser. |
Thanks @markdalgleish, I'll have a look at this tonight. |
I like what you've done here and agree it will be easier to maintain if we can abstract away the differences between the the environments we want to support. Managing dependencies using the node style require is also a welcome addition. My biggest concern with this change is how much additional code wound up in the end result - it went from ~300 lines to ~7000 lines. I know that this is a testing tool and that the file size doesn't matter very much but I'd like to discuss if we can do something about this before accepting this change. What are your thoughts on this? I haven't used browserify before so I'll spend some time reading up about it so I can be less ignorant. |
I noticed the extra code also—this is because all the code for the In the meantime I'll look into optimising the build so that the client code remains lightweight. |
I also agree with Ben. Mark, I believe using http module is an over kill which come with extra dependencies that the client code base does not need. A simple abstraction layer might be just good enough. |
I agree that the If this project was designed for end users I would 100% agree that this would be unacceptable, but for a testing tool I think it's okay. |
https://github.com/cujojs/rest Quoting from the change log: |
I've updated the code to use an XMLHttpRequest shim for Node (xhr2) so that the resulting browser bundle is nice and lean. It now comes in at 276 lines. |
c5c1687
to
45ecc1c
Compare
The 'browser' property is used in package.json so that Browserify doesn't include xhr2 in the browser bundle.
I've also sent a PR to xhr2 (pwnall/node-xhr2#14) so that the browser version is provided automatically, which would allow |
c51fb58
to
a28dd87
Compare
a28dd87
to
e71bc02
Compare
This commit standardises the code between browser and Node. Branching logic to handle the different
environments is no longer necessary.
Thanks to Browserify we can use Node's http module in the browser instead of using XHR directly, so 'http.js' has simply become 'makeRequest.js' and now exports what was previously the 'makeRequestForNode' function.