基于html属性为gullow构建过程添加条件
Add condition to gulp building process based on html attribute
是否可以添加一个条件,使我的项目中所有html文件中的每个img
标记都应该具有另一个属性,如my-custom-directive
?
我有一个angular指令,它修改了我的webapp中相对img src URL的基本URL,我想防止我的团队成员在他们编写的html模板中丢失这个属性。
您可以使用gulp-replacement来更改每个标签。。。
var replace = require('gulp-replace');
gulp.task('pages', function(){
gulp.src(['*.html'])
.pipe(replace(/<img/g, '<img my-custom-directive'))
.pipe(gulp.dest('build'));
});
这将为每个图像添加属性。如果你想要更多的控制,你可以使用gullow-tap来获取整个文件的内容;处理它。
var tap = require('gulp-tap');
gulp.task('pages', function(){
gulp.src(['*.html'])
.pipe(tap(function(file) {
// get current contents
let contents = file.contents.toString();
// do your conditional processing
// eg deal with each tag in a loop & only change those without the attribute
contents = contents.replace(/<img/g, '<img my-custom-directive');
// set new contents to flow through the gulp stream
file.contents = new Buffer(contents);
}))
.pipe(gulp.dest('build'));
});
相关文章:
- 为effect Composer创建GodRays效果过程
- 正在添加'X'按钮,在文本字段旁边使用javascript
- 如何在映射数组中添加换行符
- 正在将数据主题添加到所有项目
- ZeroClipboard-在复制之前添加到值
- 我可以在json对象中添加一个函数吗
- 将输入字段中的文本提交到我的数据库,同时将其添加到我的列表中
- 正在SharePoint 2013母版页中添加JQuery移动文件
- 如何添加浮动和非浮动,其他
- 添加文字和评论功能更新Div
- 如果使用 lodash 将属性存在于另一个对象中,则向对象添加属性
- 我的网站加载缓慢且挂起,因为实时加载过程被添加到我的 index.hml 中
- 在Cordova项目中添加.js会破坏构建过程
- 将jQuery添加到HTA后,调用VBScript过程将停止工作
- 如何使用wiredep将bread.bridge.angular添加到我的构建过程中
- 如何在每一次“暂停”的迭代过程中添加一个暂停;对于循环“;使用Javascript
- 如何阻止javascript在选择过程中自动添加标签?
- 为什么这个过程没有添加子元素?
- 如何添加年在xAxis日期格式,而导出?以及如何在导出过程中添加数据源
- 基于html属性为gullow构建过程添加条件