[英]RequireJS + Backbone without jQuery?
I'm trying to use RequireJS, here is my config file : 我正在尝试使用RequireJS,这是我的配置文件:
require.config({
baseUrl: "/scripts",
paths: {
zepto: "zepto.min",
underscore: "underscore.min",
backbone: "backbone.min"
},
shim: {
zepto: {
exports: "$"
},
underscore: {
exports: "_"
},
backbone: {
deps: ["underscore", "zepto"],
exports: "Backbone"
}
}
});
And this is my app.js : 这是我的app.js:
require(['backbone'], function(Backbone) {
console.log('loaded!');
});
This works fine, but I don't know why RequireJS is trying to load jQuery. 这工作正常,但我不知道为什么RequireJS试图加载jQuery。
Because Backbone requires module called jquery (look at top of backbone.js
) file. 由于骨干网需要的模块调用的jQuery(看看上面
backbone.js
)文件。
// Set up Backbone appropriately for the environment. Start with AMD.
if (typeof define === 'function' && define.amd) {
define(['underscore', 'jquery', 'exports'], function(_, $, exports) {
// Export global even in AMD case in case this script is loaded with
// others that may still expect a global Backbone.
root.Backbone = factory(root, exports, _, $);
});
and You haven't defined this module. 并且您尚未定义此模块。
To hack this use zepto
as jquery
: 要破解这个,请使用
zepto
作为jquery
:
require.config({
baseUrl: "/scripts",
paths: {
jquery: "zepto.min",
underscore: "underscore.min",
backbone: "backbone.min"
},
shim: {
jquery: {
exports: "$"
},
underscore: {
exports: "_"
}
}
});
And second: shim
only works with non-amd modules. 其次:
shim
仅适用于非AMD模块。 Backbone is AMD module. 骨干是AMD模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.