1

RequireJS (v2.1.5) でシムとパスの構成を混ぜて遊んでいたところ、問題が発生しました。バグのように見えますが、私の理解不足かもしれません。簡単なコード サンプルを次に示します。

この結合された Javascript ファイルには、2 つの amd モジュールとall.jsという名前の 1 つのグローバル オブジェクトが含まれています。

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>

さて、これを行うと、ONEとTWOが表示されます(OK):

require(["one", "two"], function(one, two) {
    one.log();
    two.log();
});

これを行うと、shim が読み込まれ、3 つ (ok) が表示されます。

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がロードされているのはまだ確認できます。

何がうまくいかないのですか?

4

0 に答える 0