I am reading Shimming from the official docs. of Webpack, but still I'm unable to get what it means ?
As I am new to Webpack, I have also tried to do some RND, but I could not get the proper answer from that. I have few questions about Shimming which are as follow :
- What is
Shimming? - What does
Shimmingdoes actually ? - Why there is need of
Shimmingin webpack ? - How it works ?
- Pros and cons of
Shimming.
If anyone knows, even few answers of the questions mentioned above, please let me know.
CodePudding user response:
Some libraries depend on global variables. For example, a jQuery plugin may expect the "$" global variable to be available.
Without shimming that variable with ProvidePlugin you would get an error $ is not defined.
In simple terms shimming would replace all global $ variables in JavaScript modules with require('jquery'). In some legacy libraries you would also need to shim jQuery or window.$ because the plugin only performs a basic text replacement.
You only need shimming for libraries or any code you do not have control over. In the application modules you should import jQuery with import $ from 'jquery' and avoid global variables.
