如何使用AMD和commonjs声明可选的jQuery依赖项

时间:2017-04-23 14:17:07

标签: javascript requirejs amd

如何在纯javascript插件中声明jQuery的可选依赖项?

我当前的插件以:

开头
(function (root, factory) {
    if (typeof define === 'function' && define.amd) {
        // if i put 'jQuery' in the array here that's a forced dependency
        // and I want it optional
        define([], factory);
    }
    else if (typeof exports === 'object') {
        module.exports = factory();
    }
    else {
        root.myPlugin = factory(root.$ || root.jQuery);
    }
}(this, function (jQuery) {

    "use-strict";
     ... plug-in code

}));

0 个答案:

没有答案