我从这里阅读了 requirejs 文档 API
requirejs.config({
shim: {
'backbone': {
//These script dependencies should be loaded before loading
//backbone.js
deps: ['underscore', 'jquery'],
//Once loaded, use the global 'Backbone' as the
//module value.
exports: 'Backbone'
},
'underscore': {
exports: '_'
},
'foo': {
deps: ['bar'],
exports: 'Foo',
init: function (bar) {
//Using a function allows you to call noConflict for
//libraries that support it, and do other cleanup.
//However, plugins for those libraries may still want
//a global. "this" for the function will be the global
//object. The dependencies will be passed in as
//function arguments. If this function returns a value,
//then that value is used as the module export value
//instead of the object found via the 'exports' string.
return this.Foo.noConflict();
}
}
}
});
但我没有理解shim的部分。 为什么我需要使用shim?如何配置?能否提供更多解释?
请问有人可以举例解释为什么和何时应该使用shim吗? 谢谢。
Underscore
和Backbone
像正常情况下一样使用,那么在这种情况下shim
是什么作用?我可以使用require( function() { _.extend({}); })
吗?它能理解_
吗? - Stiger