代码之家  ›  专栏  ›  技术社区  ›  XYZ

应该使用哪些捆绑系统amd、commonjs、es模块、iife、umd和systemjs

  •  -2
  • XYZ  · 技术社区  · 8 年前

    RollupJS模块bundler提供可能的输出列表

    • AMD
    • 公用电话
    • ES模块
    • 伊夫斯
    • UMD
    • 系统JS

    是否有经验法则,在特定情况下应选择哪种格式?

    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 
    
    1 回复  |  直到 8 年前
        1
  •  0
  •   colxi    8 年前

    在过去,构建模块和处理依赖项非常麻烦。新的解决方案,以库或ES2015模块的形式,已经消除了大部分的痛苦。 如果你想开始一个新的模块或项目,ES2015是正确的方法。 . 它将始终得到支撑,目前使用蒸腾器和聚乙烯填料的支撑非常好。另一方面, 如果您更喜欢使用纯ES5代码,那么通常在AMD客户机和CommonJS/Node服务器之间进行拆分仍然是常见的选择。 .

    我推荐这篇文章的讲座,在那里你可以找到所有的细节, 赞成的意见 和 欺骗 对于每个模块系统:

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