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 Commented Nov 23, 2012 at 10:10
  • Ah, it seems to be working, you must just specify the dependency and use the $ as normal. Commented 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($) {

}
Sign up to request clarification or add additional context in comments.

5 Comments

Could you explain exports, and init in shim?
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
Where do I use these module names? Is it the same as the module ID in definitions
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?
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.

Your Answer

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.