How can I make JavaScript modules work in IE 11

梦想与她 提交于 2021-01-27 23:39:49

问题


I have JavaScript modules which I want to use with IE11.

In the HTML pages they are referenced like this:

<script type="module">
     import * as mystuff from './scripts/mystuff.js'; window.mystuff = mystuff
</script>

They do not work in Internet Explorer 11, but I cannot change the modules to normal scripts (because they are generated by Transcrypt). How can I make them work with IE? Does a polyfill or something similar for the <script type="module"> construct exist?


回答1:


You cannot do this. IE does not understand the type="module" attribute.

Instead use rollup.js and Babel to bundle your module into an old style script mystuff_incl_ie.js and load this with the normal script tag:

<script src='./scripts/mystuff_incl_ie.js'></script>

See also Bundle JS with rollup and Babel for use in IE11.



来源:https://stackoverflow.com/questions/63333459/how-can-i-make-javascript-modules-work-in-ie-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!