2016-09-21 54 views
0

我为我的开发服务器使用gulp-connect插件,并且我还安装了gulp-livereload。然后,我做了以下工作:Gulp livereload无法与使用手表的gulp连接配合使用

var gulp = require('gulp'), 
    connect = require('gulp-connect'), 
    livereload = require('gulp-livereload'); 


gulp.task('serve', function() { 
    connect.server({ 
    root: 'app', 
    livereload: true 
    }); 
}); 

gulp.task('css', function() { 
    gulp.src('./app/stylesheets/*.css') 
    .pipe(connect.reload()); 
}); 

gulp.task('html', function() { 
    gulp.src('./app/index.html') 
    .pipe(connect.reload()); 
}); 

gulp.task('watch', function() { 
    gulp.watch('./app/stylesheets/*.css', ['css']); 
    gulp.watch('./app/index.html', ['html']); 
}); 

gulp.task('default', ['serve', 'watch']); 

但每当我运行的服务器,并以样式表或index.html任何改变,我仍然需要手动刷新页面,虽然我已经根据自己的文档做的一切。我也试过写这样的default任务:

gulp.task('default', ['serve', 'html', 'css', 'watch']); 

但它也没有帮助。 livereload有什么问题?

添加:当我检查控制台时,它说它无法连接到ws://localhost:35729/livereload。另外,当我刷新页面时,控制台表示与ws://localhost:35729/livereload的连接中断。这是否意味着livereload无法建立正确的连接?

编辑:虽然我什么都没做,现在livereload自动刷新页面,当我改变我的.css文件。但是当我更改index.html时它仍然不刷新。

回答

0

我非常,非常糟糕 - 我刚才注意到,在我的原代码,我不得不

// ... 
    gulp.watch('./app/html', ['html']); 

,而不是线从上面。只要我修好了,一切正常!