gulp: how to update the browser without refresh (for css changes only)(gulp:如何在不刷新的情况下更新浏览器(仅适用于 css 更改))
问题描述
我已设置 gulp,以便在我进行更改时重新加载浏览器.但是,对于 css 更改,我希望浏览器在不刷新的情况下更新,但我不确定如何执行此操作.对于我当前的设置,我使用了 this 教程:
I've setup gulp such that the browser reloads when I make changes. However, for css changes I want the browser to update without refresh, but I'm not sure how to do this. For my current setup I've used this tutorial:
var debug = require('gulp-debug'),
    connect = require('gulp-connect'),
    watch = require('gulp-watch'),
    livereload = require('gulp-livereload');
gulp.task('webserver', function () {
    connect.server({
        livereload: true,
        root: ['demo/']
    });
});
gulp.task('livereload', function () {
    gulp.src(['index.html', 'resources/**/*.js'])
        .pipe(watch(['resources/**/*.html', 'index.html']))
        //.pipe(debug({verbose: true}))
        .pipe(connect.reload());
});
gulp.task('watch', function () {
    livereload.listen();
    gulp.watch('resources/**/*.scss', ['css']);
});
在我的 css 任务中,我也调用了
In my css task I also call
.pipe(livereload());
有什么建议我需要修改以便 css 更新无需刷新即可发生吗?
Any suggestions what I need to modify so css updates happen without a refresh ?
更新:这是我的 css 任务(有点简化):
UPDATE: Here is my css task (a bit simplified):
gulp.task('css', function () {
    ...
    return gulp.src('demo.scss')
        .pipe($.sass({
            errLogToConsole: true
        }))
        .pipe(gulp.dest('./target/')
        .pipe(livereload());
});
推荐答案
发生变化时需要调用livereload.changed(files).为此,请参阅 gulp-watch文档.
You need to call livereload.changed(files) when change happens. To do that see gulp-watch doc.
watch('**/*.js', function (files) {
  livereload.changed(files)
});
                        这篇关于gulp:如何在不刷新的情况下更新浏览器(仅适用于 css 更改)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:gulp:如何在不刷新的情况下更新浏览器(仅适用于 css 更改)
				
        
 
            
        - Fetch API 如何获取响应体? 2022-01-01
 - CSS媒体查询(最大高度)不起作用,但为什么? 2022-01-01
 - Quasar 2+Apollo:错误:找不到ID为默认的Apollo客户端。如果您在组件设置之外,请使用ProvideApolloClient() 2022-01-01
 - 使用RSelum从网站(报纸档案)中抓取多个网页 2022-09-06
 - 400或500级别的HTTP响应 2022-01-01
 - 如何使用 JSON 格式的 jQuery AJAX 从 .cfm 页面输出查 2022-01-01
 - addEventListener 在 IE 11 中不起作用 2022-01-01
 - 失败的 Canvas 360 jquery 插件 2022-01-01
 - Flexslider 箭头未正确显示 2022-01-01
 - Css:将嵌套元素定位在父元素边界之外一点 2022-09-07
 
						
						
						
						
						