Skip to content

Instantly share code, notes, and snippets.

@seemikehack
Created July 3, 2014 13:38
Show Gist options
  • Save seemikehack/ed605093b531fbb051fe to your computer and use it in GitHub Desktop.
Save seemikehack/ed605093b531fbb051fe to your computer and use it in GitHub Desktop.
RequireJS Dependencies and Automatic Script Loading
define(function (require) {
var a = require('a'),
b = require('b');
// explicitly loading module
require('c');
});
@jugglinmike
Copy link

You could define a "wrapper" module:

// file: wrapper.js
define(function(require) {
  require('c');
  require('original');
});

...then your original module would look like:

// file: original.js
define(function(require) {
  var a = require('a'),
      b = require('b');
});

...and you would then load wrapper in all the places you previously referenced original.

But I have to point out that this essentially makes the original module invalid--it has an implicit dependency that it isn't declaring. I can't think of a good reason to do this, but I could be convinced.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment