I have multiple files where i need to rename the hashed css from the manifest.json but i cant seem to get it to work.

I have tried creating an array with multiple sources and destinations but i think im missing something. Basically i want it to change the values in multiple files to match the specific css files from the manifest.json.

import gulp from 'gulp';
import mergeStream from 'merge-stream';
import rev from 'gulp-rev';
import revRewrite from 'gulp-rev-rewrite';
import revDelete from 'gulp-rev-delete-original';
import { hashFiles, hashReplace } from './hashTask.config';

// imported arrays here for you to see ////

// Paths to hash all the files to bust the cache
const hashFiles = [
  './css/**/*.css',
  '../../../../com-holding-page/css/*.css',
  '!./css/lib/**'
];

const hashReplace = [
  { src : '../../../../com-holding-page/index.html', dest : '../../../../com-holding-page/' },
  { src : '../../../../app/design/frontend/test/default/template/page/html/head.phtml', dest : '../../../../app/design/frontend/test/default/template/page/html/' },
  { src : '../../../../app/design/frontend/test/default/layout/local.xml', dest : '../../../../app/design/frontend/test/default/layout/' }
];

//////////

const hashTask = () => {
  return gulp.src(hashFiles, {base: 'css'})
    .pipe(rev())
    .pipe(revDelete()) // Remove the unrevved files
    .pipe(gulp.dest('./css/'))
    .pipe(rev.manifest('rev-manifest.json', {
      merge: true // Merge with the existing manifest if one exists
    }))
    .pipe(gulp.dest('./css/'))
};

const hashIncludes = () => {
    const manifest = gulp.src('./css/rev-manifest.json');
    return mergeStream(
    hashReplace
      .map( (file) => {
                return gulp.src(file.src)
                .pipe(revRewrite({ 
                    manifest: manifest,
                    replaceInExtensions: ['.html', '.phtml', '.xml'] 
                }))
                .pipe(gulp.dest(file.dest));

      })
  );
};

export { hashTask, hashIncludes };

0 Answers