javascriptnode.jsgulpgulp-rev

Gulp Rev doesn't include paths in my manifest file


I have Gulp tasks set up to concat, minify and fingerprint assets all at once, writing them directly to my assets folder:

(the css part)

gulp.task('styles:cssmin', function(){
    return gulp.src('src/css/*.css')
        .pipe(concat('main.css')) // combine them
        .pipe(cssmin()) // minify them
        .pipe(rev()) // Pipe through gulp-rev to fingerprint generated file
        .pipe(gulp.dest('assets/css'))  // write rev'd assets 
        .pipe(rev.manifest({
            merge: true // Merge because this happens for .js and images too
        }))
        .pipe(gulp.dest('./')); // write manifest
});

This fingerprints the files and generates a manifest, but I can't get any paths to be saved to the manifest file. Here's the manifest it generates:

{
  "bg.jpg": "bg-447ac2238b.jpg",
  "logo.png": "logo-e31e139d4d.png",
  "main-min.js": "main-min-cc3a682299.js",
  "main.css": "main-ea0d06582f.css",
  "main.js": "main-35ec0bb3c8.js"
}

Which I would like to have as:

{
  "assets/img/bg.jpg": "assets/img/bg-447ac2238b.jpg",
  "assets/img/logo.png": "assets/img/logo-e31e139d4d.png",
  "assets/js/main-min.js": "assets/js/main-min-cc3a682299.js",
  "assets/css/main.css": "assets/css/main-ea0d06582f.css",
  "assets/jsg/main.js": "assets/js/main-35ec0bb3c8.js"
}

Especially considering the docs give an example which includes the relative paths


Solution

  • I was having the same issue, and ended up renaming the asset dirs in the stream to what I wanted and specifying the path of the rev-manifest.

    var rename = require("gulp-rename");
    
    gulp.task('styles:cssmin', function(){
    
        return gulp.src('src/css/*.css')
            .pipe(concat('main.css')) // combine them
            .pipe(cssmin()) // minify them
            .pipe(rename({
                dirname: "assets/css" //manually fixing path for rev-manifest
            }))
            .pipe(rev('path/to/your/rev/rev-manifest.json')) // Specify manifest location
            .pipe(gulp.dest('assets/css'))  // write rev'd assets 
            .pipe(rev.manifest({
                merge: true // Merge because this happens for .js and images too
            }))
            .pipe(gulp.dest('./')); // write manifest
    });