2013-03-16 72 views
2

我有一些问题试图让我的Phonegap应用程序在使用r.js后使用RequireJS,BackboneJS和各种库进行工作。我得到我的主build.js以下错误优化事后但是之前未捕获TypeError:无法读取undefined RequireJS Optimizer Backbone的属性'View'

Uncaught TypeError: Cannot read property 'View'

下面是我需要配置

require.config({ 
baseUrl: 'lib', 
paths: { 
    domReady  : 'require/domReady', 
    text   : 'require/text', 
    async   : 'require/async', 
    jquery   : 'jquery/jquery', 
    jqmconfig  : 'jqm/jqm-config', 
    jqm    : 'jqm/jquery.mobile', 
    underscore  : 'underscore/underscore', 
    backbone  : 'backbone/backbone', 
    jqmaps   : 'google/jquery.ui.map', 
    router   : '../app/router', 
    models   : '../app/models', 
    collections  : '../app/collections', 
    views   : '../app/views', 
    templates  : '../app/templates', 
    app    : '../app/app' 
}, 
shim: { 
    underscore: { 
     exports  : '_' 
    }, 
    backbone: { 
     deps   : ['jquery', 'jqmconfig', 'jqm', 'underscore'], 
     exports  : 'Backbone' 
    }, 
    jqmconfig   : ['jquery'], 
    jqm    : ['jquery','jqmconfig'], 
    jqmaps   : ['jqm'] 
}}); 

一切正常,这是我的引导

require(
[ 
    'app', 'domReady', 'jqmconfig' 
], 

function(app, domReady){ 

    domReady(function() { 
     // On device ready initialize the app code 
    }); 
}); 

这里是我的build.js

({ 
baseUrl: 'lib', 
paths: { 
    domReady  : 'require/domReady', 
    text   : 'require/text', 
    async   : 'require/async', 
    jquery   : 'jquery/jquery', 
    jqmconfig  : 'jqm/jqm-config', 
    jqm    : 'jqm/jquery.mobile', 
    underscore  : 'underscore/underscore', 
    backbone  : 'backbone/backbone', 
    jqmaps   : 'google/jquery.ui.map', 
    router   : '../app/router', 
    models   : '../app/models', 
    collections  : '../app/collections', 
    views   : '../app/views', 
    templates  : '../app/templates', 
    app    : '../app/app', 
    main   : '../app/main', 
}, 
name: 'main', 
out: 'app/main-build.js'}) 

什么东西显而易见?

谢谢你的时间。

回答

1

shim-config应该在build.js文件中公布,所以r.js可以正确包含填充依赖项到app/main-build.js。您可以简单地在build.js中复制您的垫片或更好地指定mainConfigFile选项,以便您的pathsshim只能在一个位置列出。

+0

非常感谢! – 2013-03-17 08:57:26

+0

欢迎您:) – user20140268 2013-03-17 10:51:28

相关问题