我有多个文件,需要从manifest.json重命名散列的CSS,但是我似乎无法使其工作。
我尝试创建具有多个源和目标的数组,但是我认为我缺少一些东西。基本上,我希望它更改多个文件中的值以匹配manifest.json中的特定CSS文件。
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 };