-
-
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, ''); | |
} |
There a working example: https://github.com/beginor/ng2-esri-demo
this is great! I would recommend that you make this it's own repository to make it easy for others to contribute and to publish it to npm so it can be installed via npm, jspm, etc. The SystemJS plugin docs don't really give much guidance on publishing a plugin, but the CSS plugin repository looks like it could be used as an example.
@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
To use this loader:
First is a
dojoConfig.js
:and include
dojo/dojo.js
into your html file:Then, add a meta config to
systemjs.config.js
: