2021-08-08 07:01:37 -04:00
|
|
|
const htmlMinifier = require("html-minifier");
|
2021-08-09 08:20:33 -04:00
|
|
|
const { htmlOnly, esbuildCss, esbuildJs, run } = require("../common");
|
2021-08-08 07:20:06 -04:00
|
|
|
|
2021-08-08 07:01:37 -04:00
|
|
|
const htmlMinifierCfg = {
|
|
|
|
collapseBooleanAttributes: true,
|
|
|
|
collapseInlineTagWhitespace: true,
|
|
|
|
collapseWhitespace: true,
|
|
|
|
// minify-html can do context-aware whitespace removal, which is safe when configured correctly to match how whitespace is used in the document.
|
|
|
|
// html-minifier cannot, so whitespace must be collapsed conservatively.
|
|
|
|
// Alternatively, minify-html can also be made to remove whitespace regardless of context.
|
|
|
|
conservativeCollapse: true,
|
|
|
|
customEventAttributes: [],
|
|
|
|
decodeEntities: true,
|
|
|
|
ignoreCustomComments: [],
|
|
|
|
ignoreCustomFragments: [/<\?[\s\S]*?\?>/],
|
|
|
|
minifyCSS: !htmlOnly && esbuildCss,
|
|
|
|
minifyJS: !htmlOnly && esbuildJs,
|
|
|
|
processConditionalComments: true,
|
|
|
|
removeAttributeQuotes: true,
|
|
|
|
removeComments: true,
|
|
|
|
removeEmptyAttributes: true,
|
|
|
|
removeOptionalTags: true,
|
|
|
|
removeRedundantAttributes: true,
|
|
|
|
removeScriptTypeAttributes: true,
|
|
|
|
removeStyleLinkTypeAttributes: true,
|
|
|
|
removeTagWhitespace: true,
|
|
|
|
useShortDoctype: true,
|
|
|
|
};
|
|
|
|
|
2021-08-09 08:20:33 -04:00
|
|
|
run((src) => htmlMinifier.minify(src, htmlMinifierCfg));
|