2015-11-17 11 views
0

如何添加一個.on偵聽器來阻止吞噬,並在下次檢測到文件重新加載時再試一次?如何處理gulp-jspm引發的錯誤?

這就是我目前試圖其中沒有

'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/')); 
}); 

捕獲錯誤或崩潰停止一飲而盡。

回答

0

您可以在這裏查看我的gulpfile.js

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']);