yellow-saint
yellow-saint

Reputation: 934

GulpJS: Perform string functions on SVG file contents

I have an illustrator file I'm regularly updating, that's then processed and distributed to /public/ though a Gulp task.

However, Illustrator appends _[0-9]+_ to some key tag IDs, and I want to perform something like .pipe(thisSVGFile.contents().replace('/_[0-9]+_/',"")) whenever Gulp Watch comes across a change.

How can I achieve this without producing my own Gulp plugin?

Upvotes: 0

Views: 130

Answers (1)

Preview
Preview

Reputation: 35806

gulp-replace supports regular expressions.

var replace = require('gulp-replace');

gulp.task('replace', function () {
  return gulp.src('./public/file.svg')
    .pipe(replace(/_[0-9]+_/g, ''))
    .pipe(gulp.dest('public'));
});

Upvotes: 1

Related Questions