javascript - RequireJS - config; paths and shims not working -
i have common.js
defines config requirejs:
(function(requirejs) { "use strict"; requirejs.config({ baseurl: "/js", paths: { "jsroutes": "http://localhost:8080/app/jsroutes" }, shim: { "jsroutes": { exports: "jsroutes" } } }); requirejs.onerror = function(err) { console.log(err); }; })(requirejs);
i have main.js
file try use jsroutes
path created:
require(["./common", "jsroutes"], function (common, routes) { // interesting });
but not load resource @ http://localhost:8080/app/jsroutes
instead tries load http://localhost:8080/js/jsroutes.js
when main.js
executed. resouce doesn't exist , 404.
how jsroutes
path work correctly? need shim (i'm not 100% sure)?
i can debug common.js
file, paths should being set, right?
update 1
i believe paths should work have them defined shouldn't they?
excerpt http://requirejs.org/docs/api.html
there may times when want reference script directly , not conform "baseurl + paths" rules finding it. if module id has 1 of following characteristics, id not passed through "baseurl + paths" configuration, , treated regular url relative document:
ends in ".js". starts "/". contains url protocol, "http:" or "https:".
update 2
i may have misread docs, can solve issue defining main.js
so:
require(["./common", "http://localhost:8080/app/jsroutes"], function (common, routes) { // interesting });
i rather hoping not have pass round rather unwieldy url though.
update 3
further investigation of docs revealed following snippet:
requirejs.config({ enforcedefine: true, paths: { jquery: 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min' } }); //later require(['jquery'], function ($) { //do $ here }, function (err) { //the errback, error callback //the error has list of modules failed var failedid = err.requiremodules && err.requiremodules[0]; if (failedid === 'jquery') { //undef function on global requirejs object. //use clear internal knowledge of jquery. modules //that dependent on jquery , in middle of loading //will not loaded yet, wait until valid jquery //does load. requirejs.undef(failedid); //set path jquery local path requirejs.config({ paths: { jquery: 'local/jquery' } }); //try again. note above require callback //with "do $ here" comment //be called if new attempt load jquery succeeds. require(['jquery'], function () {}); } else { //some other error. maybe show message user. } });
it seem here jquery
path working full url
i'm path should relative baseurl. giving domain & port screwing up.
edit: standard require js config... might help?
require.config({ baseurl : "./", paths: { // bower components respond: 'assets/bower_components/respond/dest/respond.min', // libraries & polyfills polyfillgcs: 'assets/js/lib/polyfill-getcomputedstyle', polyfillraf: 'assets/js/lib/polyfill-requestanimationframe', polyfillpro: 'assets/js/lib/polyfill-promise', easing: 'assets/js/lib/easing', signalsui: 'assets/js/lib/signals.ui', signalsjs: 'assets/js/lib/signals', domready: 'assets/js/lib/domready', // todo: still needed? // modules app: 'assets/js/es5/app' }, shim: { app: { deps: ['signalsjs'] }, signalsjs: { deps: ['easing', 'polyfillgcs', 'polyfillraf'] }, signalsui: { deps: ['signalsjs'] } } }); // load app require(['app']);
Comments
Post a Comment