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?

Était-ce utile?

La solution

Yes, it is possible, with the attributes property.

my-library:
  version: 1.x
  js:
    js/App.js: { attributes: { type: module } }

See Adding attributes to script elements and JS properties.

Licencié sous: CC-BY-SA avec attribution
Non affilié à drupal.stackexchange
scroll top