Reputation: 20107
For the sake of loading times, I'm interested in predefining all AMD module dependencies. This is because at the moment, the module file must load before require.js can work out its dependencies. Here's an illustration to show what I mean:
Is there any way to do this with require.js? I know you can define dependencies for the shimmed modules, but can you do this for your own custom AMD modules?
Upvotes: 1
Views: 583
Reputation: 151370
You are looking for something you can put in the configuration you pass to RequireJS that would do what you want. There is no analogue to shim
for modules that call define
. However, what you could do is add the deps
option to your configuration:
deps: ['module', 'dep1', 'dep2', 'dep3']
This will tell RequireJS to start loading immediately your module and the dependencies. You will have to maintain this list yourself but this would be true with shim
too.
Otherwise, you can do what kryger suggested in a comment: use r.js
to build module
into a single bundle that contains it and all of its dependencies. Whenever module
is loaded, all of its dependencies are loaded at the same time. This is more efficient than using deps
but might make things slightly more complicated if you ever need to load any of the dependencies by themselves. You'd have to use the runtime option bundles
to tell RequireJS where these modules are. And just like deps
you'd have to maintain this list yourself.
Upvotes: 1