简体   繁体   中英

Gulp - [task].pipe() is not a function

I have the following gulpfile.js. The new_version task creates a new version directory in the source code.

    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;

When I run gulp new_version I get the following error:

  [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

What am I doing wrong here?

del() returns a Promise not a stream, see del docs and pipe() is not a function of a Promise. Just call your clean function as part of a series . [code below not tested]

const { src, dest, series } = require('gulp');
...
exports.new_version = gulp.series(clean, new_version);

function new_version() {
   if(!fs.existsSync(itb_version)) {
        fs.mkdirSync(itb_version);  
   }  
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM