Skip to content

Instantly share code, notes, and snippets.

@raejin
Last active October 26, 2018 02:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save raejin/03893ba5258485cb578a72b9ae357952 to your computer and use it in GitHub Desktop.
Save raejin/03893ba5258485cb578a72b9ae357952 to your computer and use it in GitHub Desktop.
metro
'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