Gulp 观看未连续观看
Gulp Watch Not Watching Continuously
这是我的 Gulp 设置:
var gulp = require('gulp');
// ALLOWS FOR SASS
var sass = require('gulp-sass');
// WATCHES FOR CHANGES
var watch = require('gulp-watch');
// MINIFIES CSS
var cleanCSS = require('gulp-clean-css');
// MERGES CSS FILES INTO ONE
var concat = require('gulp-concat');
// GULP WATCH
gulp.task('watch', function() {
gulp.watch('wp-content/themes/nss/assets/**/*.sass', ['sass']);
});
// GULP SASS CONVERTER
gulp.task('sass', function(){
return gulp.src('wp-content/themes/nss/assets/sass/style.sass')
.pipe(sass()) // Converts Sass to CSS with gulp-sass
.pipe(cleanCSS())
.pipe(concat('style.min.css'))
.pipe(gulp.dest('wp-content/themes/nss/assets/css'));
});
gulp.task('default', ['sass','watch']);
我的问题:
Gulp Watch 只运行一次,不会持续寻找更新。我之前在其他项目中使用过完全相同的代码,所以对我做错了什么感到困惑。
GULP 版本:3.3.4
您的 gulp "watch" 任务中需要一个 return
。
If you do not return a stream, then the asynchronous result of each task will not be awaited by its caller, nor any dependent tasks.
引自this awesome answer here.
对代码稍作修改。
// GULP WATCH
gulp.task('watch', function() {
return gulp.watch('wp-content/themes/nss/assets/**/*.sass', ['sass']);
});
那就行了。
我读到也建议使用 gulp-plumber
作为 it prevents pipe breaking on errors。
这是我的 Gulp 设置:
var gulp = require('gulp');
// ALLOWS FOR SASS
var sass = require('gulp-sass');
// WATCHES FOR CHANGES
var watch = require('gulp-watch');
// MINIFIES CSS
var cleanCSS = require('gulp-clean-css');
// MERGES CSS FILES INTO ONE
var concat = require('gulp-concat');
// GULP WATCH
gulp.task('watch', function() {
gulp.watch('wp-content/themes/nss/assets/**/*.sass', ['sass']);
});
// GULP SASS CONVERTER
gulp.task('sass', function(){
return gulp.src('wp-content/themes/nss/assets/sass/style.sass')
.pipe(sass()) // Converts Sass to CSS with gulp-sass
.pipe(cleanCSS())
.pipe(concat('style.min.css'))
.pipe(gulp.dest('wp-content/themes/nss/assets/css'));
});
gulp.task('default', ['sass','watch']);
我的问题: Gulp Watch 只运行一次,不会持续寻找更新。我之前在其他项目中使用过完全相同的代码,所以对我做错了什么感到困惑。
GULP 版本:3.3.4
您的 gulp "watch" 任务中需要一个 return
。
If you do not return a stream, then the asynchronous result of each task will not be awaited by its caller, nor any dependent tasks.
引自this awesome answer here.
对代码稍作修改。
// GULP WATCH
gulp.task('watch', function() {
return gulp.watch('wp-content/themes/nss/assets/**/*.sass', ['sass']);
});
那就行了。
我读到也建议使用 gulp-plumber
作为 it prevents pipe breaking on errors。