requirejs优化器未能在jquery中加载

我正在优化我的requirejs应用程序以及backbone和jquerymobile,以下是我的文件结构:

/application /app /models /views /collections /scripts main.js text.js /assets backbone.js /libs /jquery /jquery.js /jquery-mobile.js app.js r.js /public /css /style.css 

在控制台中,我尝试运行ff命令:

 node ../r.js -o name=main out=../build.js baseUrl=. paths.models=../app/models paths.app=../app 

我确定path定义良好,正确工作,除了这个错误(这是我运行命令时得到的):

 Tracing dependencies for: main Error: Module loading did not complete for: jquery at Function.traceDependencies (/home/dunhak/public_html/my_path/etc/application/r.js:15117:19) 

非常感谢!

其中一些将取决于您加载脚本的顺序。 jQuery加载之前require.js或其他方式吗?

jQuery的最后几行可能会提供一个解决scheme的线索:

 if ( typeof define === "function" && define.amd && define.amd.jQuery ) { define( "jquery", [], function () { return jQuery; } ); } 

我的猜测是你正在做的事情是这样的:

 var $ = require('jquery'); //lower-case Q 

亲自,我一直在做:

 var $ = require('jQuery'); //upper-case Q 

这一切都可能取决于你的require.config – 我使用类似于:

 require.config({ baseUrl: "/js", paths : { jQuery: 'lib/jquery-1.7.1.min' //, etc... } }) 

还有一件事要考虑:你可能不希望jQuery包含在你的优化输出中,而是从CDN(etc)加载预缩减的版本。 在这种情况下,您需要按照此处所述排除jquery模块: http : //requirejs.org/docs/jquery.html

 modules: [ { name: "main", exclude: ["jquery"] } ]