ฉันทำงานกับ requirejs + jquery และฉันสงสัยว่ามีวิธีที่ชาญฉลาดในการทำให้ปลั๊กอิน jQuery ทำงานได้ดีกับความต้องการหรือไม่
ตัวอย่างเช่นฉันใช้ jQuery-cookie ถ้าฉันเข้าใจถูกต้องฉันสามารถสร้างไฟล์ชื่อ jquery-cookie.js และภายใน do
define(["jquery"], // Require jquery
function($){
// Put here the plugin code.
// No need to return anything as we are augmenting the jQuery object
});
requirejs.config( {
"shim": {
"jquery-cookie" : ["jquery"]
}
} );
ฉันสงสัยว่าฉันสามารถทำสิ่งต่างๆเช่น jQuery ได้หรือไม่ซึ่งเป็นเช่นนี้:
if ( typeof define === "function" && define.amd && define.amd.jQuery ) {
define( "jquery", [], function () { return jQuery; } );
}
หรือถ้านี่เป็นวิธีเดียวที่จะทำให้ปลั๊กอิน jQuery เข้ากันได้กับ requirejs หรือ amd ใด ๆ