【问题标题】:Gulp livereload doesn't work with gulp-connect using watchGulp livereload 不适用于使用 watch 的 gulp-connect
【发布时间】: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


    【解决方案1】:

    我非常非常糟糕——我刚刚注意到,在我的原始代码中,我有

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

    而不是上面的线。我修好后,一切正常!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-07-12
      • 2016-12-24
      • 2017-12-01
      • 1970-01-01
      • 2016-06-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多