[英]Configuring Gulp to reflect css changes
I'm using for the first time gulp
with ASP.net Core
, I'm trying to configure it so when my css
files are modified those changes can be reflected automatically in my browser(Chrome) without refreshing the page with F5
. 我使用的第一次
gulp
与ASP.net Core
,我想配置它,所以当我的css
文件被修改这些变化可以自动在我的浏览器(Chrome)中反映出来而不刷新页面F5
。 I've tried first to minify the .js files and that is working, but with livereload I must be doing something wrong because the changes are not being captured automatically and I have to press F5 in my browser. 我首先尝试缩小.js文件的大小,并且可以正常工作,但是使用livereload时,我必须做错了什么,因为更改不会被自动捕获,因此必须在浏览器中按F5键。 I have installed already the Chrome plugin
LiveReload
This is my code inside the gulpfile.js
: 我已经安装了Chrome插件
LiveReload
这是我在gulpfile.js
代码:
/// <binding AfterBuild='default' />
//to minify js and css
var gulp = require("gulp");
var uglify = require("gulp-uglify");
var livereload = require("gulp-livereload");
gulp.task("default", function () {
return gulp.src("wwwroot/js/*.js")
.pipe(uglify())
.pipe(gulp.dest("wwwroot/lib/_app"))
});
gulp.task("watch", function () {
livereload.listen();
gulp.watch("wwwroot/css/*.css");
});
And this is an image of the Task Runner
in Visual Studio: 这是Visual Studio中的
Task Runner
器的图像:
I don't like that Process terminated with code 0.
within the Task Runner
console, what do I need to do? 我不喜欢该
Process terminated with code 0.
在Task Runner
控制台中,该怎么办?
You can use browser-sync and create a watcher to watch your css changes and reload the page everytime anything in your css file is changed. 您可以使用浏览器同步并创建一个监视程序来监视css的更改,并在css文件中的任何内容每次更改时重新加载页面。
var browserSync = require('browser-sync');
gulp.task('css', function(){
gulp.src('css/*.css')
.pipe(reload({stream: true}));
})
gulp.task('browser-sync', function(){
browserSync({
server:{
baseDir: ""
}
});
});
gulp.task('watch', function(){
gulp.watch(['css/*.css'], ['css']);
});
gulp.task('default',['css','browser-sync','watch']); //default task to run different tasks
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.