将jQuery Mobile添加到Yeoman Backbone项目中

时间:2014-02-28 19:00:11

标签: jquery-mobile backbone.js requirejs yeoman

我是Yeoman的新手,我正在使用官方Backbone生成器建立一个新项目。我使用以下命令添加了jQuery Mobile:

bower install -save jquery-mobile

当我运行应用程序时,require.js报告我的所有jquery-mobile脚本都丢失了。我已阅读此herehere上的帖子。我必须错过一步或让我的main.js设置错误。

以下是我的main.js的相关部分:

require.config({
  shim: {
      <...>
      jquerymobileconfig: {
        deps: [
            'jquery'
        ]
      },
      jquerymobile: {
        deps: [
          'jquery',
          'jquerymobileconfig'
        ]
      }
  },
  paths: {
    jquery: '../bower_components/jquery/jquery',
    jquerymobileconfig: 'jqmconfig',
    jquerymobile: '../bower_components/jquery-mobile/js/jquery.mobile',
    backbone: '../bower_components/backbone/backbone',
    underscore: '../bower_components/underscore/underscore'
  }
});

require([
  'jquery', 'backbone', 'jquerymobile'
], function ($, Backbone) {
  Backbone.history.start();
});

1 个答案:

答案 0 :(得分:1)

我找到了问题here的答案。而不是安装bower jquery-mobile项目,请安装:

bower install -save jquery-mobile-bower

这是bower / Yeoman项目的jquery-mobile的现成版本。然后在main.js中引用jquery mobile作为:

jquerymobile: '../bower_components/jquery-mobile-bower/js/jquery.mobile-1.4.1.min',