How to ignore libraries in browserify programmatic api

14,724

Solution 1

As you can see from here the --noparse option provided on the command line is passed to the browserify({ }) call.

So in order to tell browserify to not parse jquery and three.js you have to pass the full path to your jquery and three.js files.

Example:

browserify({
  noParse: [
   require.resolve('./vendor/jquery'),
   require.resolve('./vendor/three')
  ]
})
.require(require.resolve('./entry.js'), { entry: true })
.bundle();

Solution 2

var browserify = require("browserify")

browserify({entries: ['./src/client/app.js']})
.ignore('jquery')

That would make browserify ignore jquery, and then jquery can be added on index.html directly.

Share:
14,724

Related videos on Youtube

kurttheviking
Author by

kurttheviking

I tackle hard problems.

Updated on June 25, 2022

Comments

  • kurttheviking
    kurttheviking about 2 years

    Assume the below code is found in bundler.js and tracing entry.js leads to var B = require('backbone'); (Backbone is a dependency installed as declared in package.json).

    var browserify = require('browserify');
    var bundle = new browserify();
    bundle.add('entry.js');
    bundle.bundle({
      noParse: ['backbone']
    });
    

    Executing this bundler yields a stream that contains the original backbone source. Based on browserify's command line options I expected it to skip backbone alltogether. Reading through the source, I expected perhaps the following would work:

    var browserify = require('browserify');
    var bundle = new browserify({
        noParse: ['backbone']
    });
    bundle.add('entry.js');
    bundle.bundle();
    

    Though backbone source still appears in the stream output.

    Is it possible to use --noparse=FILE as a configuration option in this application of the api?

    • smhg
      smhg over 10 years
      Did you find a solution to this?
  • kurttheviking
    kurttheviking almost 11 years
    I appreciate the reference to source. I implemented a similar block but the parse times with and without noParse on all large files (jQuery, Backbone, Lodash) is identical: ~15seconds. to me, that suggests the files are indeed still being parsed
  • Software Engineer
    Software Engineer about 10 years
    Perhaps a little more explanation?
  • cancerbero
    cancerbero over 9 years
    this worked for me, thanks, example: browserify({entries: ['./js/index.js']}).ignore('backbone').ignore('jquery').igno‌​re('underscore')
  • Louis-Rémi
    Louis-Rémi over 9 years
    I had trouble verifying noParse actually worked. I ended up adding console.log(file); in node_modules/browserify/index.js' globalTr function just before the var parts = file.split('/node_modules/'); line. It helped me realize I was using the wrong paths for the file I wanted to ignore. I wish browserify had a more verbose --verbose mode.
  • haxpor
    haxpor over 7 years
    More example of chart.js that did it here github.com/chartjs/Chart.js/blob/master/gulpfile.js#L105