user2186701
user2186701

Reputation: 31

Gulp BrowserSync crashing

I am running Gulp 3.9.1 with BrowserSync 2.12.3. Everything works fine but after a while BrowserSync stops working and I need to restart it. Here is gulpfile

var gulp = require('gulp');

var sass = require('gulp-sass');
var browserSync = require('browser-sync').create();

gulp.task('sass', function(){
    return gulp.src('app/scss/style.scss')
    .pipe(sass())
    .pipe(gulp.dest('app/css'))
    .pipe(browserSync.reload({
         stream: true
     }));
});

gulp.task('watch', ['browserSync', 'sass'], function (){
    gulp.watch('app/scss/**/*.scss', ['sass']);
    // Reloads the browser whenever HTML or JS files change
    gulp.watch('app/*.html', browserSync.reload());
    gulp.watch('app/js/**/*.js', browserSync.reload());
});

gulp.task('browserSync', function(){
    browserSync.init({
        server: {
            baseDir: 'app'
        }
    });
});

Thanks.

Upvotes: 0

Views: 533

Answers (1)

Lev K.
Lev K.

Reputation: 402

May be you have some error in your sass file. Try to add this line for to skip an error.

Please replace this line :

 .pipe(sass())

with this line :

.pipe(sass().on('error', showError)) 

and add this handler function:

function showError(error) {
console.log(error.toString());
this.emit('end');}

Upvotes: 1

Related Questions