Bench with JS

This commit is contained in:
Wilson Lin 2020-07-14 12:50:32 +10:00
parent 8d26742047
commit 892e10c92e
2 changed files with 16 additions and 3 deletions

View File

@ -1,9 +1,10 @@
const htmlMinifier = require("html-minifier");
const minifyHtml = require("@minify-html/js-esbuild");
const minimize = require("minimize");
const terser = require('terser');
module.exports = {
'minify-html-nodejs': (_, buffer) => minifyHtml.minifyInPlace(Buffer.from(buffer), {minifyJs: false}),
'minify-html-nodejs': (_, buffer) => minifyHtml.minifyInPlace(Buffer.from(buffer), {minifyJs: true}),
'html-minifier': content => htmlMinifier.minify(content, {
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: true,
@ -16,6 +17,7 @@ module.exports = {
decodeEntities: true,
ignoreCustomComments: [],
ignoreCustomFragments: [/<\?[\s\S]*?\?>/],
minifyJS: true,
processConditionalComments: true,
removeAttributeQuotes: true,
removeComments: true,
@ -27,5 +29,15 @@ module.exports = {
removeTagWhitespace: true,
useShortDoctype: true,
}),
'minimize': content => new minimize().parse(content),
'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),
};

View File

@ -10,7 +10,8 @@
"minimist": "^1.2.0",
"mkdirp": "^0.5.1",
"request": "^2.88.0",
"request-promise-native": "^1.0.8"
"request-promise-native": "^1.0.8",
"terser": "^4.8.0"
},
"engines": {
"node": "10.x"