问题
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