Tim Aych
Tim Aych

Reputation: 1365

Errors when using BrowserSync with Gulp

Gulp is running fine for me until saving a file, when I get an error: "Task 'browsersync.reload' is not in your gulpfile". I'm not sure what I'm doing wrong (I'm following a Gulp tutorial and the source is the same, as far as I can see).

Gulp file:

// Load Node Modules/Plugins
var gulp = require('gulp');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var imagemin = require('gulp-imagemin');
var connect = require('connect');
var serve = require('serve-static');
var browsersync = require('browser-sync');

// Styles task
gulp.task('styles', function(){
    return gulp.src('app/css/*.scss')
        .pipe(sass())
        .pipe(gulp.dest('dist'));
});

gulp.task('scripts', function(){
    return gulp.src('app/js/*.js')
        .pipe(jshint())
        .pipe(jshint.reporter('default'))
        .pipe(concat('all.js'))
        .pipe(uglify())
        .pipe(gulp.dest('dist'));
});

gulp.task('images', function(){
    return gulp.src('app/img/*')
        .pipe(imagemin())
        .pipe(gulp.dest('dist/img'));
});

gulp.task('server', function(){
    return connect().use(serve(__dirname))
            .listen(8080)
            .on('listening', function(){
                console.log('Server Running: View at http://localhost:8080');
            });
});

gulp.task('browsersync', function(cb) {
    return browsersync({
        server: {
            baseDir:'./'
        }
    }, cb);
});

gulp.task('watch', function(){
    gulp.watch('app/css/*.css', ['styles', 'browsersync.reload']);
    gulp.watch('app/js/*.js', ['scripts', 'browsersync.reload']);
    gulp.watch('app/img/*', ['images', 'browsersync.reload']);
});

gulp.task('default', ['styles', 'scripts', 'images', 'server', 'browsersync', 'watch']);

Upvotes: 2

Views: 1853

Answers (2)

Tim Aych
Tim Aych

Reputation: 1365

Solved: The book I'm learning this from is wrong. With help from http://www.browsersync.io/docs/api/ I was able to figure out that 'browsersync.reload' should not have any quotes. Edit:

gulp.task('watch', function(){
    gulp.watch('app/css/*.css', ['styles', browsersync.reload]);
    gulp.watch('app/js/*.js', ['scripts', browsersync.reload]);
    gulp.watch('app/img/*', ['images', browsersync.reload]);
});

Upvotes: 1

Heikki
Heikki

Reputation: 15417

I get an error: "Task 'browsersync.reload' is not in your gulpfile"

Reading the error message should lead you to these lines:

gulp.watch('app/css/*.css', ['styles', 'browsersync.reload']);
gulp.watch('app/js/*.js', ['scripts', 'browsersync.reload']);
gulp.watch('app/img/*', ['images', 'browsersync.reload']);

You are trying to run a task called browsersync.reload which you obviously don't have.

Hint: maybe it's not a task you're supposed to run?

Upvotes: 2

Related Questions