简体   繁体   中英

Gulp / Vinyl-fs - dest same directory as src not working with gulp-rename

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.

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("."));
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM