0

How would one add a .on listener that would stop gulp from crashing and simply try again next time it detects a file reload?

This is what I have tried currently

'use strict';

const gulp = require('gulp');
const jspm = require('gulp-jspm');

gulp.task('default', () => {
  return gulp.watch('./src/**/*.js', ['bundle'])
    .on('error', function (error) {
      console.log('error');
      this.emit('end');
    });
});

gulp.task('bundle', () => {
  return gulp.src('./src/main.js')
    .pipe(jspm({ selfExecutingBundle : true })
      .on('error', function (error) {
        console.log('error');
        this.emit('end');
      })
    )
    .on('error', function (error) {
      console.log('error');
      this.emit('end');
    })
    .pipe(gulp.dest('./dist/'));
});

None of which captures the error, or stops gulp from crashing.

Edward-Lombe
  • 57
  • 1
  • 4

1 Answers1

0

You can check my gulpfile.js here.

const gulp = require('gulp');
const gulp_jspm = require('gulp-jspm');

const paths = {
    //Your main.js
    main: 'public/js/main.js',
    //Your all js files
    scripts: 'public/js/**',
    dest: 'public/dest/'
};

gulp.task('scripts', () => {
    gulp.src(paths.main)
      .pipe(gulp_jspm({
          selfExecutingBundle: true
      }))
      .pipe(gulp.dest(paths.dest));
});

function reportChange(event){  
    console.log('File ' + event.path + ' was ' + event.type + ', running tasks...');
}

gulp.task('watch', () => {
    gulp.watch([paths.scripts], ['scripts']).on('change', reportChange);
});

gulp.task('default', ['watch', 'scripts']);
Joey
  • 446
  • 6
  • 11