Skip to content

Instantly share code, notes, and snippets.

@ooflorent
Created August 13, 2020 07:44
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ooflorent/af985b100f4bc2457fd177f0aaf0673b to your computer and use it in GitHub Desktop.
Save ooflorent/af985b100f4bc2457fd177f0aaf0673b to your computer and use it in GitHub Desktop.

Usage

node compile-html.cjs in.html out.html
const { promises: fs } = require("fs");
const htmlnano = require("htmlnano");
const posthtml = require("posthtml");
const inlineAssets = require("posthtml-inline-assets");
function main() {
let input = process.argv[2];
let output = process.argv[3];
fs.readFile(input)
.then((content) =>
posthtml([
inlineAssets(),
htmlnano({
collapseWhitespace: "all",
removeRedundantAttributes: true,
}),
]).process(content.toString(), {
quoteAllAttributes: false,
})
)
.then((result) => fs.writeFile(output, result.html));
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment