我有一个 gulp 的“默认”任务,我想在 gulp 继续构建我的缩小 CSS 和 JS 之前清理一个文件夹。这个“干净”任务只需要每个默认任务运行一次。但是我在尝试获取默认任务以引用实际构建任务时遇到问题。所以这是我的 gulpfile:
var gulp = require('gulp');
// including our plugins
var clean = require('gulp-clean');
var less = require('gulp-less');
var util = require('gulp-util');
var lsourcemaps = require('gulp-sourcemaps');
var rename = require('gulp-rename');
var filesize = require('gulp-filesize');
var ugly = require('gulp-uglify');
var path = require('path');
var plumber = require('gulp-plumber');
var minifyCSS = require('gulp-minify-css');
var concat = require('gulp-concat');
// DEFAULT TASK
gulp.task('default', ['clean'], function() {
.pipe(gulp.task('vendor'))
.pipe(gulp.task('css'))
});
// strips public folder for a build operation nice and clean ** obliterates! **
gulp.task('clean', function() {
return gulp.src('public/**', {read: false})
.pipe(clean());
});
// javascript vendor builds
gulp.task('vendor', function() {
return gulp.src(['bower_comps/angular/angular.js', 'bower_comps/angular-bootstrap/ui-bootstrap.js', 'bower_comps/angular-bootstrap/ui-bootstrap-tpls.js'])
//.pipe(filesize())
.pipe(ugly())
.pipe(concat('vendor.min.js'))
.pipe(gulp.dest('public/js'))
});
// builds CSS
gulp.task('css', function() {
return gulp.src('bower_comps/bootstrap-less/less/bootstrap.less')
.pipe(lsourcemaps.init())
.pipe(plumber({
errorHandler: function(err) {
console.log(err);
this.emit('end')
}
}))
.pipe(less({
paths: [path.join(__dirname, 'less', 'includes')]
}))
.pipe(minifyCSS())
.pipe(rename('site.min.css'))
.pipe(lsourcemaps.write('./maps'))
.pipe(gulp.dest('public/css/'))
.pipe(filesize())
});
那么我该怎么办呢?每个单独的任务都将独立运行,“gulp css”,“gulp vendor”。就在我将它们放入默认任务(主任务)中时,我遇到了问题。
托尼