bak202
bak202

Reputation: 277

Browserify does not resolve external file

I'm trying to use browserify inside gulp. The Gulpfile.js contains the simple task:

gulp.task('browserify', function () {
var x = browserify('./src/main/js/init.js');
return x.bundle({
    ignoreMissing: true
})
    .pipe(source('init.js'))
    .pipe(gulp.dest('./dist/js/'));

});

Where init.js is:

require("d3");

I'm trying to use the alias "d3" which is an external dependency which browserify should not try to resolve. Running this causes browserify to hang, despite it saying the task has. How is the best way to go about this? Using browserify 4.2.0.

PS: Have also tried to use the external option

EDIT: running it from the command line

browserify src/main/js/init.js  --ignore-missing

Seems to work

Upvotes: 0

Views: 413

Answers (2)

JMM
JMM

Reputation: 26787

See if this works:

gulp.task('browserify', function () {
  return browserify('./src/main/js/init.js')
    .exclude('d3')
    .bundle()
    .pipe(source('init.js'))
    .pipe(gulp.dest('./dist/js/'));
});

Upvotes: 2

Mathieu Bertin
Mathieu Bertin

Reputation: 1624

You should use gulp.src on the entry file I use this and it works

var gulp = require('gulp'),
rename = require('gulp-rename'),
browserify = require('gulp-browserify');

gulp.task('browserify', function () {

   return gulp.src('./src/main/js/init.js')
        .pipe(browserify({ //browserify options
            debug: true
        }))
        .pipe(rename('initBuild.js'))
        .pipe(gulp.dest('./dist/js/'));
}

Edit

Obviously it's deprecated. Try to use object options on the browserify constructor.

var x = browserify({
    entries: './src/main/js/init.js',
    ignoreMissing: true
});

return x.bundle()
    .pipe(source('init.js'))
    .pipe(gulp.dest('./dist/js/'));

Upvotes: 0

Related Questions