Javascript 基于html属性向gulp构建过程添加条件
是否可以添加一个条件,使我的项目中所有html文件中的每个Javascript 基于html属性向gulp构建过程添加条件,javascript,html,angularjs,gulp,bower,Javascript,Html,Angularjs,Gulp,Bower,是否可以添加一个条件,使我的项目中所有html文件中的每个img标记都应该具有另一个属性,如my custom directive 我有一个angular指令,它修改我的webapp中相对img src URL的基本URL,我想防止我的团队成员在他们编写的html模板中丢失此属性。您可以使用它来更改每个标记 var replace = require('gulp-replace'); gulp.task('pages', function(){ gulp.src(['*.html'])
img
标记都应该具有另一个属性,如my custom directive
我有一个angular指令,它修改我的webapp中相对img src URL的基本URL,我想防止我的团队成员在他们编写的html模板中丢失此属性。您可以使用它来更改每个标记
var replace = require('gulp-replace');
gulp.task('pages', function(){
gulp.src(['*.html'])
.pipe(replace(/<img/g, '<img my-custom-directive'))
.pipe(gulp.dest('build'));
});
var replace=require('gulp-replace');
gulp.task('pages',function(){
gulp.src(['*.html'])
.管道(更换(/
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'));
});