问题描述
我想让 gulp
监视我的工作文件夹上的所有更改,但仅生成一个文件。因为我使用导入所有必需文件的 scss
,所以不需要编译所有的 .css
文件,只有主文件。
现在,我的 gulpfile.js
包含:
var gulp = require('gulp');
var util = require('gulp-util');
var sass = require('gulp-sass');
$ b gulp.task('sass',function(){
return gulp.src('./ sass / style.scss')
.pipe(sass()。 on('error',sass.logError))
.pipe(gulp.dest('./ dist / css'));
});
$ b gulp.task('watch',function(){
gulp.watch('./ sass / ** / *。scss',['sass']);
});
我必须进入 ./ sass / style.scss
并保存到triger gulp手表中。
我希望能够观察所有文件(类似于 ./**/* .scss
),但只显示一个 - ./ sass / style.scss
。如何做到这一点? gulpfile.js
的一部分:
gulp.task ('watch',function(){
gulp.watch('./**/*。scss',['sass']);
});
其中说:监视所有 .scss
'sass' taks 。
'sass'
taks仅编译 ./ sass / style.scss'
I want to make gulp
watch for all changes on my work folders but to generate only one file. Because I use scss
which imports all required files, there is no need to compile all .css
files, only main one.
Now, my gulpfile.js
contains:
var gulp = require('gulp');
var util = require('gulp-util');
var sass = require('gulp-sass');
gulp.task('sass', function () {
return gulp.src('./sass/style.scss')
.pipe(sass().on('error', sass.logError))
.pipe(gulp.dest('./dist/css'));
});
gulp.task('watch', function() {
gulp.watch('./sass/**/*.scss', ['sass']);
});
And I have to go in ./sass/style.scss
and save it to triger gulp watch.
I want gulp to watch all files (something like ./**/*.scss
) but to render only one - ./sass/style.scss
. How to achieve that?
Solution to this is simple, just edit watch
part of the gulpfile.js
to:
gulp.task('watch', function() {
gulp.watch('./**/*.scss', ['sass']);
});
Which says: watch for all .scss
and on change run 'sass'
taks.
'sass'
taks compiles only ./sass/style.scss'
这篇关于Gulp观察所有文件,但只渲染一个(sass)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!