I'm experimenting with native ES6 modules support in Chrome. jQuery is not es6 module (no export) - I know. Still, trying to understand what does it mean for us.
This works without errors:
<script type="module">
import * as jQuery from "./js/jquery.js";
window.console.log(jQuery);
</script>
But of course jQuery
thereis not a function but a Module
symbol.
The question is: is it possible to extract jQuery/$ function from jQuery module? When there are no exports defined on module?
So do we have a method to extract not exported function from Module in Chrome (as we have it e.g. in browserfy)?
P.S. I have made an stupid error ("as jQuery" <-> "as jQyery") but it changes nothing, it is only alias name.
This:
creates jQuery on window as "side effect". JQuery code
There is some specific in this and the same behaviour can't be expected from all "legacy" scripts.
What is interesting next also works (my explaination: because of "fetching first rule")
Syntax
import "module-name"
described there https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/importGoogle article: https://developers.google.com/web/fundamentals/primers/modules
Also this loads jquery ONLY ONCE (and execute it ONLY ONCE):
This is important feature that can be used in development.
P.S.
This works also but has its trap: