使用node.js和gulp时无法使用livereload工作

我的大文件如下:

var gulp = require('gulp'), connect = require('gulp-connect'), sass = require('gulp-ruby-sass'), autoprefixer = require('gulp-autoprefixer'), minifycss = require('gulp-minify-css'), jshint = require('gulp-jshint'), uglify = require('gulp-uglify'), imagemin = require('gulp-imagemin'), rename = require('gulp-rename'), clean = require('gulp-clean'), concat = require('gulp-concat'), notify = require('gulp-notify'), cache = require('gulp-cache'), livereload = require('gulp-livereload'); gulp.task('styles', function() { return gulp.src('main.scss') .pipe(autoprefixer('last 2 version', 'safari 5', 'ie 8', 'ie 9', 'opera 12.$ .pipe(gulp.dest('css')) .pipe(rename({suffix: '.min'})) .pipe(minifycss()) .pipe(gulp.dest('css')); }); gulp.task('default', function() { gulp.start('styles'); gulp.start('server'); gulp.start('watch'); }); gulp.task('server', function() { connect.server({ livereload:true }); }); gulp.task('indexChange',function(){ console.log('index has changed'); connect.reload(); } ); gulp.task('watch', function() { gulp.watch('index.html', ['indexChange']); }); 

当我改变我的index.html文件的'indexChange'任务运行和控制台输出'索引已经改变',但是connect.reload()什么都不做。

我已经检查了肝载入端口和连接服务器端口,所以我知道两者都在运行。 但我无法弄清楚我错过了什么代码让livereload工作。

我究竟做错了什么?

您需要将pipe道返回到connect.reload(); 为了工作,试试这个:

 // add gulp-watch var watch = require('gulp-watch'); gulp.task('indexChange',function(){ console.log('index has changed'); } ); gulp.task('watch', function() { watch({glob: './index.html'}, ['indexChange']).pipe(connect.reload()); });