How can we use es6 modules in modern web browsers without transpiling the code

风格不统一 提交于 2019-12-02 12:01:52

问题


Is it possible to use es6 module system and import modules in web browsers?


回答1:


With chrome 61, es6 module system is introduced to the world of web browsers. This link https://developers.google.com/web/fundamentals/primers/modules can be referred for more details on how chrome implements the module system.

Some of the important features of es6 module system discussed in the above link are:

  1. Modules by default are strict mode.
  2. They are not lexical top-level scope, which is var foo = 42 in module file won't be available as window.foo.
  3. Modules are included in html file as <script type="module" src="example.mjs">
  4. Modules are deferred by default

There are some other browsers too which have come up with solutions in their different versions. This below-given link explains the compatibility level of module system in different browsers. https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Browser_compatibility



来源:https://stackoverflow.com/questions/50920122/how-can-we-use-es6-modules-in-modern-web-browsers-without-transpiling-the-code

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