Gulp-[task] .pipe()不是函数

时间:2019-07-15 15:51:03

标签: node.js npm stream gulp

我有以下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

我在这里做错了什么?

1 个答案:

答案 0 :(得分:2)

true返回Promise而不是流,请参见del docs,并且pipe()不是Promise的函数。只需在del()中调用clean函数即可。 [下面的代码未经测试]

series