diff --git a/bench/minifiers.js b/bench/minifiers.js index 4ff0c1f..7d1ae92 100644 --- a/bench/minifiers.js +++ b/bench/minifiers.js @@ -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), }; diff --git a/bench/package.json b/bench/package.json index 44be3cc..d0c2674 100644 --- a/bench/package.json +++ b/bench/package.json @@ -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"