[英]Automatically list require.js dependencies with async loading for r.js optimization
[英]require.js and r.js dependencies
我的應用程序一直運行良好,但今天我決定給r.js一個漩渦。
現在我的樹(它的一部分)看起來像
在我的index.html文件中我有<script data-main="assets/js/main" src="assets/js/require.js"></script>
這是main.js
require.config({
paths: {
jquery: 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min',
underscore: 'components/underscore/underscore-min',
backbone: 'components/backbone/backbone-min',
jqueryui: 'components/jqueryui/jquery-ui-1.10.1.custom.min'
},
shim: {
'backbone': {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
'jqueryui': ['jquery']
}
});
require(['views/app'], function(App) {
var router = Backbone.Router.extend({
routes: {
'': 'root',
'year(/:year)': 'year'
},
root: function() {
new App();
},
year: function(year) {
new App({
year: year
});
}
});
r = new router();
Backbone.history.start({
// pushState: true
});
});
在我的模塊中,我引用我的文件,如assets/js/views/election.js
或assets/js/models/election.js
但是當我用這個build.js運行r.js時
({
// baseUrl: "assets/",
paths: {
jquery: 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min',
underscore: 'components/underscore/underscore-min',
backbone: "components/backbone/backbone-min",
jqueryui: 'components/jqueryui/jquery-ui-1.10.1.custom.min'
},
name: "main",
out: "main-built.js"
})
我得到Error: ENOENT, no such file or directory '/Users/alex/Dropbox/www/animated-elections/assets/js/assets/js/collections/elections.js'
。 我明白這意味着我不明白為什么它會在我的路徑中添加另一個assets/js
。
我相信require.js
應該與主文件位於同一個文件夾中,即。 在assets
文件夾旁邊而不是在其中。
r.js位於您的app目錄中,而不是示例設置中指定的兄弟。
我沒有測試過這個,但是r.js可能假設任何模塊調用應該相對於它所在的位置。
在build.js文件中添加此代碼。
baseUrl: ".",
paths: {
jquery: 'http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min',
underscore: 'components/underscore/underscore-min',
backbone: "components/backbone/backbone-min",
jqueryui: 'components/jqueryui/jquery-ui-1.10.1.custom.min',
'views/app': 'empty:',
'views/election': 'empty:',
//and so with others
},
name: "main",
out: "main-built.js"
問候。-
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.