Search code examples
javascriptsvgreplacegulpadobe-illustrator

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?


Solution

  • 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'));
    });