【问题标题】:requirejs optimizer failed to load in jqueryrequirejs 优化器无法在 jquery 中加载
【发布时间】:2012-06-17 03:03:27
【问题描述】:

我正在优化我的 requirejs 应用以及主干和 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

我确保路径定义良好并且正常工作,除了这个错误(这是我在运行命令时得到的):

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)

非常感谢!

【问题讨论】:

  • 您找到解决方案了吗?

标签: javascript jquery node.js requirejs


【解决方案1】:

其中一些将取决于您加载脚本的顺序。 jQuery 是在 require.js 之前加载还是相反?

jQuery 的最后几行可能是解决问题的线索:

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(等)加载预压缩版本。在这种情况下,您需要排除 jquery 模块,如下所述:http://requirejs.org/docs/jquery.html

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

【讨论】:

  • 这对兄弟很有帮助!我节省了很多时间。我意识到最好“清空”通过 CDN 托管的库的路径,在本例中为 jQuery。我所做的是,我在命令中添加了 paths.jquery=empty。非常感谢:)
猜你喜欢
  • 2013-02-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-17
  • 1970-01-01
相关资源
最近更新 更多