livereload(浏览器同步)只工作一次

时间:2016-10-04 16:12:01

标签: node.js web sass gulp browser-sync

问题在于我什么时候开始

  gulp watch

并更改sass文件,页面正在重新加载并只构建一次项目。然后它停止任务sass,如果我想更改其他sass文件 - 没有发生任何事情(见下面的日志)。我怎么能解决它?

gulp.task('sass', wrapPipe(function(success, error) {
     return gulp.src('app/css/scss/style.scss')
         .pipe(sass({
             includePaths: [
                 './bower_components/foundation-sites/scss'
             ]
         }).on('error', error))
         .pipe(gulp.dest('app/css'))
         .pipe(browserSync.reload({
             stream: true
         }));

    }));

    gulp.task('livereload', function () {
        browserSync.init({
            server: "./app",
            notify: false
        });
    });

    gulp.task('watch', ['livereload'], function(){
        gulp.watch('app/css/scss/**/*.scss', ['sass']);
    });

这是日志:

[18:52:39] Starting 'livereload'...
[18:52:39] Finished 'livereload' after 20 ms
[18:52:39] Starting 'watch'...
[BS] Reloading Browsers...
[18:52:39] Finished 'watch' after 33 ms
[BS] Access URLs:
 -------------------------------------
       Local: http://localhost:3000
    External: http://192.168.0.95:3000
 -------------------------------------
          UI: http://localhost:3001
 UI External: http://192.168.0.95:3001
 -------------------------------------
[BS] Serving files from: ./app
[18:52:50] Starting 'sass'...
[BS] 1 file changed (style.css)

1 个答案:

答案 0 :(得分:0)

我不确定除了检测后续修改的.scss文件之外还想要什么行为。为此,如果添加回报会发生什么:

gulp.task('watch', ['livereload'], function(){
    return gulp.watch('app/css/scss/**/*.scss', ['sass']);
});