正式兼容CommonJS和AMD

正式兼容CommonJS和AMD

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

问题描述

限时删除!!

从这篇文章:

写的是

更精确地

如果真的是这样,我们需要的是一个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:似乎不允许从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.

然而从:

模块加载程序规范将允许定义您的自定义模块加载程序。因此,可以通过编写自己的加载程序来导入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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 12:17