0

I'm relatively new to Gulp and looking to create a task that would clone a file, move it to a directory, then find and replace the following (keep note that the number of spaces proceeding the default! is different)

$primary-color: #000         !default;
$secondary-color: #000                         !default;
$trinary-color: #000   !default;

After the Gulp taks, would look like this, keeping the semicolon:

$primary-color: #000;
$secondary-color: #000;
$trinary-color: #000;

Guessing I'll need to use Gulp replace, doing the following:

gulp.task('variables', function() {
  return gulp.src('src/scss/frontend/global/_variables.scss')
             .pipe(replace(REGEX_HERE, ''))
             .pipe(gulp.dest('src/scss/application/global/_variables.scss'));
});

but don't know the regex I'll need to remove both !default and the preceeding spaces.

Ben Marshall
  • 1,724
  • 2
  • 17
  • 33

1 Answers1

1

Using gulp-replace and the regex /\s*!default/g you can do it like this:

gulp.task('variables', function() {
  return gulp.src('src/scss/frontend/global/_variables.scss')
    .pipe(replace(/\s*!default/g, ''))
    .pipe(gulp.dest('src/scss/application/global/'));
});
Sven Schoenung
  • 30,224
  • 8
  • 65
  • 70