我们如何在现代Web浏览器中使用es6模块而不转换代码 [英] How can we use es6 modules in modern web browsers without transpiling the code

查看:90
本文介绍了我们如何在现代Web浏览器中使用es6模块而不转换代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用es6模块系统并在Web浏览器中导入模块?

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

推荐答案

借助chrome 61,es6模块系统被引入了Web浏览器领域.此链接 https://developers.google.com/web/fundamentals/primers/modules <有关chrome如何实现模块系统的更多详细信息,请参见/a>.

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.

上面链接中讨论的es6模块系统的一些重要功能是:

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

  1. 默认情况下,模块为strict模式.
  2. 它们不是词法顶级范围,模块文件中的var foo = 42将无法作为window.foo使用.
  3. 模块以<script type="module" src="example.mjs">
  4. 的形式包含在html文件中
  5. 默认情况下推迟模块
  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

还有其他一些浏览器也提供了不同版本的解决方案.下面给出的链接说明了不同浏览器中模块系统的兼容性级别. https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Statements/import#Browser_compatibility

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

这篇关于我们如何在现代Web浏览器中使用es6模块而不转换代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆