0

Here is the post I am following with no success.

Modify file in place (same dest) using Gulp.js and a globbing pattern

Here is my code

var fstrm = require('gulp');

var inlineCss = require('gulp-inline-css');
var rename = require("gulp-rename");

(function() {
  fstrm.src("emails/**/index.html")
    .pipe(inlineCss({}))
    .pipe(rename("inline.html"))
    .pipe(fstrm.dest("emails"));
}());

it finds all index.html in the subdirectories under emails/ and inlines the css (this I can confirm) but fails to write that file back in the same subdirectory from which the index.html came. Instead it writes them all to the emails directory overwriting the previous inline.html and leaving then just the last file to be processed.

I have tried every variation offered at that and the other post related to this question with no success. Has fileglob changed since? or gulp? I ran this using vinyl-fs instead of gulp and it's the same deal.

Community
  • 1
  • 1
DKebler
  • 1,216
  • 1
  • 15
  • 27

1 Answers1

1

Look at the Notes section of the gulp-rename docs, this works.

var gulp = require('gulp');
var rename = require('gulp-rename');
var inlineCss = require('gulp-inline-css');

gulp.task('doit', function() {
  return gulp.src("emails/**/*index.html")
    .pipe(inlineCss({}))
    .pipe(rename(function(path) {
      path.dirname = '/emails/' + path.dirname;
      path.basename = path.basename.replace('index', 'inline');
      return path;
    }))
    .pipe(gulp.dest("."));
});
rwisch45
  • 3,692
  • 2
  • 25
  • 36
  • Works perfectly. Guess it should have occurred to me that rename was messing with the file paths in a way not consistent with other solutions. – DKebler Feb 28 '16 at 23:52