0

我有多个文件,我需要从 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 };
4

1 回答 1

0

改变

const manifest = gulp.src('./css/rev-manifest.json');

对此

const { readFileSync } = require('fs'); // import this in header
// replace the below line of code with your code and make sure the rev-manifest file path is correct
const manifest = readFileSync('./rev-manifest.json'); // my rev file path points to the root of the project folder
于 2021-09-09T05:47:35.760 回答