Node.js browserify slow: isn't there a way to cache big libraries? Node.js browserify slow: isn't there a way to cache big libraries? node.js node.js

Node.js browserify slow: isn't there a way to cache big libraries?


Have you tried using the --insert-globals, --ig, or --fast flags? (they're all the same thing)

The reason it's slow may be that it's scanning all of jquery and d3 for __dirname, __filename, process, and global references.

EDIT:

I just remembered: Browserify will take any pre-existing require functions and fall back to using that. more info here

This means you could build a bundle for your static libs, and then only rebuild the bundle for your app code on change.

This coupled with my pre-edit answer should make it a lot faster.


There are a few options that can help:

--noparse=FILE is a must for things like jQuery and three.js that are huge but don't use require at all.

--detect-globals Set to false if your module doesn't use any node.js globals. Directs browserify not to parse a file looking for process, global, __filename, and __dirname.

--insert-globals Set to true if your module does use node.js globals. This will define those globals without parsing the module and checking to see if they're used.

I was able to speed up my build by externalizing ThreeJS, using noparse with it, and setting it not to create a source map for it.

Use https://github.com/substack/watchify while developing.


If you use grunt, you can use my grunt task : https://github.com/amiorin/grunt-watchify

It caches the dependencies and watches the filesystem. Because of this the build is very fast. You can use it with grunt-contrib-watch and grunt-contrib-connect or alone. You can find a Gruntfile.js example in the github repository.

If you don't use grunt, you can use the original watchify from @substack : https://github.com/substack/watchify