Dhruv Parmar
Dhruv Parmar

Reputation: 63

Shimming in Webpack

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 :

If anyone knows, even few answers of the questions mentioned above, please let me know.

Upvotes: 1

Views: 181

Answers (1)

Dmitry S.
Dmitry S.

Reputation: 8513

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.

Upvotes: 1

Related Questions