Created
January 19, 2021 09:27
-
-
Save asci/c3eae4c97681395bb14d99831150594f to your computer and use it in GitHub Desktop.
ES module from Data URL
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
// 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