Hey there! I'm currently working as a junior front-end developer and have recently delved into using gulp. One of the challenges I face is dealing with HTML files received from senior developers that aren't well-formatted, containing excessive whitespace and poor indentation. Here's an example:
<div id="preloader">
<div id="status"> </div>
</div>
<div id="nav-anchor"></div>
<div class="top-navbar-fixed">
<nav class="sibling-website-nav">
<ul>
<li><a href="">Accounting</a></li><li class="active"><a href="">Training</a></li>
<!-- <li><a href="">Recruitment</a></li> -->
</ul>
</nav>
The unnecessary whitespace makes it hard to work with. Fortunately, gulp has a plugin called HERE, which can help clean up the code like so:
var prettify = require('gulp-html-prettify');
gulp.task('templates', function() {
gulp.src('./lib/*.html')
.pipe(prettify({indent_char: ' ', indent_size: 2}))
.pipe(gulp.dest('./dist/'))
});
While this works well, it creates new files in a different directory. What I aim for is to format the existing files in their current directories. How can I achieve this using gulp?