Gulp 监视所有文件,但只渲染一个(sass) [英] Gulp watch all files but render only one (sass)
问题描述
我想让 gulp
监视我的工作文件夹上的所有更改,但只生成一个文件.因为我使用 scss
导入所有需要的文件,所以不需要编译所有 .css
文件,只需要编译 main 一个.
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.
现在,我的 gulpfile.js
包含:
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']);
});
我必须进入 ./sass/style.scss
并将其保存到触发 gulp watch.
And I have to go in ./sass/style.scss
and save it to triger gulp watch.
我希望 gulp 观看所有文件(类似于 ./**/*.scss
)但只渲染一个 - ./sass/style.scss
.如何实现?
I want gulp to watch all files (something like ./**/*.scss
) but to render only one - ./sass/style.scss
. How to achieve that?
推荐答案
解决方案很简单,只需将 gulpfile.js
的 watch
部分编辑为:p>
Solution to this is simple, just edit watch
part of the gulpfile.js
to:
gulp.task('watch', function() {
gulp.watch('./**/*.scss', ['sass']);
});
其中说:注意所有 .scss
并在更改时运行 'sass'
taks.
Which says: watch for all .scss
and on change run 'sass'
taks.
'sass'
taks 只编译 ./sass/style.scss'
这篇关于Gulp 监视所有文件,但只渲染一个(sass)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!