How do I use requireJS and jQuery together?

前端 未结 5 1482
暗喜
暗喜 2020-11-30 16:14

I would like to use requireJS and I am using jQuery. I don\'t want to use the combined version of requireJS and jQuery since I am not using the latest jQuery version. What i

5条回答
  •  难免孤独
    2020-11-30 17:12

    This question is at least two years old now, but I noticed this is a problem still with RequireJS 2.0 (require-jquery.js uses jQuery 1.8.0, but the latest version is 1.8.2).

    If you happen to see this question, note that require-jquery.js is now just require.js and jquery.js, mashed together. You can just edit require-jquery.js and replace the the jQuery parts with a newer version.

    Update (May 30, 2013): Now that RequireJS has paths and shim, there is a new way to import jQuery and jQuery plugins, and the old method is no longer necessary nor recommended. Here is an abridged version of the current method:

    requirejs.config({
        "paths": {
          "jquery": "//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min"
        }
    });
    
    define(["jquery"], function($) {
        $(function() {
        });
    });
    

    See http://requirejs.org/docs/jquery.html for more info.

提交回复
热议问题