我尝试使用gulp-pump
和gulp-run-sequence
,但是遇到了关于task completion callback called too many times
的错误。
以下是我的Gulpfile:
var gulp = require('gulp');
var sass = require('gulp-sass');
var uglify = require('gulp-uglify');
var autoprefixer = require('gulp-autoprefixer');
var cleanCSS = require('gulp-clean-css');
var rename = require('gulp-rename');
var runSequence = require('run-sequence');
var pump = require('pump');
var pumpCb = function (err) {
if (err) {
console.log('Error: ', err.toString());
}
};
// Local
gulp.task('local-sass', function (pumpCb) {
return pump([
gulp.src('public/assets/src/sass/**/*.scss'),
sass(),
autoprefixer(),
gulp.dest('public/assets/dist/css/')
],
pumpCb
);
});
gulp.task('local-js', function (pumpCb) {
return pump([
gulp.src('public/assets/src/js/**/*.js'),
uglify(),
gulp.dest('public/assets/dist/js/')
],
pumpCb
);
});
// Production
gulp.task('prod-sass', function (pumpCb) {
return pump([
gulp.src('public/assets/src/sass/**/*.scss'),
sass({outputStyle:'compact'}),
autoprefixer(),
gulp.dest('public/assets/dist/css/')
],
pumpCb
);
});
gulp.task('prod-css', function (pumpCb) {
return pump([
gulp.src(['./public/assets/dist/css/**/*.css','!./public/assets/dist/css/**/*.min*']),
cleanCSS(),
rename({ suffix: '.min' }),
gulp.dest('public/assets/dist/css/')
],
pumpCb
);
});
gulp.task('prod-js', function (pumpCb) {
return pump([
gulp.src('public/assets/src/js/**/*.js'),
uglify(),
rename({ suffix: '.min' }),
gulp.dest('public/assets/dist/js')
],
pumpCb
);
});
// Calls
gulp.task('default', function () {
gulp.watch('public/assets/src/sass/**/*.scss',['local-sass']);
gulp.watch('public/assets/src/js/**/*.js',['local-js']);
});
gulp.task('prod', function () {
runSequence('prod-sass','prod-css','prod-js');
});
从run-sequence
和pump
的文档中我无法看到我做错了什么,所以也许这对Gulp有更广泛的误解?
我已经阅读了大部分关于同一错误的答案,但我不认为它们适用于这个特定情况,我也不知道如何将他们的发现推断到我自己的Gulpfile上。
任何帮助将不胜感激!
答案 0 :(得分:1)
我的gulp任务中也出现了这个错误。这是因为你有一个return
语句而你正在调用任务回调pumpCb
。删除return
语句。