Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ignore module with browserify in gulp

since gulp-browserify module is blacklisted I`ve tried to rewrite my old code in gulpfile.js without gulp-browserify.

I have this worked task with gulp-browserify

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

gulp.task('browserify', function() {
    return gulp.src('./lib/tssoft.commons.js')
        .pipe(browserify({
            ignore: ['jsdom']
        }))
        .pipe(gulp.dest('./dist/'))
});

as you see I tell gulp-browserify to ignore require('jsdom') in browserifying.

After gulp-browserify was uninstalled I instal browserify module and rewrite code

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

gulp.task('browserify', function() {
    var b = browserify();
    b.ignore('jsdom');
    b.add('./lib/tssoft.commons.js');
    return b.bundle()
        .pipe(gulp.dest('./dist/'));
});

And get this error: "Arguments to path.resolve must be strings".

like image 290
k.makarov Avatar asked Apr 10 '15 13:04

k.makarov


2 Answers

Stumpled upon this just a couple days ago, here you go:

var gulp = require('gulp'),
    browserify = require('browserify'),
    source = require('vinyl-source-stream');

gulp.task('browserify', function() {
    var b = browserify();
    b.ignore('jsdom');
    var path = './lib/tssoft.commons.js';
    b.add(path);
    return b.bundle()
        .pipe(source(path))
        .pipe(gulp.dest('./dist/'));
});
like image 94
arrgh Avatar answered Sep 23 '22 14:09

arrgh


The gulp-browerify ignore need a absolute path。 So you just :

var gulp = require('gulp'),
browserify = require('gulp-browserify');
gulp.task('browserify', function() {
    return gulp.src('./lib/tssoft.commons.js')
        .pipe(browserify({
            ignore: [require.resolve('jsdom')]
        }))
        .pipe(gulp.dest('./dist/'))
});

Good luck

like image 39
孙欣乐 Avatar answered Sep 22 '22 14:09

孙欣乐