Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

raphael's avatar

Browserify becomes very slow with many components

I'm building a Front-End with React and embedded a number of components. Running gulp watch and browserifying already takes up to 12 seconds and it's getting worse and worse.

elixir(function (mix) {
    mix.browserify('resources/assets/js/app.js', null, null, {
        paths: ['./node_modules', './resources/assets/js']
    })
});

Unfortunately, Elixir does not come with the great watchify module which allows to re-compile incrementally (much faster).

I found a laravel-elixir-browserify extension (https://www.npmjs.com/package/laravel-elixir-browserify), but this does one not support Elixir 3.0 (only ^2.0).

How can I improve the build performance? Has anyone implemented a custom watcher for watchify yet?

0 likes
5 replies
raphael's avatar

Okay, by checking Elixir's Config.js file, I found out that watchify already is included: You can enable it in your gulpfile.js or elixir.json in the root directory.

elixir.config.js.browserify.plugins = [watchify];
elixir.config.js.browserify.options = {cache: {}, packageCache: {}};

or

elixir.config.js.browserify.watchify.enabled = true;
elixir.config.js.browserify.watchify.options = {cache: {}, packageCache: {}};

However, neither nor does speed up anything at all.

Any ideas?

ohffs's avatar

Are you including the whole of node_modules? That's quite a lot of js if you are?

raphael's avatar

From the manual:

opts.paths is an array of directories that browserify searches when looking for modules which are not referenced using relative path. Can be absolute or relative to basedir.

I'm just telling browserify to also look into the node_modules directory when importing components.

TorbenDaudistel's avatar
Level 5

Hi,

do you use homestead with nfs? If so, you have to enable polling in the watchify options.

Second: As you pass individual options to your browserify task, I get the impression, that the watchify options are not applied correctly. Try the following after enabling watchify.

elixir(function (mix) {
    mix.browserify('resources/assets/js/app.js', null, null, {
        paths: ['./node_modules', './resources/assets/js'],
        cache: {},
        packageCache: {}
    })
});
3 likes
raphael's avatar

@TorbenDaudistel Thank you so much! Putting the cache and packageCache inside the browserify-options solved it <3

elixir(function (mix) {
    mix.browserify('resources/assets/js/app.js', null, null, {
        paths: ['./node_modules', './resources/assets/js'],
        cache: {},
        packageCache: {}
    })
});
1 like

Please or to participate in this conversation.