ember.js - Import SockJS as AMD in Ember CLI -



ember.js - Import SockJS as AMD in Ember CLI -

i desperately trying include sockjs via bower in ember cli. have followed docs close could. these steps, seemed work:

added "sockjs-client": "0.3.4" bower.json ran bower install

added next brocfile.js

app.import('vendor/sockjs-client/lib/index.js', { 'sockjs': [ 'sockjs' ] });

added import { sockjs sockjs } 'sockjs'; module. had tried import sockjs 'sockjs'; , various other combinations well...

this @ to the lowest degree seems compile , ember server runs without errors. however, open page in browser, receive next error:

uncaught referenceerror: sockjs not defined

the created source, shows error, looks this:

sockjs = (function(){ var _document = document; var _window = window; var utils = {}; <!-- include lib/reventtarget.js --> <!-- include lib/simpleevent.js --> <!-- include lib/eventemitter.js --> <!-- include lib/utils.js --> <!-- include lib/dom.js --> <!-- include lib/dom2.js --> <!-- include lib/sockjs.js --> <!-- include lib/trans-websocket.js --> <!-- include lib/trans-sender.js --> <!-- include lib/trans-jsonp-receiver.js --> <!-- include lib/trans-jsonp-polling.js --> <!-- include lib/trans-xhr.js --> <!-- include lib/trans-iframe.js --> <!-- include lib/trans-iframe-within.js --> <!-- include lib/info.js --> <!-- include lib/trans-iframe-eventsource.js --> <!-- include lib/trans-iframe-xhr-polling.js --> <!-- include lib/trans-iframe-htmlfile.js --> <!-- include lib/trans-polling.js --> <!-- include lib/trans-receiver-eventsource.js --> <!-- include lib/trans-receiver-htmlfile.js --> <!-- include lib/trans-receiver-xhr.js --> <!-- include lib/test-hooks.js --> homecoming sockjs; })();

what right way include sockjs ember cli?

edit

after more trial , error got next working browsers perspective:

brocoli.js:

app.import('vendor/bower-sockjs-client/sockjs.js', { 'sockjs-client': ['sockjs-client'] }); module.exports = app.totree();

bower.json:

"dependencies": { "handlebars": "~1.3.0", "jquery": "^1.11.1", "qunit": "~1.12.0", "ember-qunit": "~0.1.5", "ember": "1.5.1", "ember-resolver": "~0.1.1", "loader": "stefanpenner/loader.js#1.0.0", "ember-cli-shims": "stefanpenner/ember-cli-shims#0.0.2", "ember-load-initializers": "stefanpenner/ember-load-initializers#0.0.2", "ember-qunit-notifications": "^0.0.1", "ember-cli-test-loader": "rjackson/ember-cli-test-loader#0.0.2", "bower-sockjs-client": "0.3.4" }

and no import whatsoever within module.

this makes ember cli complain lot: 'sockjs' not defined. @ to the lowest degree works now. there wrong doing or bug within ember cli?

i know got solved. here explanation of whats going wrong. having issues, thought i'll see whats going on under hood.

the library downloaded via bower "sockjs-client" not contain distribution file. need to build self. need make command. if linux or mac, have it. if on windows, need download cygwin or mingw

to build sockjs, go vendor/sockjs-client/ in terminal , execute command

npm install create build

this generate 2 files sockjs.min.js , sockjs.js.

now can include file in brocfile.js

app.import('vendor/sockjs-client/sockjs.min.js');

now sockjs should available global variable. bundle using 'bower-sockjs-client' fork shares dist files. if using that, create sure date.

since sockjs global, need add together jshintrc file.

{ "predef": { "document": true, "window": true, "demo1env": true, "sockjs": true } }

why import not working -

the reason not able import bundle because sockjs uses kind of umd syntax amd. next check see if can utilize amd syntax.

typeof define == "function" && define.amd

ember-cli uses minimal loader.js load amd modules , define.amd not set, evaluate false in above code. if modify loader.js file, amd definition of sockjs isn't compatible es6 transpiler. es6 transpiler expectes module exported 'default' key.

import sockjs 'sockjs'; become var sockjs = _dependency_1['default']; sockjs _dependency_1, _dependency_1['default'] undefined.

ember.js amd sockjs ember-cli

Comments

Popular posts from this blog

model view controller - MVC Rails Planning -

ruby on rails - Devise Logout Error in RoR -

html - Submenu setup with jquery and effect 'fold' -