2016-11-11 1 views

答えて

1

サードパーティのスクリプトがAMD互換性がない場合は、shimsを使用する必要があります。

上部のコードはこのような何か持っている場合、スクリプトはAMDに互換性がある場合は、チェックがあります

(function(root, factory) { 

    // Set up Backbone appropriately for the environment. Start with AMD. 
    if (typeof define === 'function' && define.amd) { 
    define(['underscore', 'jquery', 'exports'], function(_, $, exports) { 
     // Export global even in AMD case in case this script is loaded with 
     // others that may still expect a global Backbone. 
     root.Backbone = factory(root, exports, _, $); 
    }); 

    // Next for Node.js or CommonJS. jQuery may not be needed as a module. 
    } else if (typeof exports !== 'undefined') { 
    var _ = require('underscore'), $; 
    try { $ = require('jquery'); } catch(e) {} 
    factory(root, exports, _, $); 

    // Finally, as a browser global. 
    } else { 
    root.Backbone = factory(root, {}, root._, (root.jQuery || root.Zepto || root.ender || root.$)); 
    } 

}(this, function(root, Backbone, _, $) { 
    // .... 
} 

そして、ここでは、例えばのように私のプロジェクトの一つ上の構成ファイルをどのように見えるかです:

shim: { 

    // jQuery Mobile 
    "jquerymobile": ["jquery"], 

    // Twitter Bootstrap jQuery plugins 
    "bootstrap": ["jquery"], 

    // jQueryUI 
    "jqueryui": ["jquery"], 

    // jQuery Cookie 
    "jquery.cookie": { 
     deps: ["jquery"], 
     exports: "jquery.cookie" 
    }, 

    // jQuery easing functions 
    "jquery.easing" : { 
     deps: ["jquery"], 
     exports: "jquery.easing" 
    }, 

    // Shim backbone to resolve conflicts on minification 
    "backbone": { 
     deps: ['underscore', 'jquery'], 
     init: function(_, $) { 
      return this.Backbone = Backbone.noConflict(); 
     } 
    }, 

    // Backbone.validateAll plugin that depends on Backbone 
    "backbone.validateAll": ["backbone"], 

    "backbone.paginator" : { 
     deps: ["backbone"], 
     exports : "Backbone.Paginator" 
    }, 

    "backgrid" : { 
     deps : ['jquery', 'underscore', 'backbone'], 
     exports: "Backgrid" 
    }, 

    "backgrid.paginator" : { 
     deps: ["backbone", "backgrid"], 
     exports : "Backgrid.Paginator" 
    } 

} 
+0

バックボーンにはデフォルトでシムが必要ありませんが、この場合、グローバル化したくない場合は、shim 'init'が最適です。 –

関連する問題