我在 RequireJS (v2.1.5) 中混合 shims 和路径配置时遇到了问题。它看起来像一个错误,但也许只是我缺乏理解。这是一个简单的代码示例:
我有这个组合的 Javascript 文件,其中包含两个 amd 模块和一个名为all.js的全局对象:
define("one", [], function() {
return {
log: function() {
console.log("ONE"); }
};
});
define("two", [], function() {
return {
log: function() {
console.log("TWO");
}
};
});
window.three = {
log: function() {
console.log("THREE");
}
};
这是配置:
<script>
requirejs.config({
baseUrl: ".",
paths: {
one : "all",
two: "all",
three: "all"
},
shim: {
three: {
exports: "three"
}
}
});
</script>
现在,如果我这样做,我会看到一个和两个(好的):
require(["one", "two"], function(one, two) {
one.log();
two.log();
});
如果我这样做,垫片已加载,我看到三个(好的):
require(["three"], function(three) {
three.log();
});
但是,如果我结合上述内容,什么也不会发生,我会收到错误Uncaught Error: Load timeout for modules: three:
require(["one", "two", "three"], function(one, two, three) {
one.log();
two.log();
three.log();
});
我仍然看到all.js加载到我的网络面板中。
怎么了?