Read my Blog article about this.
How to use ES6 modules in an HTML Page:
about:config
, switch dom.moduleScripts.enabled
to true;
Firefox also runs fine with file:/
protocol (loading page from local disk)
file:/
protocol
("blocked by CORS",
"strict MIME type checking"),
so you need to deploy your page-resources to some HTTP server)type="module"
in all
script
elements that want to import
modulespage
object in a non-module-typed script
element, then, script
element,
import modules and set all used module-functions into the global page-object (using the same function name)page.functionName()
<script type="module">
element that connects page-callbacks
with module functions (that way element-ids are duplicated just locally within the HTML file)
The two buttons below call the function foobar()
in two different ways, like described above.
This function is implemented in es6-modules.js.
This module imports all other modules.
For seeing the source of this HTML page es6-modules.html
,
click right mouse button and select menu item "View Page Source".
ɔ⃝ Fritz Ritzberger, 2017-12-29