node compile-html.cjs in.html out.html
Created
August 13, 2020 07:44
-
-
Save ooflorent/af985b100f4bc2457fd177f0aaf0673b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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