如何通过 RequireJS 加载 jQuery Migrate for jQuery? [英] How to load jQuery Migrate for jQuery via RequireJS?

查看:38
本文介绍了如何通过 RequireJS 加载 jQuery Migrate for jQuery?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以通过 RequireJS 加载 jQuery 迁移吗?我不明白如何正确处理时间.看这个例子:

Can I load jQuery migrate via RequireJS? I don't understand how the timing can be handled correctly. See this example:

require([
  'jquery',
  'jqmigrate'
], function ($) {
  if ($.browser.msie) {...}
});

jqmigrate 是否有可能在 jquery 之前加载?另外,我不想在每个模块中都显式地加载 jqmigrate.有什么方法可以在 require.config 中执行此操作,以便在需要 jQuery 时自动加载 jqmigrate?

Isn't is possible that jqmigrate will load before jquery? Also, I do not want to keep loading jqmigrate explicitly in every module. Any way to do this in the require.config so it loads jqmigrate automatically when jQuery is required?

推荐答案

使用垫片对我有用.我确实被卡住了,因为我把它的 shims 进行了复数化;垫片

using shims worked for me. I did get stuck because i had pluralized shims its; shim

requirejs.config({
    paths: {
        'jquery': '//code.jquery.com/jquery-2.1.4',
        'jquery-migrate': '//code.jquery.com/jquery-migrate-1.2.1'
    },
    shim: {
        'jquery-migrate': { deps: ['jquery'], exports: 'jQuery' },
        'foo': ['jquery']
    }
});
require(['jquery-migrate', './foo'], ($, foo) => {
     console.log('bootstrapped', $, foo);
});

这篇关于如何通过 RequireJS 加载 jQuery Migrate for jQuery?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆