Skip to content

Instantly share code, notes, and snippets.

@green3g
Last active February 19, 2017 12:08
Show Gist options
  • Save green3g/4dce79f9bffe74b99a6a6cea3f44604f to your computer and use it in GitHub Desktop.
Save green3g/4dce79f9bffe74b99a6a6cea3f44604f to your computer and use it in GitHub Desktop.
SystemJS Dojo Loader
exports = {
fetch: function(load, fetch) {
console.log('load', load);
let module = load.name.split('!')[0];
return new Promise(function(resolve) {
//use dojo's require and then register the module
window.require([module], function(mod) {
System.register(module, [], function(exp, idObj) {
var result = {
setters: [],
execute: function() {
//Make the name 'default' here as there is only one export per module so it is technically the default.
//Import using a default import statement - eg: import Map from 'esri/Map'
//It's possible this may only compile using 'system' module type in some IDEs using the official typings file though.
exp("default", mod);
}
};
return result;
});
});
});
}
};
@beginor
Copy link

beginor commented Feb 16, 2017

Can you provide sample code to use this loader? thanks!

@green3g
Copy link
Author

green3g commented Feb 16, 2017

It would be something like this:

System.import('esri/map!dojo').then(function(map) {
    
  });

but it doesn't currently work.

https://github.com/systemjs/systemjs/blob/master/docs/creating-plugins.md#sample-coffeescript-plugin

@beginor
Copy link

beginor commented Feb 17, 2017

Finally, I have made a systemjs.loader.dojo.js plugin works with Angular v2.4.7 and ArcGIS API for Javascript v4.2, can load ArcGIS API on demand, do not need to load all required modules before the app boot, and there is a demo: ng2-esri-demo

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