Browserify shim jquery expose doesn't process a lib while working fine on another

霸气de小男生 提交于 2019-12-10 20:45:49

问题


I'm facing a problem with exposing global jquery to several npm loaded non-commonjs libs.

I have a following jquery expose config in package.json:

"browserify-shim": {
"jquery": "global:jQuery",
...

And I'm trying to apply this to this datepicker from eonasdan that has a common-js dependency resolving:

'use strict';
if (typeof define === 'function' && define.amd) {
    // AMD is used - Register as an anonymous module.
    define(['jquery', 'moment'], factory);
} else if (typeof exports === 'object') {
    factory(require('jquery'), require('moment'));
} else {

But the compiled file doesn't replace require('jquery') with a global variable construct as it happens in all the rest of files including other libs, like this compiled bootstrap-slider for example:

if(typeof define === "function" && define.amd) {
    define(["jquery"], factory);
}
else if(typeof module === "object" && module.exports) {
    var jQuery;
    try {
        jQuery = (typeof window !== "undefined" ? window['jQuery'] : typeof global !== "undefined" ? global['jQuery'] : null);
    }
    catch (err) {
        jQuery = null;
    }
    module.exports = factory(jQuery);
}

What could possibly be a reason of this lib being such exceptional?

Does the depth of require chain matter for browserify-shim? Cause the slider is being required in the main bundling file, while datepicker is a dependency of dependency of a bundle (3rd level)

来源:https://stackoverflow.com/questions/32616028/browserify-shim-jquery-expose-doesnt-process-a-lib-while-working-fine-on-anothe

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