Skip to content

Instantly share code, notes, and snippets.

@beginor
Forked from green3g/dojo.js
Last active February 18, 2017 09:23
Show Gist options
  • Save beginor/7dbe633ef26e98fe0ba70bcb1d191b8c to your computer and use it in GitHub Desktop.
Save beginor/7dbe633ef26e98fe0ba70bcb1d191b8c to your computer and use it in GitHub Desktop.
SystemJS Dojo Loader
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, '');
}
@beginor
Copy link
Author

beginor commented Feb 18, 2017

@tomwayson That sounds a good idea, I will build a public repo for this loader.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment