Loading jQuery, Underscore and Backbone using RequireJS 2.0.1 and shim

后端 未结 3 1437
小蘑菇
小蘑菇 2021-01-30 00:55

I am experimenting a little bit with RequireJS 2.0.1. My goal is to load correctly jQuery, Underscore and Backbone. From the original RequireJS doc I d

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-30 01:42

    What you are doing is correct, but jQuery does not need to be in the shim config because it exports an AMD (Asynchronous Module Definition) module. Underscore removed its support for AMD / Require.js quickly after adding it, see: Why underscore.js removed support for AMD

    Shim is intended as a convenience for using libraries that do not export an AMD module. If the library you are using does support AMD, or has 2 versions (one that supports AMD, and one that is a global variable) you should use the AMD version. You should use the AMD version for the same reasons you would use AMD in the first place and also because the library may include require.js (or Almond ) in its source and would be adding unnecessary file size to your project.

提交回复
热议问题