2012-05-07 170 views
1

我有這個需要jQuery的插件。我不會使用jQuery版本的require,因爲某些原因不相關。RequireJS依賴關係序列

define(['jquery','dep1','dep2','mymodule'],function($,foo,bar,plugin){ 
    //all loaded 
}); 

由於AMD裝載機的性質,訂單不能保證。 order plugin還聲明該插件不能與定義調用一起使用,因此也不能與模塊定義一起使用。而the API只保證參數的順序,而不是執行順序。因此,如果在jQuery之前mymodule加載的事件會失敗。

如何保證在插件之前加載所需的依賴關係?

回答

1

首先,它並不像你所使用的順序插件;訂單插件需要您在文件名前添加order!

其次,您的mymodule文件還應該定義jQuery作爲要求。這將確保jquery在mymodule之前加載,而不必依賴於訂單插件。

模塊1

define(['jquery','dep1','dep2','mymodule'],function($,foo,bar,plugin){ 
    //all loaded 
}); 

mymodule.js

define(['jquery'],function($){ 
    //all loaded 
}); 
0

,你可以這樣做:

define(['jquery', 'dep1', 'dep2'], function() { 
    //load myModule separately 
    var m = require('mymodule'); 
});