gulp-data icon indicating copy to clipboard operation
gulp-data copied to clipboard

A way to ignore if file doesnt exist

Open DusanMilko opened this issue 9 years ago • 1 comments

I want to try to load the json file and if it doesnt exists just ignore and keep going.

Advice?

DusanMilko avatar Mar 20 '15 21:03 DusanMilko

Try this...

gulp.task('json-test', function() {
  return gulp.src('./examples/test1.html')
    .pipe(data(function(file) {
      var path = './examples/' + path.basename(file.path) + '.json';
      return (fs.existsSync(path)) ? require(path) : {};
    }))
    .pipe(swig())
    .pipe(gulp.dest('build'));
});

colynb avatar Mar 29 '15 15:03 colynb