Replace string in a single file using gulp

2k views Asked by At

I’m using a single task to generate css files from sass plus strip comments, create a source map and minify. I'm trying to replace a string in theme.components-md.scss file.

Here’s my attempt:

var gulp = require('gulp'),
    sass = require('gulp-ruby-sass'),
    sourceMaps = require('gulp-sourcemaps'),
    minifyCss = require('gulp-minify-css'),
    replace = require('gulp-replace'),
    filter = require('gulp-filter');

gulp.task('vendor:css', function() {
    var themeComponentsFilter = filter('theme.components-md.scss');
    return sass('resources/assets/sass/')
        .pipe(stripComments({
            safe: false
        }))
        .pipe(themeComponentsFilter)
        .pipe(replace(/..\/img\//g, '../../img/vendor/'))
        .pipe(themeComponentsFilter.restore())
        .pipe(sourceMaps.init())
        .pipe(minifyCss())
        .pipe(sourceMaps.write('/', {
            sourceMappingURLPrefix: 'http://core.dev/css/vendor'
        }))
        .pipe(gulp.dest('public/css/vendor'));
});

But it's not working.

1

There are 1 answers

0
AlGallaf On BEST ANSWER

Instead of filtering theme.components-md.scss, I had to filter for theme.components-md.css.