How to add a js script as type=“module”
-
01-03-2021 - |
题
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?
解决方案
Yes, it is possible, with the attributes property.
my-library:
version: 1.x
js:
js/App.js: { attributes: { type: module } }
不隶属于 drupal.stackexchange