Backbone在indexview模塊中沒有被調用。requirejs + backbonejs + optimizer = backbone undefined
使用requirejs 2.1.5/2.1.4和0.9.10 backbonejs
運行r.js...
// this is causing the backbone to return
// null/undefined in the next define call below
define("backbone", function(){});
define('views/index/IndexView', [
'underscore',
'backbone',
'text!templates/index/indexTemplate.html'
], function(_, Backbone, indexTemplate){
console.log(Backbone); // returns undefined
var IndexView = Backbone.View.extend({
...
但如果我拿出首先定義調用註冊骨幹作爲後
main.js一個模塊,一切 工作正常。但backbone-min.js分別加載。但現在這是運行腳本的唯一方式 。我絕對錯過了一些東西。
main.js
require.config({
paths: {
underscore : 'libs/underscore/underscore-min',
backbone : 'libs/backbone/backbone-min'
templates : '../templates'
},
shim: {
'backbone': {
deps: ['jquery','underscore'],
exports: 'Backbone'
}
}
});
require(['app'], function(App){
App.initialize();
});
build.js
({
appDir: "../",
baseUrl: "js",
dir: "../../build",
optimize: "none",
paths: {
"jquery": "libs/requirejs/require-jquery",
"underscore" : 'libs/underscore/underscore-min',
"backbone": 'libs/backbone/backbone-min',
"templates": '../templates',
},
modules: [
{
name: "main",
exclude: ["jquery"]
}
]
})
我仍然得到我的腳溼骨幹和requirejs。 任何反饋非常感謝。
它必須是除了你的配置的。在我的構建中,require塊如下所示: define(「backbone」,[「jquery」,「undercore」],(function(global){return | global.Backbone; }; }(this))); 請注意,我在我的shim.js中也有下劃線 – mbseid 2013-03-07 19:47:44
您可以像下面這樣將'mainConfigFile'添加到您的build.js文件中:'mainConfigFile:'app/main.js''然後重建? – Mirodil 2014-02-10 14:38:12