A
A
Andrey Dyrkov2016-07-12 17:00:44
gulp.js
Andrey Dyrkov, 2016-07-12 17:00:44

How to hang an error handler?

I have a task

// #javascript
gulp.task('js', function () {

  return browserify({
      entries:path.src.js,
      extensions:['.jsx']
    })
    .transform('babelify',{
       presets:['es2015','react'],
       plugins:['transform-class-properties']
     })
    .bundle()
    .on('error',function(err){
      console.log(err);
    })

    .pipe(source('app.min.js'))
    .pipe(buffer())


    .pipe(_if(isDev,sourcemaps.init()))
    // .pipe(jsMin())
    .pipe(_if(isDev,sourcemaps.write()))

    .pipe(gulp.dest(path.dist.js))
    .pipe(_debug({title:'js to Dist'}))
    .pipe(_reload({stream: true}));
});

We need not a normal handler, but from notify. Something like this
.pipe(_plumber({
        errorHandler: _log.onError(function(err){
            return {
              title:'JAVASCRIPT',
              message:err.message
            };
          })
      }))

If you put it after buffer, then nothing happens, it doesn’t catch, the js task just hangs.
For the purity of the experiment
var gulp        = require('gulp'),
    babel       = require('gulp-babel'),

    browserify  = require('browserify'),
    babelify    = require('babelify'),
    buffer      = require('vinyl-buffer'),
    source      = require('vinyl-source-stream'),

    jsMin       = require('gulp-uglify'),
    rename      = require('gulp-rename'),
    sass        = require('gulp-sass'),
    cssMin      = require('gulp-minify-css'),
    cssPrefixer = require('gulp-autoprefixer'),
    watch       = require('gulp-watch'),
    sourcemaps  = require('gulp-sourcemaps'),
    _if         = require('gulp-if'),
    _debug      = require('gulp-debug'),
    _log        = require('gulp-notify'),
    _plumber    = require('gulp-plumber'),
    _delete     = require('rimraf'),
    _server     = require('browser-sync'),
    _reload     = _server.reload;

How to do? :)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question