我正在为我的移动应用程序项目使用backbone.js 和underscore.js。我的问题是如何识别每个文件的 JavaScript 依赖关系?我尝试使用下面的代码,但仍然无法在我的浏览器中工作。
require.config({
waitSeconds: 0,
//path mappings for module names not found directly under baseUrl
paths: {
jquery: 'vendor/jqm/jquery_1.7_min',
jqm: 'vendor/jqm/jquery.mobile-1.4.0-rc.1',
underscore: 'vendor/underscore/underscore_amd',
backbone: 'vendor/backbone/backbone_amd',
jqueryflexslider: 'vendor/lib/jquery.flexslider',
shCore: 'vendor/lib/shCore',
shBrushXml: 'vendor/lib/shBrushXml',
shBrushJScript: 'vendor/lib/shBrushJScript',
jqueryeasing: 'vendor/lib/jquery.easing',
jquerymousewheel: 'vendor/lib/jquery.mousewheel',
demo: 'vendor/lib/demo',
text: 'vendor/require/text',
plugin: 'plugin',
main: 'main',
messages: 'messages',
templates: '../templates',
modules: '../modules',
model: '../model'
},
shim: {
'backbone': {
deps: ['underscore', 'jquery'],
exports: 'Backbone'
},
'jquery': {
exports: '$'
},
'jqm': {
deps: ['jquery'],
exports: '$'
},
'jqueryflexslider': {
deps: ['jquery'],
exports: '$'
},
'jqueryeasing': {
deps: ['jquery'],
exports: 'jQuery'
},
'jquerymousewheel': {
deps: ['jquery'],
exports: '$'
},
'demo': {
deps: ['jquery'],
exports: '$'
},
'main': {
deps: ['jquery'],
exports: '$'
},
'messages': {
deps: ['jquery'],
exports: '$'
},
'underscore': {
exports: '_'
},
}
});
//1. load app.js,
//2. configure jquery mobile to prevent default JQM ajax navigation
//3. bootstrapping application
define(['app', 'jqm-config'], function(app) {
$(document).ready(function() {
console.log("DOM IS READY"); // Handler for .ready() called.
});
app.initialize();
});
参考:https://github.com/woothemes/FlexSlider/blob/master/demo/index.html