backbone.js - 将 jquery UI 与 require.js 和 CDN 结合使用

标签 backbone.js requirejs

我正在尝试使用 requirejs 通过 CDN 加载 jqueryui,这是我的配置:

paths:
 jqueryui: "http://ajax.googleapis.com/ajax/libs/jqueryui/1.9.2/jquery-ui.min.js"

shim:
 jqueryui:
   deps: ['jquery']

现在在我的主模块中,我只使用 require['jqueryui'],几乎是标准方式,其他一切都从我的私有(private) CDN 加载得很好,但 requirejs 也尝试从私有(private) CDN 加载 jqueryui,看起来认为 jqueryui 是一个本地模块。不知道哪里出了问题。另外,我使用 requirejs-rails gem 作为 require.js 的包装器。

最佳答案

当您在具有远程模块引用(例如 CDN 内容)的项目上运行 RequireJS 优化器 (r.js) 时,您应该在构建配置中使用 empty: 方案。

来自documentation :

You may have a script you want to load from a Content Delivery Network (CDN) or any other server on a different domain. [...] However, it is more likely that you do not want to include that resource in the build. If the script does not have any dependencies, or you do not want to include its dependencies or will be including them in another way, then you can use the special 'empty:' scheme in the paths config to just skip the file when doing an optimization.

因此请尝试在您的构建配置文件中指定:

paths: {
    jqueryui: "empty:"
}

关于backbone.js - 将 jquery UI 与 require.js 和 CDN 结合使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14203974/

相关文章:

javascript - Backbone 路由器不适用于 requirejs

javascript - 如何在嵌套模块中调用模块? javascript

javascript - Requirejs:jQuery 未定义

javascript - 匀场后如何从我的模块引用 PreloadJS?

javascript - 主干网触发了错误的路由器方法

javascript - Marionette "Uncaught TypeError: Object [object Object] has no method ' 渲染'",带有 ItemView

javascript - 配置 Karma 以使用 requirejs 加载 pegjs

javascript - 定义未定义(ESLint)

javascript - 主干 - 未定义的请求正文

django - 使用主干/ Ember 使 Django 成为一个简单的 REST API?