I am writing a gulp task to browserify, compile my less files into css and to run a gulp-webserver. On Client side I am using React 0.14. The moment any error is found in browserify, my gulp watch crashes. Every time I have to stop the watch task and run it again. How to avoid this? I mean if an error is found and if i fix the error, how can i again run the browserify task without my watch getting crashed. If I get an error in browserify like: the closing JSX tag missing...and Once I fix the error, how to stop my watch from crashing.
var gulp = require('gulp');
var browserify = require('browserify');
var babelify = require("babelify");
var source = require('vinyl-source-stream');
var plugins = require('gulp-load-plugins')();
var runSequence = require('run-sequence');
var watchLess = require('gulp-watch-less');
var domain = require("domain");
gulp.task('webserver', function(){
gulp.src('./')
.pipe(plugins.webserver({
fallback : 'index.html',
host : 'localhost',
livereload : {
enable : true
},
open : true
}))
})
gulp.task('browserify', function(){
console.log('Browserifying ...');
return browserify({
entries : ['./js/index.js'],
debug : true
})
.transform('babelify', {presets: ['es2015', 'react']})
.bundle()
.on('error', function(err) {
console.log('Error:', err);
})
.pipe(source('bundle.js'))
.pipe(gulp.dest('./'))
})
gulp.task('build-css', function(){
return gulp.src('./less/**/*.less')
.pipe(plugins.less())
.pipe(gulp.dest('./css'))
})
gulp.task('build', function() {
runSequence(
['build-css'], ['browserify'], ['webserver'], ['watch']
);
});
gulp.task('watch', function(){
gulp.watch('./js/*.js',['browserify'])
gulp.watch('./less/**/*.less',['build-css'])
gulp.watch('./css/**/*.css')
})
将此添加到您的错误处理方法中:
this.emit('end')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.