[英]gulp-rev-replace on HTML files in subfolders
我想知道如何获得gulp-rev-replace来替换子文件夹中HTML文件中相同哈希值的文件引用。 考虑以下文件结构
和以下html语句:
index.html:
<!-- build:css styles/main.css -->
<link rel="stylesheet" href="/bower_components/normalize-css/normalize.css">
<link rel="stylesheet" href="styles/main.css">
<!-- endbuild -->
subfolder / index.html:
<!-- build:css ../styles/main.css -->
<link rel="stylesheet" href="/bower_components/normalize-css/normalize.css">
<link rel="stylesheet" href="../styles/main.css">
<!-- endbuild -->
还有我的Gulpfile中的以下内容
gulp.task('html', ['styles'], () => {
const assets = $.useref.assets({searchPath: ['.tmp', 'app', '.']});
return gulp.src('app/**/*.html')
.pipe(assets)
.pipe($.if('*.js', $.uglify()))
.pipe($.if('*.css', $.minifyCss({compatibility: '*'})))
.pipe($.rev())
.pipe(assets.restore())
.pipe($.useref())
.pipe($.revReplace())
.pipe($.if('*.html', $.minifyHtml({conditionals: true, loose: true})))
.pipe(gulp.dest('dist'));
});
index.html
的样式链接块将替换为正确的缩小和哈希样式表引用。 subfolder/index.html
的相同块将改为获得完全不同的哈希样式表引用。 但是,它确实使样式表的路径正确。
我是否正确设置了Gulpfile?
借助这个单独的答案弄清楚了。 我最终将每个HTML文件中的样式引用设置为app目录的根目录,并提供3个目录进行搜索:
<!-- build:css({.tmp,app,.}) /styles/main.css -->
<link rel="stylesheet" href="/bower_components/normalize-css/normalize.css">
<link rel="stylesheet" href="/styles/main.css">
<!-- endbuild -->
匹配提供给gulp-useref的三个目录
const assets = $.useref.assets({searchPath: ['.tmp', 'app', '.']});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.