jQuery 1.7+, AMD (RequireJS), and Global Scope

江枫思渺然 提交于 2019-12-06 08:40:39

Ok, just after posting, I just realized I could proxy it through another file:

//main.js
require.config({
    paths : {
    jquery : 'my/libs/jquery-1.7.1.min',
    jQuery : 'my/src/jquery'
}

and

//my/src/jquery.js

define([
        'jquery'
    ],
    function($) {
        $.noConflict(true);

        return $;
    }
);

The reason for the 'jquery' alias for the main file rather than just reference the fully qualified location in the proxy is because I'm using an AMD-ready branch of Backbone that depends on this alias:

https://github.com/jrburke/backbone/blob/2b0cfb4282f071cffb14a9573d703da6acc5febd/backbone.js

The author has had some commits accepted by Document Cloud and is hoping that this modification gets drawn in too.

It will be interesting to see if there are any flaws with this or what additional answers there could be from the AMD battle tested.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!