Skip to content

Instantly share code, notes, and snippets.

@asci
Created January 19, 2021 09:27
Show Gist options
  • Save asci/c3eae4c97681395bb14d99831150594f to your computer and use it in GitHub Desktop.
Save asci/c3eae4c97681395bb14d99831150594f to your computer and use it in GitHub Desktop.
ES module from Data URL
// Async variant
const m = { myModule: undefined }
;(async () => {
const myModule = await import(
URL.createObjectURL(
new Blob(
[
`export let Value = 123
`,
],
{ type: "text/javascript" }
)
)
)
m["myModule"] = myModule
})()
// OR sync
import { Value } from "data:text/javascript,export let Value = 123;"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment