我想知道如何用相同的散列替换子文件夹中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 -->
子文件夹/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 -->
下面是我的古尔普文件
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
中的同一个块将得到一个完全不同的散列样式表引用。但是,它确实使样式表的路径正确。
我的文件设置不正确吗?
发布于 2015-10-14 01:24:51
在这个单独回答的帮助下找到了答案。最后,我将每个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', '.']});
https://stackoverflow.com/questions/33002378
复制相似问题