2020-01-09 04:45:14 -05:00
|
|
|
const htmlMinifier = require("html-minifier");
|
2020-07-21 03:57:39 -04:00
|
|
|
const minifyHtml = require("@minify-html/js");
|
2020-01-09 04:45:14 -05:00
|
|
|
const minimize = require("minimize");
|
2020-07-13 22:50:32 -04:00
|
|
|
const terser = require('terser');
|
2020-01-09 04:45:14 -05:00
|
|
|
|
|
|
|
module.exports = {
|
2020-07-13 22:50:32 -04:00
|
|
|
'minify-html-nodejs': (_, buffer) => minifyHtml.minifyInPlace(Buffer.from(buffer), {minifyJs: true}),
|
2020-01-09 04:45:14 -05:00
|
|
|
'html-minifier': content => htmlMinifier.minify(content, {
|
|
|
|
collapseBooleanAttributes: true,
|
|
|
|
collapseInlineTagWhitespace: true,
|
|
|
|
collapseWhitespace: true,
|
2020-07-11 11:29:34 -04:00
|
|
|
// minify-html can do context-aware whitespace removal, which is safe when configured correctly to match how whitespace is used in the document.
|
2020-01-17 19:42:01 -05:00
|
|
|
// html-minifier cannot, so whitespace must be collapsed conservatively.
|
2020-07-11 11:29:34 -04:00
|
|
|
// Alternatively, minify-html can also be made to remove whitespace regardless of context.
|
2020-01-17 19:42:01 -05:00
|
|
|
conservativeCollapse: true,
|
2020-01-09 04:45:14 -05:00
|
|
|
customEventAttributes: [],
|
|
|
|
decodeEntities: true,
|
|
|
|
ignoreCustomComments: [],
|
|
|
|
ignoreCustomFragments: [/<\?[\s\S]*?\?>/],
|
2020-07-13 22:50:32 -04:00
|
|
|
minifyJS: true,
|
2020-01-09 04:45:14 -05:00
|
|
|
processConditionalComments: true,
|
|
|
|
removeAttributeQuotes: true,
|
|
|
|
removeComments: true,
|
2020-01-09 06:40:04 -05:00
|
|
|
removeEmptyAttributes: true,
|
2020-01-09 04:45:14 -05:00
|
|
|
removeOptionalTags: true,
|
|
|
|
removeRedundantAttributes: true,
|
|
|
|
removeScriptTypeAttributes: true,
|
|
|
|
removeStyleLinkTypeAttributes: true,
|
|
|
|
removeTagWhitespace: true,
|
|
|
|
useShortDoctype: true,
|
|
|
|
}),
|
2020-07-13 22:50:32 -04:00
|
|
|
'minimize': content => new minimize({
|
|
|
|
plugins: [{
|
|
|
|
id: 'terser',
|
|
|
|
element: (node, next) => {
|
|
|
|
if (node.type === 'text' && node.parent && node.parent.type === 'script') {
|
|
|
|
node.data = terser.minify(node.data).code || node.data;
|
|
|
|
}
|
|
|
|
next();
|
|
|
|
},
|
|
|
|
}]
|
|
|
|
}).parse(content),
|
2020-01-09 04:45:14 -05:00
|
|
|
};
|