1

Is there a way to do

require ['jquery'], ($) ->
  ...

instead of

require ['jquery', 'jquery-cookies', 'jquery-scroll', 'jquery-foo', jquery'bar'], ($) ->
  ...

each time?

axsuul
  • 7,370
  • 9
  • 54
  • 71
  • not really, because jQuery is a dependency of all the plugins, not the other way around. johlrich's answer is probably the easiest way to do it, although you should note my comment on it regarding load order... – market Oct 18 '12 at 01:37
  • no love for this question, wth is wrong with people?! i will give you the up-arrow for it though buddy! – Randy L Jan 25 '13 at 22:40

1 Answers1

2

One option would be to just define a new module that is jquery with your plugins.

// new module in something like jqueryBundle.js
define(['jquery', 'jquery-cookies', 'jquery-scroll', 'jquery-foo', 'jquery-bar'],  function($) {
    return $;
});

Then you could just require jqueryBundle instead.

Edit: Per comment suggestion, I neglected to mention that my answer expected the jquery plugins to be either amd modules (by author or wrapped by you) or already configured via shim configuration: http://requirejs.org/docs/api.html#config-shim

Many jquery plugins are not AMD modules, but are usually great candidates for simple shim configuration. For a small sample see my answer to another question: Using require.js with Twitter Boostrap API and backbone

Community
  • 1
  • 1
johlrich
  • 1,771
  • 1
  • 12
  • 11
  • 1
    unless the plugins are wrapped in an AMD module (using the `define()` call), they could be loaded before jQuery is, which would obviously cause issues... – market Oct 18 '12 at 01:35
  • 1
    good point, i added something regarding wrapping and/or shim configs, thanks for the suggestion – johlrich Oct 18 '12 at 01:47