browserify / factor-bundle

factor browser-pack bundles into common shared bundles
Other
400 stars 27 forks source link

Is it possible to manually decide which dependency should be considered "common" #85

Closed jessedvrs closed 8 years ago

jessedvrs commented 8 years ago

Let's say I have a lot of entry-points in my application and only a few entry-points require dependency X. It is somehow possible to exclude X from being considered common? Or better: is it possible to specify which dependencies are added to the common-bundle?

A very strong side of factor-bundle is that it does optimisations while leaving all files unchanged. I would be pleased if I can keep it like that since I am working on a very large scale application.

jessedvrs commented 8 years ago

For a second I thought that I would be able to do it using the undocumented threshold (Function) option. Unfortunately, that function gets called for every entry-point, not for every dependency.

terinjokes commented 8 years ago

@jessedvrs The threshold function is called for each file being added to the bundle.

jessedvrs commented 8 years ago

Got it working using the threshold option as a function.

var contains = require('mout/array/contains');
...
threshold: function(row, groups) {
    return contains([
            'node_modules/jquery/dist/jquery.js',
            'node_modules/angular/index.js',
            'node_modules/moment/moment.js',
            'node_modules/moment/locale/nl.js',
            'node_modules/angular-resource/index.js',
            'node_modules/angular-messages/index.js',
            'node_modules/angular-animate/index.js',
            'node_modules/angular-sanitize/index.js',
            'src/app/cb/index.js'
    ], row.sourceFile);
}

Only the files specified in the array are being added to my common bundle now. Thanks @terinjokes ;)