Search code examples
browserify

browserify with noparse=true - how it works


I would like to ask what is the purpose of using browserify with noparse option set to true (or how browserify works). For instance:

  • if browserify does not parse files at all, does it means that it will not find require statements?
  • if it does not find require statements, then how to force code to load module? For instance, I have toastr & jQuery. toastr requires jQuery. But when I used browserify to create a bundle with noparse set to true, and I added to this bundle both files:

var bundler = browserify(); bundler.add('jquery.js'); bundler.add('toastr.js'); bundler.bundle();

then I get the error, that jQuery module it not found.


Solution

  • Normally when you bundle a file with browserify, it parses the file for require() calls so it can build a dependency graph and bundle the required files. The purpose of the noParse option is to skip that parsing when you don't need or want it. For example, if you're bundling a large library file like jQuery and you know it doesn't contain any require() calls that need to be processed, it will save time in bundling if you noParse that file. Also, it's currently difficult to require() a previously browserified bundle when making a new bundle. In that case you can sometimes resolve the issue by setting noParse for the previously browserified bundle.

    if browserify does not parse files at all, does it means that it will not find require statements?

    Yes.