【问题标题】:gulp-rev-rewrite not writing in all filesgulp-rev-rewrite 未写入所有文件
【发布时间】:2019-04-11 11:48:39
【问题描述】:

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

【问题讨论】:

  • 您遇到错误了吗?
  • 不,它写入 ../../../../com-holding-page/index.html 就是这样,但使用了不正确的哈希引用。
  • 在什么意义上不正确?它使用哪个“散列引用”,应该改用哪个?

标签: javascript ecmascript-6 gulp gulp-rev


【解决方案1】:

改变

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-07-03
    • 2016-03-22
    • 1970-01-01
    • 2019-01-17
    • 2020-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    相关资源
    最近更新 更多