1

I am trying to use some of the jQuery plugins in my project (I am using RequireJS). However I don't understand how to do it. I have tried to follow this: http://requirejs.org/docs/api.html#config-shim After what I understand it sets up a dependency of whats inside the array. I thought I could do this in a module:

define(['ui'], function($) {

}

However it does not work. What am I missing? This is from my require.config:

shim: {
        'ui': {
            'deps': ['jquery']
        },
        'tools': {
            'deps': ['jquery', 'ui']
        }
}

and paths;

'paths': {
    'jquery': 'lib/jquery/jquery',
    'ui': 'jquery/jquery-ui.min',
    'tools': 'jquery/jquery.tools.min',            
},
2
  • have u defined paths for ui and tools in config
    – deven98602
    Nov 23, 2012 at 10:10
  • Ah, it seems to be working, you must just specify the dependency and use the $ as normal.
    – user626912
    Nov 23, 2012 at 10:16

1 Answer 1

1
requirejs.config({
'paths': {
    'jquery': 'lib/jquery/jquery',
    'ui': 'jquery/jquery-ui.min',
    'tools': 'jquery/jquery.tools.min',            
},
    shim:{
        'ui': {
            'deps': ['jquery'],
            // exports :'ui'   As they are jquery plugins they will not require exports
        },
        'tools': {
            'deps': ['jquery', 'ui'],
             //exports : 'tools'
        }
} 
});

define(['jquery'], function($) {

}
5
  • Could you explain exports, and init in shim?
    – user626912
    Nov 23, 2012 at 10:22
  • exports are used to make the module name available to other modules that are dependent on it .It used for non-amd modules. init function are called before module name is exported .used generally to do cleanup,like calling noConflicft() to avoid overriding a module name already present
    – deven98602
    Nov 23, 2012 at 10:45
  • Where do I use these module names? Is it the same as the module ID in definitions
    – user626912
    Nov 23, 2012 at 11:07
  • so if I add export to ui with exports: 'test' then I would require 'test'? But why do I specify ui in the dependency list, or would this also change then?
    – user626912
    Nov 23, 2012 at 11:14
  • Inside shim for tools in dependecy list it will be still 'ui' because there you'r just asking it to be loaded before tools library is loaded.
    – deven98602
    Nov 23, 2012 at 11:32

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.