2012-10-17 17 views

回答

6

除了您瞭解的路徑配置選項之外,您還應該查看墊片配置選項http://requirejs.org/docs/api.html#config-shim

許多插件不是AMD準備好的,所以您有兩種選擇。無論是將其配置爲墊片(適用於大多數的插件),或在https://github.com/amdjs

簡單的例子編寫自己的適配器一樣的努力:

require.config({ 
    shim: { 
     'bootstrap': ['jquery'], // no exports 
     'underscore': { exports: '_' }, // no dependencies 
     'backbone.layoutmanager': { 
      deps: ['backbone'] 
      exports: 'Backbone.LayoutManager' 
     } // a mix of exports and dependencies 
    } 
}); 

對於像json2它沒有依賴關係,並只激活,如果瀏覽器沒有本地實現,您可以簡單地將它列爲主應用程序需求的依賴項,而無需封裝/填充。