需要带节点和jQuery的JS
我正在使用r.js尝试通过在我的主应用程序文件上运行r.js来编译我的require js应用程序:需要带节点和jQuery的JS,jquery,node.js,requirejs,r.js,Jquery,Node.js,Requirejs,R.js,我正在使用r.js尝试通过在我的主应用程序文件上运行r.js来编译我的require js应用程序: $ r.js js/bootstrap.js 但是,我在jQuery中遇到了错误: 错误:将www/js/lib/jquery\u plugins/slider.js评估为模块“slider”失败,错误为:ReferenceError:jquery未定义 我知道这是因为在我的slider插件中引用了jQuery,但我认为这可以通过在bootstrap.js文件中添加jQuery作为垫片来解决,
$ r.js js/bootstrap.js
但是,我在jQuery中遇到了错误:
错误:将www/js/lib/jquery\u plugins/slider.js评估为模块“slider”失败,错误为:ReferenceError:jquery未定义
我知道这是因为在我的slider插件中引用了jQuery,但我认为这可以通过在bootstrap.js文件中添加jQuery作为垫片来解决,该文件如下所示:
// Require JS bootstrap file
require.config({
paths: {
jquery: 'lib/jquery',
backbone: 'lib/backbone',
backboneLocalStorage: 'lib/backbone.localStorage',
underscore: 'lib/underscore',
util: 'lib/util',
config: 'config',
lang: 'lang',
hammer: 'lib/hammer',
moment: 'lib/jquery_plugins/moment',
slider: 'lib/jquery_plugins/slider'
},
shim: {
jquery: {
exports: '$'
},
underscore: {
exports: '_'
},
backbone: {
deps: ['underscore'],
exports: 'Backbone'
},
hammer: {
deps: ['jquery'],
exports: 'Hammer'
}
}
});
// load the app
require(['app'], function(App) {
if(navigator.userAgent.indexOf("Chrome")) {
// then I am running on my local host on chrome
// so force device ready
onDeviceReady();
}
document.addEventListener('deviceready', onDeviceReady, false);
function onDeviceReady() {
App.initialize();
}
});
我尝试将导出更改为jQuery,而不是$,但这似乎没有改变任何东西。在shim下,您没有指定slider&moment的依赖项 请检查滑块和力矩导出的内容:)
我现在得到了这个错误
错误:将www/js/lib/jquery.js作为模块“jquery”进行评估失败,错误为:ReferenceError:window未定义
,有什么想法吗?你能从shim和check中去掉jquery:{exports:'$}吗?当我删除它时,仍然显示相同的错误。我还尝试了jquery:['jquery']
,然后说Shim config在节点中不受支持,可能有效,也可能无效。检测到模块:节点中不支持下划线垫片配置,可能有效,也可能无效。检测到模块:backbone
,然后我得到一个关于backbone.localStorage.js中未定义窗口的错误
shim: {
jquery: {
exports: '$'
},
underscore: {
exports: '_'
},
backbone: {
deps: ['underscore'],
exports: 'Backbone'
},
hammer: {
deps: ['jquery'],
exports: 'Hammer'
},
slider: {
deps: ['jquery'],
exports: 'slider'
},
moment: {
deps: ['jquery'],
exports: 'moment'
}
}