-
Notifications
You must be signed in to change notification settings - Fork 2
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
Make Cettia work with bundlers such as Webpack #14
Conversation
|
FYI, you can run the corresponding server |
Yeah, I didn't originally make a build step for script tags. But thats easy to add! I just updated the PR with a webpack build command to bundle another version for browsers. So you can use:
The browser embedded version is also doing a uglify step to export a seperate cettia-browser.min.js file. Does that take care of all of the use cases? |
Hmm, new Expected - http://jsbin.com/nirocovofe/edit?html,js,console <!-- Required only for binary -->
<script src="https://npmcdn.com/msgpack-lite@0.1.17/dist/msgpack.min.js"></script>
<!-- Required only for TextEncoder -->
<script src="https://npmcdn.com/text-encoding@0.5.5/lib/encoding.js"></script>
<!-- cettia.js -->
<script src="http://cettia.io/projects/cettia-javascript-client/1.0.0-Beta1/cettia.min.js"></script> Actual - http://jsbin.com/doceyih/edit?html,js,console <!-- cettia.js -->
<script src="https://rawgit.com/DDKnoll/cettia-javascript-client/d14970f056ac3a52eabb5ccae44dcafa9f506298/cettia-browser.js"></script> |
|
||
// Determines if the given data contains binary | ||
var hasBinary = false; | ||
if (process.env.NODE_ENV !== "browser") { |
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.
This used to be typeof module.exports === 'object'
. Now we can check node env variables directly.
I had to update a few places where it used |
I've just confirmed that the fix works pretty well - http://jsbin.com/reliyunopa/edit?html,js,console
Actually, it doesn't seem to support Asynchronous Module Definition, but it's fine because I think supporting webpack is worth more than supporting AMD. Would you mind if I squash and merge your work? |
Well if you want to do AMD, we could add that as well. Just need to add another webpack build in package.json with the But everything else looks good to me, otherwise. |
Thanks for the great work! Do you need a release? |
Yeah, just getting around to pulling around the new versino. A release would be great! |
@DDKnoll If I run However, the generated files are somewhat different from yours, but it passes automated tests on Node and manual tests on browser. It would be nice if you could take a look. #15 |
Step 1: Copy over old code
For most of the cettia file, I just pulled the code out of that export wrapper and reindented it. I placed it in the src folder to keep it seperate from the
Step 2: Make two seperate versions for browser and node env using Babel.
To separate out the browser and node versions, I used Babel to strip out dead code and export two different versions. Also Babel lets you use all of the new features of javascript! Win win!
In the node environment, you need to polyfill a handful of native window methods. In the browser we need to skip those polyfills. So we add
if(browser)
statement that can be stripped out:Initial Code
Replace env variables plugin
Remove the Dead Code! Final browser.js file does not have those lines.
Step 3: Import the correct version as needed.