我可以从索引中重命名文件名。使用以下配置
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-html-replace它取代了 HTML block 。
标记需要删除的内容
<!-- 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/'));
});
注意:我没有测试过。
关于javascript - 使用 gulp 删除 index.html 的正文内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45953110/