es-modules-utils
v2.0.0
Published
Native ECMAScript modules utilities
Downloads
15
Readme
Native ECMAScript modules utilities
Installation
- With npm:
npm install es-modules-utils
- With yarn:
yarn add es-modules-utils
Usage
no-module-fallback
Provides ability to use native ECMAScript modules (aka ES or ES6 modules, with native import
/export
)
or the bundled JavaScript file if they are not supported.
The utility script is expected to be included in HTML, e.g.:
<script
module="./module.js"
no-module="./no-module.js"
add-global-class
add-global-variable
src="es-modules-utils/no-module-fallback.js"
>
</script>
Params:
module="module-URL.js"
: the URL of the script file, which will be loaded if the browser DOES support native ECMAScript modulesno-module="no-module-URL.js"
: the URL of the script file, which will be loaded in case the browser DOES NOT support native ECMAScript modulesadd-global-class
: the binary attribute, which enables adding the<html class="esmodules">
if ES modules are supported,<html class="no-esmodules">
otherwise (can be used e.g. to show some animation till the ES module is loaded)add-global-variable
: the binary attribute, which enables adding the global Boolean variablewindow.esmodules=true/false
(can be used e.g. to decide which method to use to include new scripts)
The solution uses the nomodule
script attribute approach,
which also can be used without the additional features like:
<script type="module" src="module-URL.js"></script>
<script nomodule src="no-module-URL.js"></script>