0

Can anyone explain me what is the use of shims dependencies in requirejs-config file? Doing much of research but I hasn't found exact answer for this.

Prathap Gunasekaran
3,2891 gold badge17 silver badges39 bronze badges
asked Mar 6, 2019 at 10:49
1
  • please update requirejs-config file Commented Mar 6, 2019 at 10:51

1 Answer 1

2

As per my understanding,
basically shim is used to avoid dependency conflict. For example if you calling a custom javascript then it must be loaded after javascript library isn't it? but magento doesn't know whether the library is loaded or not. So using shim we'll let system know that it is dependent on library so it will be instantiated when we map shim.

And

Magento uses requirejs to speed up the stuffs and (asynchronously module dependencies) nature of require js. So we use shim to tell the machine load our defined dependency first i.e., jquery

If we don't define then we get jquery not defined error while developing custom extensions as well.

Alan Strom :

The RequireJS shim configuration directive allows you to configure what I’ll call "load order" dependencies. i.e., you can say

when you load the jquery.cookie module? Make sure you’ve completely loaded the jquery module first.

Example :

var config = {
paths:{
 "jquery.cookie":"Package_Module/path/to/jquery.cookie.min"
},
shim:{
 'jquery.cookie':{
 'deps':['jquery']
 }
}};

We’ve defined a new top level configuration property named shim. This property is a javascript object of key value pairs. The key should be the name of your module (jquery.cookie above). The value is another javascript object that defines the shim configuration for this specific module.

see this for more information

Hope it helps :)

answered Mar 6, 2019 at 11:04

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.