最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Ignore module with browserify in gulp - Stack Overflow

programmeradmin4浏览0评论

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/tssoftmons.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/tssoftmons.js');
    return b.bundle()
        .pipe(gulp.dest('./dist/'));
});

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

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.mons.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.mons.js');
    return b.bundle()
        .pipe(gulp.dest('./dist/'));
});

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

Share Improve this question asked Apr 10, 2015 at 13:05 k.makarovk.makarov 8541 gold badge12 silver badges30 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 8

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.mons.js';
    b.add(path);
    return b.bundle()
        .pipe(source(path))
        .pipe(gulp.dest('./dist/'));
});

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.mons.js')
        .pipe(browserify({
            ignore: [require.resolve('jsdom')]
        }))
        .pipe(gulp.dest('./dist/'))
});

Good luck

发布评论

评论列表(0)

  1. 暂无评论