Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to ignore libraries in browserify programmatic api

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?

like image 345
kurttheviking Avatar asked Aug 11 '13 06:08

kurttheviking


2 Answers

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();
like image 179
Thorsten Lorenz Avatar answered Nov 20 '22 01:11

Thorsten Lorenz


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.

like image 41
iLemming Avatar answered Nov 20 '22 01:11

iLemming