使用gulp删除index.html的body内容

我能够从索引中重命名文件名称。 使用以下configuration

Gulp.js

var rename = require("gulp-rename"); gulp.task('modify-html', function () { gulp.src('reports/index.html') .pipe(rename('/app.html')) .pipe(gulp.dest('reports/')); }); 

有谁知道如何使用gulp删除我的HTML文件的正文内容

的index.html

 <html> <body> <h1>My First Heading</h1> <p>My first paragraph.</p> </body> </html> 

你可以用gulp-htmlreplace它来代替HTML块。

标记需要删除的内容

 <!-- build:remove --> Put all the content which needs to be removed, in the block <!-- endbuild --> 

并使用它

 var htmlreplace = require('gulp-html-replace') gulp.task('modify-html', function () { gulp.src('reports/index.html') .pipe(htmlreplace({ remove : '' })) .pipe(rename('/app.html')) .pipe(gulp.dest('reports/')); }); 

然后,你可以使用gulp-dom

 var dom = require('gulp-dom'); gulp.task('modify-html', function () { gulp.src('reports/index.html') .pipe(dom(function () { this.querySelector('body').innerHTML = ''; return this; })) .pipe(rename('/app.html')) .pipe(gulp.dest('reports/')); }); 

注意:我没有testing过。