Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

I'm creating a file that requires huge libraries such as jquery and three.js using browserify. The compiling process takes several seconds, probably because it's recompiling all the libs for each minor change I make. Is there a way to speed it up?

like image 999
MaiaVictor Avatar asked Apr 29 '13 09:04

MaiaVictor


People also ask

What are some of the benefits of Browserify?

An additional advantage with Browserify is its use of transforms. Transforms work by injecting streams between resolved modules and content that is returned to transpile / convert code. Using transforms, you can support things like ES6 and JSX without having to precompile your code.

When should I use Browserify?

Browserify solves the problems of having too many JS files referenced in your HTML, inability to use Node modules in the browser, and inability to reference your own modules in your own code. Watchify streamlines the process of bundling your files and will make a change every time you change a JS file in your project.

Is Browserify a dev dependency?

We can also include browserify itself as a dependency, however it isn't a dependency for the project to run – any user to our app can find Superman without needing to run Browserify. It is one of our devDependencies – modules required for developers to make updates to this app. Now we've got a package.

Is Webpack still used?

Loved by many, hated by some, known to all. And still the most popular bundler in 2021. With more than 15 million weekly downloads (at the time of writing this post), there's no doubt that Webpack is still the bundler par excellence in 2021.


1 Answers

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.

like image 171
coderzach Avatar answered Oct 14 '22 07:10

coderzach