我试图了解 TodoMVC 的 Backbone + RequireJS 版本。我不明白为什么在 main.js 文件中,主干包不是依赖项?
// Require.js allows us to configure shortcut alias
require.config({
// The shim config allows us to configure dependencies for
// scripts that do not call define() to register a module
shim: {
'underscore': {
exports: '_'
},
'backbone': {
deps: [
'underscore',
'jquery'
],
exports: 'Backbone'
}
},
paths: {
jquery: 'lib/jquery/jquery.min',
underscore: '../../../assets/lodash.min',
backbone: 'lib/backbone/backbone',
text: 'lib/require/text'
}
});
require([
'views/app',
'routers/router' // <--views/app.js and routers/router.js are the only dependencies
], function( AppView, Workspace ) {
// Initialize routing and start Backbone.history()
new Workspace();
Backbone.history.start(); // <--Here we use Backbone variable. Where do the writer tell the page about the backbone dependency??
// Initialize the application view
new AppView();
});