Skip to content

Instantly share code, notes, and snippets.

@voltrevo
Last active January 29, 2016 04:59
Show Gist options
  • Save voltrevo/b3227351cea032efb6ac to your computer and use it in GitHub Desktop.
Save voltrevo/b3227351cea032efb6ac to your computer and use it in GitHub Desktop.
var magicRequire = function(moduleName) {
return new Promise(function(resolve, reject) {
var scriptTag = document.createElement('script');
scriptTag.src = 'https://www.brcdn.org/' + moduleName + '/latest';
document.body.appendChild(scriptTag);
scriptTag.addEventListener('load', function() {
if (!window.require) {
reject(new Error('require function not found'));
return;
}
console.log('Loaded', moduleName);
window[moduleName] = require(moduleName);
resolve(window[moduleName]);
});
scriptTag.addEventListener('error', reject);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment