Gulp watch all files but render only one (sass)

最后都变了- 提交于 2019-12-01 17:31:07

问题


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?


回答1:


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'



来源:https://stackoverflow.com/questions/32160997/gulp-watch-all-files-but-render-only-one-sass

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!