繁体   English   中英

gulp-rev-rewrite 没有写入所有文件

[英]gulp-rev-rewrite not writing in all files

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

改变

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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