ES6模块的“导入”正式兼容CommonJS和AMD? [英] ES6 module's "import" officially compatible with CommonJS and AMD?

查看:591
本文介绍了ES6模块的“导入”正式兼容CommonJS和AMD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从这篇文章:
https:// hacks .mozilla.org / 2015/08 / es6-in-depth-modules /

写的是


新标准旨在与现有的CommonJS和AMD模块进行互操作。

The new standard is designed to interoperate with existing CommonJS and AMD modules.

更精确地


所有CommonJS和AMD模块提供给ES6作为默认导出

All CommonJS and AMD modules are presented to ES6 as having a default export

如果真的是这样,我们需要的是一个ES6 polyfill而我们不需要再使用其他任何东西。

If it is really the case all we'd need is a ES6 polyfill and we wouldn't have to do use anything else.

然而,对于这样的ES6 Polyfill: https://github.com/ModuleLoader/es6-module-loader 似乎不允许从ES6加载CommonJS / AMD模块,但只能构建在就像SystemJS允许的那样。

Yet for eg this ES6 Polyfill :https://github.com/ModuleLoader/es6-module-loader doesn't seem to allow loading CommonJS/AMD modules from ES6 but only solutions built on top of it like SystemJS allow it.

所以问题是:这是真的,官方的ES6标准说CommonJS / AMD应该被支持(被呈现为默认的出口)?

So the question is : Is this true that the official ES6 standard says CommonJS/AMD should be supported (by being presented as having a default export) ?

如果是这样,你是否参考了这样说的ESCMA规范?那么为什么它不是polyfill本身的特征,而不是建立在它之上的解决方案?

If it is the case, do you have a reference to the ESCMA specification that says so ? and then why is it not a feature of the polyfill itself rather than solutions built on top of it ?

推荐答案

到目前为止我已经明白了,但是我可能是错的,所以确认/纠正是受欢迎的。

So far here is what I've understood, but I may be wrong so confirmation/rectifications are welcomed.


  • ECMAScript 6 指定与AMD,CommonJS或任何其他模块格式的兼容性。它只允许在规范中定义的ECMAScript 6模块。

  • ECMAScript 6 does not specifies any compatibility with AMD, CommonJS or any other module format. It only allows for ECMAScript 6 Module as defined in the spec.

然而这个来源


模块装载机:不是ES2015的一部分。这在ECMAScript 2015规范中被保留为实现定义。最终标准将在WHATWG的Loader规范中,但目前正在进行中。

Module Loaders : Not part of ES2015. This is left as implementation-defined within the ECMAScript 2015 specification. The eventual standard will be in WHATWG's Loader specification, but that is currently a work in progress.

模块加载程序规范将允许定义您的自定义模块加载程序。因此,可以通过编写自己的加载程序来导入AMD,CommonJS等,将描述如何加载这样一个模块。但是,只要我们的自定义模块加载程序描述如何解释此资源,它也将允许加载例如咖啡脚本或任何其他资源。

Module Loader spec will allow to define your own custom module loader. Thus it will be possible to import AMD, CommonJS, etc... by writing your own loader that will describe how to load such a module. But it will also allow to load for eg coffee script or any other resource as long as our custom module loader describes how to interpret this resource.

这篇关于ES6模块的“导入”正式兼容CommonJS和AMD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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