4

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?

5

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.