Reputation: 5848
I am using RequireJS, but our project has gotten quite large.
requirejs([
'util/utils',
'util/image_store',
'models/user_model',
'util/analytics'
],function() { /* do start here */ });
I've taken that initial group and I've concatenated together of those files so now I want to do this: requirejs([ 'initial_download.js' ],function() { /* do start here */ });
Now how do I let the other files know, that say use models/user_model that they don't need to download it themselves that requires already did a define?
Like this in a hypothetical UserView.js:
define(['models/user_model'],function(UserModel) {
function UserView() { /* */ }
});
Upvotes: 1
Views: 110
Reputation: 4996
when you concatenated the files, you needed to wrap each file's contents into a named define
call. This way when it loads, the modules resurrect themselves as if they were loaded from individual files:
;(function() {
define('util/utils',function(){
return utilsObject
})
define('util/image_store',function(){
return imageStoreObject
})
define('models/user_model',function(){
return userModelObject
})
define('util/analytics',function(){
return analyticsObject
})
// you need this to make this an AMD module.
// it does not matter what it returns, as your
// main payload is above.
define(function(){})
})();
Upvotes: 1
Reputation: 5353
I believe you can use the Require.js optimizer to do this for you: http://requirejs.org/docs/optimization.html
Upvotes: 0