【发布时间】:2012-12-29 17:26:53
【问题描述】:
我有兴趣为我网站上的所有 JavaScript 代码创建一个配置对象。我找到了https://github.com/requirejs/example-multipage-shim,这是此设置的一个示例。
来自https://github.com/requirejs/example-multipage-shim(强调 我的):由于 shim 配置需要依赖项在页面中, 而不是对 page1.html 使用 data-main="js/page1",这个例子 在 HTML 页面中内联 require 调用。 如果使用了 data-main 相反,“js/page1”不能内联任何依赖项, 而是仍然依赖 'common' 和 'app/main1' 构建层 保留模块,由于 shim 配置对 构建。
我不明白加粗的句子。这是否意味着“js/page1”如果存在就不能声明依赖关系?内联依赖是什么意思?内联成什么? HTML 文件还是 JavaScript 文件?
我阅读了有关 shim 配置的 API 文档,但它对优化器的限制尚不清楚。
来自https://github.com/requirejs/example-multipage-shim/blob/master/www/page1.html:
<script src="js/lib/require.js"></script>
<script>
//Load common code that includes config, then load the app
//logic for this page. Do the require calls here instead of
//a separate file so after a build there are only 2 HTTP
//requests instead of three.
require(['./js/common'], function (common) {
//js/common sets the baseUrl to be js/ so
//can just ask for 'app/main1' here instead
//of 'js/app/main1'
require(['app/main1']);
});
</script>
为什么以下错误?为什么“app/main1”必须与引导(数据主)代码位于单独的模块中?
<script src="js/lib/require.js"></script>
<script>
require(['js/common'], function (common) {
var underscore = require('underscore');
// ...
});
</script>
【问题讨论】:
标签: requirejs