Gulp.js在使用gulp.useref后为SRC和href属性追加字符串
gulp.js prepend and append string to src and href attributes after using gulp.useref
我在一个模板引擎中运行一些html文件,所有资源都是这样声明的:
<link rel="stylesheet" href="$href('libs/bootstrap.min.css')">
<script src="$href('libs/jquery.js')"></script>
当我运行$。Useref确实将文件移动到正确的文件夹中,但是保留了.html文件应有的绝对路径和相对路径。我是否可以编辑$。用户"模板"的脚本和链接标签指向正确的地方和前缀/追加$href(")内的SRC和href属性?有没有其他的gulp插件可以做到这一点?
最后用gulp-replace:
gulp.task('templates', function () {
return gulp.src('dist/**/*.html')
.pipe(replace(/src="([^"]*)"/g, 'src="$$href(''$1'')"'))
.pipe(replace(/href="([^"]*)"/g, 'href="$$href(''$1'')"'))
.pipe(gulp.dest('dist'));
});
相关文章:
- 使用JQuery从包含A href值中设置*all*IMG-src值
- 正则表达式使链接可点击(仅在“href”而不是“img src”中)
- 使用jQuery禁用img src等于特定值时的href
- 删除了wysihtml5.image src和href
- 使用 javascript 在刷新时更改 “href” 和 img “src” 值
- 从父锚点 href 更改 img src
- a.getAttribute(“href”) 返回 img src 而不是 href
- 获取图像 src,然后将其作为 href 应用于 .each 循环中
- 我应该在执行推送状态时更新所有 href 和 src 吗?
- 我可以使用 javascript:this.child.src 作为链接的 href 吗?
- href 中的角绑定有效,但 src 绑定不起作用
- 从元素中获取href,并将其添加到图像的src属性中
- 将location.href添加到脚本src中
- 添加图像src和<a>在List.js中的href
- 如何从图像的src值填充href值
- 如何在具有相同 src 的图像上自动添加 href
- 如何从图像中复制URL's src属性转换为jQuery中的href属性
- 如何从javascript工作在c# .aspx文件,指向正确的文件夹/文件与href和src
- 在href of link中替换src
- 更改img onclick的href和src