문제

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 } }

See Adding attributes to script elements and JS properties.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 drupal.stackexchange
scroll top