我是 RequireJS 的新手,但似乎碰壁了。
麻烦从我的“app”模块开始。我不确定如何告诉 RequireJS 加载我的叶子模块——依赖于“app”的包。
我想我明白为什么 - 因为系统中没有任何东西依赖于它们并且它们没有在任何地方注册,但我需要处理这种情况。
我怎样才能让 RequireJS 知道这些模块并适当地加载它们?
干杯
//index.html
....
<script data-main="app/config" src="/assets/js/libs/require.js"></script>
....
//config.js
require.config({
deps: [ "app" ],
paths: {
libs: "../assets/js/libs",
plugins: "../assets/js/plugins",
jquery: "../assets/js/libs/jquery",
underscore: "../assets/js/libs/underscore",
backbone: "../assets/js/libs/backbone",
marionette: "../assets/js/libs/backbone.marionette"
}
});
//app.js
require(
[ "jquery", "underscore", "backbone", "marionette" ],
function ( $, _, Backbone, Marionette ) {
//....
}
);
//app.view.js
require(
[ "jquery", "underscore", "backbone", "marionette", "app" ],
function ( $, _, Backbone, Marionette, App ) {
//....
}
);
//app.route.js
require(
[ "backbone", "app" ],
function ( Backbone, App ) {
//....
}
);
因此:
- app.js 依赖于“jquery”、“underscore”、“backbone”、“marionette”
- app.view.js 依赖于 "jquery", "underscore", "backbone",
- "marionette", "app" app.route.js 依赖于 "backbone", "app"