【发布时间】:2012-11-05 17:21:04
【问题描述】:
我似乎无法让 zepto 与 requirejs 一起工作。
这是我的文件
main.js
require.config({
paths: {
zepto: 'libs/zepto/zepto.min',
underscore: 'libs/underscore/underscore-min',
backbone: 'libs/backbone/backbone-min',
cordova: 'libs/cordova/cordova-2.1.0',
history: 'libs/history/history',
historyZ: 'libs/history/history.adapter.zepto'
},
shim: {
zepto: {
exports: '$'
},
backbone: {
deps: ['underscore', 'zepto']
}}
});
require([
// Load our app module and pass it to our definition function
'app',
], function(App){
// The "app" dependency is passed in as "App"
App.initialize();
});
app.js
define([
'zepto',
'underscore',
'backbone',
'router' // Request router.js
], function($, _, Backbone, Router){
var initialize = function(){
// Pass in our Router module and call it's initialize function
Router.initialize();
}
return {
initialize: initialize
};
});
路由器.js
define([
'zepto',
'underscore',
'backbone',
'views/dashboard'
], function($, _, Backbone, DashboardView){
var AppRouter = Backbone.Router.extend({
routes: {
// Define some URL routes
'' : 'showDashboard',
}
});
var initialize = function(){
var app_router = new AppRouter;
app_router.on('showDashboard', function(){
// We have no matching route, lets just log what the URL was
//console.log('No route:', actions);
var dashboardView = new DashboardView();
dashboardView.render();
});
Backbone.history.start();
};
return {
initialize: initialize
};
});
你得到了图片..但是当我运行这一切时,我在 Chromes 控制台中得到了这个:
GET http://localhost/SBApp/www/js/jquery.js 404 (Not Found) require.js:1824
和一个脚本错误(我在括号中加上了这不会让我发布。)
在带有 firebug 的 Firefox 中,它会吐出一个脚本错误
有没有人成功地用 require 配置了 zepto 并且可以给我一些帮助?
【问题讨论】:
-
你有没有 grep 你的库和源代码中提到“jquery”?任何库都会独立尝试包含它,这似乎非常奇怪。
-
我做到了,唯一引用 jQuery 的东西就是 require。我想当我尝试将 AMD 与它一起使用时,它会寻找它,我一直在环顾四周,发现尚不支持 Zepto 和 AMD?
标签: javascript backbone.js requirejs zepto frontend