A posthtml plugin remove whitespace between HTML tags
This tag is based on and compatible with the Twig spaceless
tag, Swig spaceless
tag and Django spaceless
tag.
npm i -D posthtml posthtml-spaceless
Note: This project is compatible with node v4+
import {readFileSync, writeFileSync} from 'fs';
import posthtml from 'posthtml';
import spaceless from 'posthtml-spaceless';
const html = readFileSync('input.html', 'utf8');
posthtml()
.use(spaceless())
.process(html)
.then(result => {
writeFileSync('output.html', result.html);
});
Returns the html without whitespace between tags
<!DOCTYPE html>
<html>
<head></head>
<body>
<h2>Header</h2>
<spaceless>
<ul>
<li>one</li>
<li>two</li>
<li>three</li>
</ul>
</spaceless>
</body>
</html>
<!DOCTYPE html>
<html>
<head></head>
<body>
<h2>Header</h2>
<ul><li>one</li><li>two</li><li>three</li></ul>
</body>
</html>