gpt4 book ai didi

javascript - 应该使用哪个捆绑系统 AMD、CommonJS、ES Module、IIFE、UMD 和 SystemJS

转载 作者:行者123 更新时间:2023-11-28 14:31:09 24 4
gpt4 key购买 nike

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

  • AMD
  • CommonJS
  • ES 模块
  • IIFE
  • 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

最佳答案

Building modules and handling dependencies was cumbersome in the past. Newer solutions, in the form of libraries or ES2015 modules, have taken most of the pain away. If you are looking at starting a new module or project, ES2015 is the right way to go. It will always be supported and current support using transpilers and polyfills is excellent. On the other hand, if you prefer to stick to plain ES5 code, the usual split between AMD for the client and CommonJS/Node for the server remains the usual choice.

我推荐本文的讲座,您将在其中找到每个模块系统的所有详细信息、优点缺点:

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

关于javascript - 应该使用哪个捆绑系统 AMD、CommonJS、ES Module、IIFE、UMD 和 SystemJS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51531216/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com