複数のアプリケーションで共有されるrequirejsの構成があります。アプリが読み込まれると、アプリはアプリのレイアウト (およびその他のさまざまなパラメーター) を含むオブジェクトを受け取ります。そのオブジェクトを使用して、アプリのモジュール/パッケージを定義したいと考えています。
siteMap = { modules: { "foo": { … }, "bar": { … }, … }, other: "stuff" }
/shared/
libs/
bootstrap.js
jquery.js
…
app.js
/$appName/
foo/
index.html
edit.html
main.js
bar/
index.html
stuff.html
main.js
…
次のようなパッケージを追加する方法が必要だと思います。
// /shared/app.js
require.config({
paths: {
"bootstrap": ["//hosted.bootstrap.js","/shared/libs/bootstrap.js"],
"jquery": ["//hosted.jquery.js","/shared/libs/jquery.js"],
"siteMap": "//appName.example.com/api/siteMap"
},
…
});
require(['jquery','siteMap','bootstrap'], function($,siteMap) {
for ( var module in siteMap.modules )
{
require.config.packages[module] = siteMap.modules[module];
// OR
require.addPackage(siteMap.modules[module]);
}
});