{"action":"created","issue":{"url":"https://api.github.com/repos/cettia/cettia-javascript-client/issues/14","repository_url":"https://api.github.com/repos/cettia/cettia-javascript-client","labels_url":"https://api.github.com/repos/cettia/cettia-javascript-client/issues/14/labels{/name}","comments_url":"https://api.github.com/repos/cettia/cettia-javascript-client/issues/14/comments","events_url":"https://api.github.com/repos/cettia/cettia-javascript-client/issues/14/events","html_url":"https://github.com/cettia/cettia-javascript-client/pull/14","id":187147917,"number":14,"title":"Make Cettia work with bundlers such as Webpack","user":{"login":"DDKnoll","id":495226,"avatar_url":"https://avatars.githubusercontent.com/u/495226?v=3","gravatar_id":"","url":"https://api.github.com/users/DDKnoll","html_url":"https://github.com/DDKnoll","followers_url":"https://api.github.com/users/DDKnoll/followers","following_url":"https://api.github.com/users/DDKnoll/following{/other_user}","gists_url":"https://api.github.com/users/DDKnoll/gists{/gist_id}","starred_url":"https://api.github.com/users/DDKnoll/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DDKnoll/subscriptions","organizations_url":"https://api.github.com/users/DDKnoll/orgs","repos_url":"https://api.github.com/users/DDKnoll/repos","events_url":"https://api.github.com/users/DDKnoll/events{/privacy}","received_events_url":"https://api.github.com/users/DDKnoll/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":7,"created_at":"2016-11-03T18:10:02Z","updated_at":"2016-11-09T15:47:21Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/cettia/cettia-javascript-client/pulls/14","html_url":"https://github.com/cettia/cettia-javascript-client/pull/14","diff_url":"https://github.com/cettia/cettia-javascript-client/pull/14.diff","patch_url":"https://github.com/cettia/cettia-javascript-client/pull/14.patch"},"body":"# Step 1: Copy over old code\r\nFor 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\r\n\r\n# Step 2: Make two seperate versions for browser and node env using Babel.\r\nTo 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!\r\n\r\nIn 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:\r\n\r\n### Initial Code\r\n```\r\nif (process.env.NODE_ENV !== \"browser\") {\r\n  window = require(\"jsdom\").jsdom().defaultView;\r\n  window.WebSocket = require(\"ws\");\r\n  window.EventSource = require(\"eventsource\");\r\n}\r\n```\r\n\r\n### Replace env variables plugin\r\n```\r\nif (false) { /** This code is dead! **/\r\n  window = require(\"jsdom\").jsdom().defaultView;\r\n  window.WebSocket = require(\"ws\");\r\n  window.EventSource = require(\"eventsource\");\r\n}\r\n```\r\n\r\n### Remove the Dead Code!  Final browser.js file does not have those lines.\r\n```\r\n```\r\n\r\n# Step 3: Import the correct version as needed.\r\n\r\n```\r\n// NODE\r\nvar cettia = require(\"cettia-client\").default;\r\n\r\n// WEBPACK/BROWSERIFY\r\nvar cettia = require(\"cettia-client/browser\").default;\r\n```"},"comment":{"url":"https://api.github.com/repos/cettia/cettia-javascript-client/issues/comments/259446597","html_url":"https://github.com/cettia/cettia-javascript-client/pull/14#issuecomment-259446597","issue_url":"https://api.github.com/repos/cettia/cettia-javascript-client/issues/14","id":259446597,"user":{"login":"flowersinthesand","id":1095042,"avatar_url":"https://avatars.githubusercontent.com/u/1095042?v=3","gravatar_id":"","url":"https://api.github.com/users/flowersinthesand","html_url":"https://github.com/flowersinthesand","followers_url":"https://api.github.com/users/flowersinthesand/followers","following_url":"https://api.github.com/users/flowersinthesand/following{/other_user}","gists_url":"https://api.github.com/users/flowersinthesand/gists{/gist_id}","starred_url":"https://api.github.com/users/flowersinthesand/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/flowersinthesand/subscriptions","organizations_url":"https://api.github.com/users/flowersinthesand/orgs","repos_url":"https://api.github.com/users/flowersinthesand/repos","events_url":"https://api.github.com/users/flowersinthesand/events{/privacy}","received_events_url":"https://api.github.com/users/flowersinthesand/received_events","type":"User","site_admin":false},"created_at":"2016-11-09T15:47:21Z","updated_at":"2016-11-09T15:47:21Z","body":"I've just confirmed that the fix works pretty well - http://jsbin.com/reliyunopa/edit?html,js,console\r\n\r\n> Does that take care of all of the use cases?\r\n\r\nActually, it doesn't seem to support [Asynchronous Module Definition](https://github.com/amdjs/amdjs-api/blob/master/AMD.md), but it's fine because I think supporting webpack is worth more than supporting AMD.\r\n\r\nWould you mind if I squash and merge your work?"}}
{"actor":{"display_login":"flowersinthesand"}}