I’m curious about things like jQuery
, React
These packaged libraries can be used globally after loading $
, jQuery
and React
comes to visit and wants to know how the library you built can be used globally like React
.
I found that after webpack packaging, the related objects defined could not be found globally at all.
Package it into a library, please read https://webpack.js.org/guides...
After webpack is packaged, it is all closures. How can it be accessed globally?
In order to have global access, the relevant configuration of new webpack.ProvidePlugin must be added to webpack
For example
Generally, just register your main object (or class) directly to the global object. For example, you can imitate the jQuery registration method (removing the section that determines document):
If you adopt a modular writing method, you can write the above code on the entry module.