How to add a js script as type=“module”
-
01-03-2021 - |
Question
How to add type="module" to script added in MODULENAME.libraries.yml when i do:
my-library:
version: 1.x
js:
js/App.js: { }
I get
<script src="/modules/custom/MODULENAME/js/App.js?v=1.x"></script>
I need to add type="module" to script tag like:
<script type="module" src="/modules/custom/MODULENAME/js/App.js?v=1.x"></script>
I have tried:
my-library:
version: 1.x
js:
js/App.js: { type: module }
But i doesn’t work.
Is this possible to add a script of type module?
La solution
Yes, it is possible, with the attributes property.
my-library:
version: 1.x
js:
js/App.js: { attributes: { type: module } }
Licencié sous: CC-BY-SA avec attribution
Non affilié à drupal.stackexchange