Gulp write file if none exist -
how can make gulp write file if there no existing file.
the bellow solution works gulp 4.0 in alpha.
// when gulp 4.0 releases .pipe(gulp.dest(conf.plugscss.dist, {overwrite: false}))
there no exact equivalent in gulp 3.x, can use gulp-changed
achieve same thing.
gulp-changed
used write files have changed since last time written destination folder. can provide custom haschanged
function. in case can write function nothing check if file exists using fs.stat()
:
var gulp = require('gulp'); var changed = require('gulp-changed'); var fs = require('fs'); function compareexistence(stream, cb, sourcefile, targetpath) { fs.stat(targetpath, function(err, stats) { if (err) { stream.push(sourcefile); } cb(); }); } gulp.task('default', function() { return gulp.src(/*...*/) .pipe(changed(conf.plugscss.dist, {haschanged: compareexistence})) .pipe(gulp.dest(conf.plugscss.dist)); });
Comments
Post a Comment