0

I'm trying to create a Gulp task that replaces spaces from filename with underscores. Here's what I have:

gulp.task("underscore", function (done) {
  gulp.src("src/**/*.{jpg,jpeg}")
    .pipe(changed("dist"))

    //Remove Space
    .pipe(rename(function(opt) {
      opt.basename = opt.basename.replace(/ /, '_');
      return opt;
    }))

    //Copy to destination
    .pipe(gulp.dest("dest"));
    done();
});

It doesn't seem to reliably remove spaces. Is there something I'm missing? It seems to work about 99% of the time, which is good, but not really acceptable with the number of images I'm processing.

1 Answers1

0

you can use this .split(' ').join('_') instead of .replace(/ /, '_')

Anas Omar
  • 504
  • 3
  • 8