0

I am building a basic outline for a fairly complex angular.js application. I choose browserify this time over require.js because of support of cjs modules in browser. But the only thing that is now holding me back is the fact that browserify bundles each 'require' call in the same file. So for e.g if I have the modules:

MODULE - A (Requires angular.js and jQuery)

MODULE - B (Requires angular.js and jQuery)

What browserify will do is, it will bundle angular and jQuery in both the MODULE-A and MODULE-B which is going to increase the size of the code base in the first place. When I try to compare the same with require.js, its evident that require is going to load the angular.js only once. So is it a known tradeoff between performance and flexibility?

Is it how it is suppose to be? Kindly shed some light over the same.

1 Answer 1

0

If the two modules require use the same version of angular.js and jQuery, browserify will only include it in the bundle once. However, if they use different versions, it will include them twice. This is by design.

If this is not the behavior you are seeing, make sure you are using a recent version of browserify as there were a couple of relevant bugs in older versions:

Sign up to request clarification or add additional context in comments.

2 Comments

what i don't understand is that how browserify will be able to figure out if the angular.js has been already bundled with some other module or not and then not to include it for the other module
If it's literally pasted into the code of another module (which defeats the whole purpose of modules), then it won't know. But if it is included via require(), then it can keep track of all modules and versions so it can avoid duplicates. (That might not be exactly what it's doing, but you get the idea. You can read the source code if you want to know exactly what it's doing.)

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.