V
V
Vasily Vyaznikov2016-10-20 16:15:01
gulp.js
Vasily Vyaznikov, 2016-10-20 16:15:01

How to remove comments when minifying HTML?

I use gulp-htmlmin for minification . But, if there are comments in the code, then they remain in the form in which they were originally. For example, there are blocks of commented out code that is not compressed in any way.
I can't figure out if it's possible to configure gulp-htmlmin to remove or compress HTML comments.
Task code:

gulp.task('html', function () {
    return gulp.src('src/*.html') 
        .pipe(include()) 
        .pipe(htmlmin({collapseWhitespace: true})) 
        .pipe(gulp.dest('dist')) 
        .pipe(browserSync.reload({stream: true})); 
});

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Ernest Faizullin, 2016-10-20
@erniesto77

as an option

var gulp = require('gulp');
var removeHtmlComments = require('gulp-remove-html-comments');
 
gulp.task('html', function () {
  return gulp.src('src/*.html')
    .pipe(removeHtmlComments())
    .pipe(gulp.dest('dist'));
});

https://www.npmjs.com/package/gulp-remove-html-comments

A
Andrey Efimov, 2018-12-12
@efiand

.pipe(htmlmin({
collapseWhitespace: true,
removeComments: true
}))
https://github.com/kangax/html-minifier#options-qu...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question