2016-03-23 4 views
0

ハンドルバーをRequire.jsと一緒に使用していますが、何らかの理由でハンドルバーが表示されません。ハンドルバーはRequire.jsを使用して定義されていません

マイ設定:

require.config({ 
    paths: { 
     underscore: "lib/underscore-min",    //1.8.3 
     backbone: "lib/backbone-min",     //1.2.3 
     jquery: "lib/jquery-2.1.4.min",     //2.1.4 
     marionette: "lib/backbone.marionette.min",  //2.4.3 
     handlebars: "lib/handlebars.runtime.amd.min", //4.0.5 

    shim: { 
     "underscore": { 
      exports: "_" 
     }, 
     "backbone": { 
      deps: ["underscore", "jquery"], 
      exports: "Backbone" 
     }, 
     "jquery": { 
      exports: "jquery" 
     }, 
     "marionette": { 
      deps: ["backbone", "jquery"], 
      exports: "Marionette" 
     }, 
     "handlebars":{ 
      exports: "Handlebars" 
     } 
    } 
}); 

...と同じファイルに比べて:他のファイルで

require(["handlebars"], function(Handlebars){ 
    "use strict"; 
    console.log(Handlebars); //undefined 
}); 

define(["handlebars"], function(Handlebars){ 
    "use strict"; 

    console.log(Handlebars); //still undefined 
}); 

私はまた、コンパイル済みのテンプレートを使用していますこれは完璧に機能しているので、何が問題なのかわかりません。

ありがとうございます!

---- SOLUTION ----

ラジャブが指摘したように、問題は、私は彼の助けのための"handlebars"代わりの"handlebars.runtime"ので、感謝を使用したことだったが!

+0

ロードするファイルの依存関係を指定しないでください。 – Yerken

+0

それは単なる例だったので、私は問題を解決するために必要な部分を書きました。 – Dave

答えて

1

使用する必要があります

は([ "handlebars.runtime"]、関数(ハンドル){ `

代わりに

"が[(ハンドルを必要と必要"]、関数(ハンドルバー){`

またシムが使用されていますAMDをサポートしていないモジュールのために。あなたの例では完全に役に立たない。これらのライブラリはすべてAMDをサポートしています。例えばBACKBONE.JSに16ラインを見て:

define('handlebars.runtime', ['exports', 'module', './handlebars/base' ... etc 

すべての依存関係すでに内部

define(['underscore', 'jquery', 'exports'], function(_, $, exports) { 

やライン1002でhandlebars.runtime.amd.js。したがって、設定のパスのみが必要です。

require.config({ 
    paths: { 
     underscore: "lib/underscore-min",    
     backbone: "lib/backbone-min",     
     jquery: "lib/jquery-2.1.4.min",     
     marionette: "lib/backbone.marionette.min",  
     handlebars: "lib/handlebars.runtime.amd.min", 
    } 
} 

require(['handlebars.runtime'], function(HandlebarsOrWhateverNameYouWantItStillWillbeHandlebars){ 
    "use strict"; 
    console.log(HandlebarsOrWhateverNameYouWantItStillWillbeHandlebars); 
}); 

すべてです。

+0

うん、それは問題だった。助けと提案のおかげで! – Dave

関連する問題