Last active
October 26, 2018 02:26
-
-
Save raejin/03893ba5258485cb578a72b9ae357952 to your computer and use it in GitHub Desktop.
metro
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
'use strict'; | |
const host = 'http://localhost:8082' | |
const dynamicImport = require; | |
module.exports = function (moduleID, importPath) { | |
const head = document.getElementsByTagName('head')[0]; | |
const promise = new Promise((resolve, reject) => { | |
const script = document.createElement('script'); | |
let onScriptComplete; | |
script.charset = 'utf-8'; | |
script.timeout = 120; | |
script.src = `${host}/${importPath}.bundle.js`; | |
onScriptComplete = function (event) { | |
console.log('script complete'); | |
// avoid mem leaks in IE. | |
script.onerror = script.onload = null; | |
resolve(dynamicImport(moduleID)); | |
}; | |
script.onerror = script.onload = onScriptComplete; | |
head.appendChild(script); | |
}); | |
return promise; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment