如何避免gulpfile.js上重复的.pipe()

时间:2016-10-21 10:49:48

标签: javascript node.js gulp dry

在我的gulpfile.js上,我有一些共同点.pipes()的任务。现在我将它们复制/粘贴到我需要的地方,但理想情况下我想避免_ WET - 写两次所有内容。

一个例子:

gulp.task('scripts', function(){
    console.log('start task scripts');
    gulp.src([
            folderScripts+'/**/*.js',
            '!'+folderScripts+'/**/_*.js',
            '!'+folderScripts+'/**/*.min.js'
        ])

        // some .pipes() here

        // --- FIXME Find a way to not duplicate this
        .pipe(include())
            .on('error', console.log)
        .pipe(gulpif(argv.production, stripDebug()))
        .pipe(rename({ suffix: '.min' }))
        // --- END FIXME Find a way to not duplicate this

        //more .pipes()

        .pipe(gulp.dest('exported'));
    logEnv();
});


gulp.task('min-this', function(){
    // some code

   if (argv.js || argv.jsfolder) {

     gulp.src([
        argv.js ? argv.js
        : argv.jsfolder+'/**/*.js',
        '!'+argv.jsfolder+'/**/_*.js',
        '!'+argv.jsfolder+'/**/*.min.js'
        ])

        // some .pipes() here 

        // --- FIXME Find a way to not duplicate this
         .pipe(include())
            .on('error', console.log)
        .pipe(gulpif(argv.production, stripDebug()))
        .pipe(rename({ suffix: '.min' }))
        // --- END FIXME Find a way to not duplicate this

        //more .pipes()

        .pipe(gulp.dest( function(file) { return file.base; } ));
   }
});

我怎么能不复制块// --- FIXME Find a way to not duplicate this内的内容?

由于

0 个答案:

没有答案