Currently to import a script you need it to have a URL, such as an HTTP url, data
or blob
.
But there is no way to import modules that are local to the document inside a script tag.
what if you could use a hash URI to import those?
Like this:
<script type="module" id="someLocalScript">
export function fun() { return "Hello" }
</script>
<script type="module">
import {fun} from "#someLocalScript"
console.log(fun())
</script>
I’ve encountered this trying to build some browser-based dev-tools, and had to resort to using blobs and eval
to achieve something similar.