【发布时间】:2016-09-21 13:33:57
【问题描述】:
我正在为我的开发服务器使用gulp-connect 插件,并且我已经安装了gulp-livereload。然后我做了以下任务:
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时它仍然没有刷新。
【问题讨论】:
标签: gulp gulp-watch livereload