RequireJs: How to define extra dependencies for 3rd party library

谁说胖子不能爱 提交于 2019-12-13 05:25:01

问题


Basically I want to be able to load some module first before other. For example, I want bootstrap to load first before backbone. Can I declare dependencies like so?

shim: {
    'backbone': {deps: ['bootstrap']}
}

回答1:


Yes, that is the way to do it (in the require.config({ ... block of course.) It is also recommended to add an exports key and set it to Backbone. This will allow you to use Backbone inside a require or define block, as though it were a real AMD module:

define(['backbone'], function (Backbone) {
  // Backbone here is the function parameter instead of the global reference
});

Read more here. In fact they even reference Backbone as their example!



来源:https://stackoverflow.com/questions/20696465/requirejs-how-to-define-extra-dependencies-for-3rd-party-library

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!