1

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() { /* */ }
});

2 Answers 2

1

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(){})

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

Comments

0

I believe you can use the Require.js optimizer to do this for you: http://requirejs.org/docs/optimization.html

Comments

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.