简体   繁体   English

Gulp-sass和浏览器同步不会重新加载浏览器

[英]Gulp-sass and browser-sync don't reload browser

When I change some scss file everything seems to work (scss is compiled to css file and the source files are watched): 当我更改一些scss文件时,一切似乎都有效(scss被编译为css文件并且监视源文件):

[21:19:46] Starting 'sass'...
[BS] 1 file changed (principal.css)
[21:19:46] Finished 'sass' after 18 ms

But I need to reload the browser by hand to reflect the changes. 但我需要手动重新加载浏览器以反映更改。 This is my gulpfile: 这是我的gulpfile:

var gulp        = require('gulp');
var browserSync = require('browser-sync').create();
var sass        = require('gulp-sass');

// Static Server + watching scss/html files
gulp.task('default', ['sass'], function() {

    browserSync.init({
        proxy: "huertajalon/"
    });

    gulp.watch("./sass/**/*.scss", ['sass']);
    gulp.watch("./*.php").on('change', browserSync.reload);
    gulp.watch("./style.css").on('change', browserSync.reload);

});

// Compile sass into CSS & auto-inject into browsers
gulp.task('sass', function() {
    return gulp.src("sass/principal.scss")
        .pipe(sass())
        .pipe(gulp.dest("./css"))
        .pipe(browserSync.stream());
});

In other cases (for example, when I modify and save style.css) the browser reloads well. 在其他情况下(例如,当我修改并保存style.css时)浏览器重新加载。

What am I doing wrong? 我究竟做错了什么? Thanks! 谢谢!

Try something like this. 尝试这样的事情。

gulp.task(default, ['sass'], browserSync.reload);

Also refer to http://www.browsersync.io/docs/gulp/#gulp-reload 另请参阅http://www.browsersync.io/docs/gulp/#gulp-reload

Are you using browser-sync version 2.6.0 or higher, since this is required to use browserSync.stream() . 您使用的是浏览器同步版本2.6.0或更高版本,因为这需要使用browserSync.stream() http://www.browsersync.io/docs/api/#api-stream http://www.browsersync.io/docs/api/#api-stream

If not then you should update or you could try browserSync.reload({stream: true}) instead, which was the previous way to handle streams with browser-sync. 如果没有,那么您应该更新,或者您可以尝试使用browserSync.reload({stream: true}) ,这是以前使用浏览器同步处理流的方法。 If I remember correctly. 如果我没记错的话。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM