With ES6 Script Modules, there is currently no good way to access declarative HTML content from a module. For example, if I’m defining a custom element in a script module, how do I set up the element’s shadow tree? Currently I’d be required to build it though means like setting an innerHTML string or constructing it bit-by-bit with document.createElement()/appendChild() etc. Ideally though, I’d like to just write HTML and get access to it from my script module, in a way that the HTML and the script module can be bundled together.
My colleagues on the Microsoft Edge team and I have developed a proposal for HTML Modules, an extension of ES6 Script Modules that allows for access to declarative HTML content from within a script module. With HTML Modules, one can simply import the DOM content from an HTML file using the existing ES6 Module syntax:
import {element} from "./myElement.html";
Please see our explainer doc with the details.
Any feedback is appreciated!
There was previous discussion of this proposal on this GitHub issue thread and at TPAC 2018.