Gulp plugin to remove empty lines from HTML files
npm install gulp-remove-empty-lines-htmlA Gulp plugin that removes empty lines from HTML files and optionally removes HTML comments. It preserves the original formatting of the HTML content.
This package supports both CommonJS (require) and ESM (import) usage. Node.js >=22 is required.
``bash`
npm install gulp-remove-empty-lines-html --save-dev
`javascript
const { src, dest } = require('gulp');
const { removeEmptyLinesHtml } = require('gulp-remove-empty-lines-html');
gulp.task('clean-html', () => {
return gulp.src('./src/*/.html')
.pipe(removeEmptyLinesHtml())
.pipe(gulp.dest('./dist'));
});
`
`javascript
import { src, dest } from 'gulp';
import removeEmptyLinesHtml from 'gulp-remove-empty-lines-html';
export function cleanHtml() {
return src('./src/*/.html')
.pipe(removeEmptyLinesHtml())
.pipe(dest('./dist'));
}
`
removeComments
Default: false
Type: boolean
Description: Remove all HTML comments from files.
- Removes empty lines and lines containing only whitespace
- Optionally removes HTML comments (when removeComments is true).html
- Preserves original HTML formatting and indentation
- Only processes HTML files ( extension)
- Node.js >=22
Input:
`html
This is a test
`
Output (default):
`html`
Hello World
This is a test
Output (with removeComments: true):`html``
Hello World
This is a test
MIT