How to ignore libraries in browserify programmatic api
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.
Related videos on Youtube
Comments
-
kurttheviking about 2 years
Assume the below code is found in
bundler.js
and tracingentry.js
leads tovar B = require('backbone');
(Backbone is a dependency installed as declared inpackage.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 over 10 yearsDid you find a solution to this?
-
-
kurttheviking almost 11 yearsI 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 about 10 yearsPerhaps a little more explanation?
-
cancerbero over 9 yearsthis worked for me, thanks, example: browserify({entries: ['./js/index.js']}).ignore('backbone').ignore('jquery').ignore('underscore')
-
Louis-Rémi over 9 yearsI had trouble verifying noParse actually worked. I ended up adding
console.log(file);
innode_modules/browserify/index.js
'globalTr
function just before thevar 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 over 7 yearsMore example of chart.js that did it here github.com/chartjs/Chart.js/blob/master/gulpfile.js#L105