admin管理员组

文章数量:1313177

RollupJS module bundler provides a list of possible outputs

  • AMD
  • CommonJS
  • ES Module
  • IIFE
  • UMD
  • SystemJS

Is there a rule of thumb which format should be chosen under a certain circumstance?

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 

RollupJS module bundler provides a list of possible outputs

  • AMD
  • CommonJS
  • ES Module
  • IIFE
  • UMD
  • SystemJS

Is there a rule of thumb which format should be chosen under a certain circumstance?

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 
Share Improve this question edited Jul 26, 2018 at 5:01 XYZ asked Jul 26, 2018 at 4:50 XYZXYZ 27.4k15 gold badges93 silver badges167 bronze badges 1
  • 3 "IIFE" <- one of these things is not like the others – Phil Commented Jul 26, 2018 at 4:58
Add a ment  | 

1 Answer 1

Reset to default 7

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.

I remend the lecture of this article, where you will find all the details, pros and cons for each module system :

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

本文标签: