Skip to content

Instantly share code, notes, and snippets.

@javan
Created September 11, 2019 10:13
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save javan/5f5a0eae7ba64dd24c565f798d42bb76 to your computer and use it in GitHub Desktop.
Save javan/5f5a0eae7ba64dd24c565f798d42bb76 to your computer and use it in GitHub Desktop.
const files = {
"m1.js": `import {func} from './m2.js'; console.log(func());`,
"m2.js": `export function func() { return 'abc'; }`
}
const urls = new Map
function getURL(filename) {
let url = urls.get(filename)
if (!url) {
const source = files[filename].replace(/\.\/(.+?\.m?js)/g, (_, p1) => getURL(p1))
const blob = new Blob([ source ], { type: "text/javascript" })
url = URL.createObjectURL(blob)
urls.set(filename, url)
}
return url
}
import(getURL("m1.js"))
// https://twitter.com/rauschma/status/1171525636420063238
// https://gist.github.com/WebReflection/6a9df9477b843956f589210f8ab371c0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment