应该使用AMD、CommonJS、ES Module、IIFE、UMD和SystemJS的捆绑系统



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 

构建模块和处理依赖关系在过去很麻烦。以库或ES2015模块的形式出现的较新解决方案消除了大部分痛苦如果您正在考虑启动一个新的模块或项目,ES2015是正确的选择。它将始终得到支持,目前使用透明胶片和聚乙烯填充物的支持非常好。另一方面,如果您更喜欢使用普通的ES5代码,那么通常在客户端的AMD和服务器的CommonJS/Node之间进行拆分仍然是常见的选择

我推荐这篇文章的讲座,在那里你可以找到每个模块系统的所有细节,优点缺点

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

最新更新