哪种捆绑系统应该被使用:AMD、CommonJS、ES模块、IIFE、UMD和SystemJS

9

RollupJS模块打包工具提供了一系列可能的输出格式:

  • AMD
  • CommonJS
  • ES模块
  • IIFE
  • UMD
  • SystemJS

在特定情况下是否有一个经验法则可以选择哪种格式?

amd – Asynchronous Module Definition, used with module loaders like RequireJS
cjs – CommonJS, suitable for Node and Browserify/Webpack
es – Keep the bundle as an ES module file
iife – A self-executing function, suitable for inclusion as a <script> tag. (If you want to create a bundle for your application, you probably want to use this, because it leads to smaller file sizes.)
umd – Universal Module Definition, works as amd, cjs and iife all in one
system – Native format of the SystemJS 

2
"IIFE" <- 其中一件事与其他不同 - Phil
1个回答

6
建立模块和处理依赖关系在过去是很麻烦的。新的解决方案,以库或ES2015模块的形式,已经消除了大部分痛苦。如果您正在考虑启动一个新的模块或项目,ES2015是正确的选择。它将始终得到支持,并且使用转换器和填充物来支持当前非常好。另一方面,如果您更喜欢使用纯ES5代码,则通常的选择是将客户端使用AMD,服务器端使用CommonJS/Node。
我推荐阅读本文,其中您将找到每个模块系统的所有详细信息、优点和缺点。

https://auth0.com/blog/javascript-module-systems-showdown/


5
这可能更适合作为评论。仅提供链接的回答价值很低。 - Phil
2
这是一篇关于编程的文章,但其中缺少了“umd”的内容。谢谢 :) - XY Li

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接