【问题标题】:gulp-htmlmin close automaticly the tagsgulp-htmlmin 自动关闭标签
【发布时间】:2016-07-18 23:31:51
【问题描述】:

gulp-htmlmin 有问题。

我有以下 HTML 代码:

<div class="test">
    <p>Lorem Ipsum</p>

随着 div 的关闭 (&lt;/div&gt;) 故意不添加。

编译后的HTML代码,是:

<div class="test"><p>Lorem Ipsum</p></div>

希望我不要自动关闭标签,即结果是:

<div class="test"><p>Lorem Ipsum</p>

我该怎么做?

【问题讨论】:

  • 为什么要使用格式错误的 html?
  • @DerekMT12 用于 PHP/HTML 文件。我是否应该包含headerfooter,其中标签以header 开头,然后在footer 中结束。

标签: html gulp


【解决方案1】:

我找到了我的问题的解决方案。在gulpfile.js 中添加 htmlmin 选项:includeAutoGeneratedTags: false

例如:

var gulp = require('gulp');
var htmlmin = require('gulp-htmlmin');

var htmlminOptions = {
    collapseWhitespace: true,
    includeAutoGeneratedTags: false
};

...

gulp.task('minify:html', function() {
    gulp.src('**/*.html')
    .pipe(htmlmin(htmlminOptions))
    .pipe(gulp.dest('path/to/dest');
});

更多信息请见:html-minifier

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-05-16
    • 2018-05-17
    • 2013-09-09
    • 1970-01-01
    相关资源
    最近更新 更多