我有以下gulpfile.js。 new_version
任务在源代码中创建一个新版本目录。
const { src, dest } = require('gulp');
const fs = require('fs');
const minify = require('gulp-minify');
const del = require('del');
var PACKAGE = require('./package.json');
var version = PACKAGE.version;
var itb_version = PACKAGE.itb_version;
var name = PACKAGE.name;
var distPath = "./dist/" + version + "/js";
function clean() {
return del('dist/**', {force:true});
}
function new_version() {
return clean()
.pipe(function() {
if(!fs.existsSync(itb_version)) {
fs.mkdirSync(itb_version);
}
});
}
function build() {
return src('./src/myfile.js')
.pipe(minify({
ext:{
min:'.min.js'
}
}))
.pipe(dest(distPath));
}
exports.clean = clean;
exports.new_version = new_version;
exports.build = build;
运行gulp new_version
时出现以下错误:
[10:44:50] Using gulpfile ~/projects/myproject/gulpfile.js
[10:44:50] Starting 'new_version'...
[10:44:50] 'new_version' errored after 3.14 ms
[10:44:50] TypeError: clean(...).pipe is not a function
我在这里做错了什么?
答案 0 :(得分:2)
true
返回Promise而不是流,请参见del docs,并且pipe()不是Promise的函数。只需在del()
中调用clean
函数即可。 [下面的代码未经测试]
series