Last active
January 29, 2016 04:59
-
-
Save voltrevo/b3227351cea032efb6ac to your computer and use it in GitHub Desktop.
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
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