Webpack: how to tame npm compatible js library

I have js libraries that are initialized as follows:

(function(root) { ...... ...... })(this) 

when building with webpack, I get something like

 function(module, exports) { (function(root) { })(this) } 

"this" is not a window as libraries suggest. Is there a neat way to tame this type of library to work with webpack? My last resort would be to crack this window using a postloader or something like that.

+5
source share
1 answer

Yes, we call these โ€œbroken modulesโ€ because, as you said, they just execute in a global context, there are several different methods for fitting these modules.

Here is a list of the various options (since the decision cam is library dependent). I like to use ProvidePlugin or use an alias and external ones.

+5
source

All Articles