-
-
Save beginor/7dbe633ef26e98fe0ba70bcb1d191b8c to your computer and use it in GitHub Desktop.
SystemJS Dojo Loader
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
exports.fetch = function(load) { | |
var name = load.name; | |
return new Promise(function(resolve) { | |
var dojoName = convertToDojoModule(name); | |
window.require([dojoName], function(mod) { | |
SystemJS.register(dojoName, [], function (exp, idObj) { | |
return { | |
setters: [], | |
execute: function() { | |
exp("default", mod); | |
} | |
}; | |
}); | |
resolve(''); | |
}); | |
}); | |
}; | |
exports.instantiate = function (load) { | |
var name = load.name.split('!')[0]; | |
var dojoName = convertToDojoModule(name); | |
return new Promise(function (resolve) { | |
// Since module is loaded by fetch, just require it again, | |
// dojo require does not load the module again. | |
window.require([dojoName], function (module) { | |
resolve(module); | |
}); | |
}); | |
}; | |
function convertToDojoModule(module) { | |
// we just replace SystemJS.baseURL with ''; | |
return module.replace(SystemJS.baseURL, ''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@tomwayson That sounds a good idea, I will build a public repo for this loader.