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 更改)
				
        
 
            
        基础教程推荐
- Javascript 在多个元素上单击事件侦听器并获取目标 2022-01-01
 - 什么是不使用 jQuery 的经验技术原因? 2022-01-01
 - 为什么我在 Vue.js 中得到 ERR_CONNECTION_TIMED_OUT? 2022-01-01
 - WatchKit 支持 html 吗?有没有像 UIWebview 这样的控制器? 2022-01-01
 - 每次设置弹出窗口的焦点 2022-01-01
 - 如何在特定日期之前获取消息? 2022-01-01
 - Node.js 有没有好的索引/搜索引擎? 2022-01-01
 - jQuery File Upload - 如何识别所有文件何时上传 2022-01-01
 - 如何使用 CSS 显示和隐藏 div? 2022-01-01
 - 如何使用sencha Touch2在单页中显示列表和其他标签 2022-01-01
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				