Use actual Node.js library name for bench; allow benchmarking without JS minification
This commit is contained in:
parent
863ccb947b
commit
cae66f3e2a
|
@ -49,7 +49,7 @@ The settings used for each minifier can be found in [minifiers.js](./minifiers.j
|
||||||
|
|
||||||
Make sure to install the dependencies listed in [package.json](./package.json) by running `npm i` or `yarn`. Node.js 10 is required, and system dependencies for building [canvas](https://www.npmjs.com/package/canvas), used for rendering graphs, may need to be installed. See the [npm package](https://www.npmjs.com/package/canvas) for more details.
|
Make sure to install the dependencies listed in [package.json](./package.json) by running `npm i` or `yarn`. Node.js 10 is required, and system dependencies for building [canvas](https://www.npmjs.com/package/canvas), used for rendering graphs, may need to be installed. See the [npm package](https://www.npmjs.com/package/canvas) for more details.
|
||||||
|
|
||||||
Run [build.sh](./build.sh) to build minify-html-nodejs with the local minify-html.
|
Run [build.sh](./build.sh) to build @minify-html/js with the local minify-html.
|
||||||
|
|
||||||
Run [sizes.js](sizes.js) to run each HTML minifier against each test and record the minified size results. This will also output the minified files in `min` if inspection of minified outputs is necessary. [compare.sh](./compare.sh) is a useful script for viewing a character-by-character diff between the minified outputs of minify-html and html-minifier for a specific test. Pass the test's file name as the first argument.
|
Run [sizes.js](sizes.js) to run each HTML minifier against each test and record the minified size results. This will also output the minified files in `min` if inspection of minified outputs is necessary. [compare.sh](./compare.sh) is a useful script for viewing a character-by-character diff between the minified outputs of minify-html and html-minifier for a specific test. Pass the test's file name as the first argument.
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
git --no-pager diff --no-index --word-diff=color --word-diff-regex=. "min/html-minifier/$1.html" "min/minify-html-nodejs/$1.html" | less
|
git --no-pager diff --no-index --word-diff=color --word-diff-regex=. "min/html-minifier/$1.html" "min/@minify-html/js/$1.html" | less
|
||||||
|
|
|
@ -3,7 +3,7 @@ const results = require('./results');
|
||||||
|
|
||||||
const colours = {
|
const colours = {
|
||||||
'minify-html': '#041f60',
|
'minify-html': '#041f60',
|
||||||
'minify-html-nodejs': '#1f77b4',
|
'@minify-html/js': '#1f77b4',
|
||||||
'minimize': '#ff7f0e',
|
'minimize': '#ff7f0e',
|
||||||
'html-minifier': '#2ca02c',
|
'html-minifier': '#2ca02c',
|
||||||
};
|
};
|
||||||
|
@ -56,7 +56,7 @@ const renderChart = async (cfg) => {
|
||||||
};
|
};
|
||||||
|
|
||||||
(async () => {
|
(async () => {
|
||||||
const averageSpeeds = results.getSpeedResults().getAverageRelativeSpeedPerMinifier('minify-html-nodejs');
|
const averageSpeeds = results.getSpeedResults().getAverageRelativeSpeedPerMinifier('@minify-html/js');
|
||||||
results.writeAverageSpeedsGraph(await renderChart({
|
results.writeAverageSpeedsGraph(await renderChart({
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: {
|
data: {
|
||||||
|
@ -70,7 +70,7 @@ const renderChart = async (cfg) => {
|
||||||
...chartOptions('Average operations per second (higher is better)', false, percentageTick),
|
...chartOptions('Average operations per second (higher is better)', false, percentageTick),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const speeds = results.getSpeedResults().getRelativeFileSpeedsPerMinifier('minify-html-nodejs');
|
const speeds = results.getSpeedResults().getRelativeFileSpeedsPerMinifier('@minify-html/js');
|
||||||
results.writeSpeedsGraph(await renderChart({
|
results.writeSpeedsGraph(await renderChart({
|
||||||
type: 'bar',
|
type: 'bar',
|
||||||
data: {
|
data: {
|
||||||
|
|
|
@ -3,7 +3,7 @@ const htmlMinifier = require('html-minifier');
|
||||||
const minifyHtml = require('@minify-html/js');
|
const minifyHtml = require('@minify-html/js');
|
||||||
const minimize = require('minimize');
|
const minimize = require('minimize');
|
||||||
|
|
||||||
const minifyHtmlCfg = minifyHtml.createConfiguration({minifyJs: true});
|
const testJsMinification = process.env.HTML_ONLY !== '1';
|
||||||
|
|
||||||
const jsMime = new Set([
|
const jsMime = new Set([
|
||||||
undefined,
|
undefined,
|
||||||
|
@ -46,49 +46,62 @@ class EsbuildAsync {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
const minifyHtmlCfg = minifyHtml.createConfiguration({minifyJs: testJsMinification});
|
||||||
'minify-html-nodejs': (_, buffer) => minifyHtml.minifyInPlace(Buffer.from(buffer), minifyHtmlCfg),
|
const htmlMinifierCfg = {
|
||||||
'html-minifier': async (content) => {
|
collapseBooleanAttributes: true,
|
||||||
const js = new EsbuildAsync();
|
collapseInlineTagWhitespace: true,
|
||||||
const res = htmlMinifier.minify(content, {
|
collapseWhitespace: true,
|
||||||
collapseBooleanAttributes: true,
|
// minify-html can do context-aware whitespace removal, which is safe when configured correctly to match how whitespace is used in the document.
|
||||||
collapseInlineTagWhitespace: true,
|
// html-minifier cannot, so whitespace must be collapsed conservatively.
|
||||||
collapseWhitespace: true,
|
// Alternatively, minify-html can also be made to remove whitespace regardless of context.
|
||||||
// minify-html can do context-aware whitespace removal, which is safe when configured correctly to match how whitespace is used in the document.
|
conservativeCollapse: true,
|
||||||
// html-minifier cannot, so whitespace must be collapsed conservatively.
|
customEventAttributes: [],
|
||||||
// Alternatively, minify-html can also be made to remove whitespace regardless of context.
|
decodeEntities: true,
|
||||||
conservativeCollapse: true,
|
ignoreCustomComments: [],
|
||||||
customEventAttributes: [],
|
ignoreCustomFragments: [/<\?[\s\S]*?\?>/],
|
||||||
decodeEntities: true,
|
// This will be set to a function if `testJsMinification` is true.
|
||||||
ignoreCustomComments: [],
|
minifyJS: false,
|
||||||
ignoreCustomFragments: [/<\?[\s\S]*?\?>/],
|
processConditionalComments: true,
|
||||||
minifyJS: code => js.queue(code),
|
removeAttributeQuotes: true,
|
||||||
processConditionalComments: true,
|
removeComments: true,
|
||||||
removeAttributeQuotes: true,
|
removeEmptyAttributes: true,
|
||||||
removeComments: true,
|
removeOptionalTags: true,
|
||||||
removeEmptyAttributes: true,
|
removeRedundantAttributes: true,
|
||||||
removeOptionalTags: true,
|
removeScriptTypeAttributes: true,
|
||||||
removeRedundantAttributes: true,
|
removeStyleLinkTypeAttributes: true,
|
||||||
removeScriptTypeAttributes: true,
|
removeTagWhitespace: true,
|
||||||
removeStyleLinkTypeAttributes: true,
|
useShortDoctype: true,
|
||||||
removeTagWhitespace: true,
|
};
|
||||||
useShortDoctype: true,
|
|
||||||
});
|
module.exports = {
|
||||||
return js.finalise(res);
|
'@minify-html/js': (_, buffer) => minifyHtml.minifyInPlace(Buffer.from(buffer), minifyHtmlCfg),
|
||||||
},
|
'html-minifier': testJsMinification
|
||||||
'minimize': async (content) => {
|
? async (content) => {
|
||||||
const js = new EsbuildAsync();
|
const js = new EsbuildAsync();
|
||||||
const res = new minimize({
|
const res = htmlMinifier.minify(content, {
|
||||||
plugins: [{
|
...htmlMinifierCfg,
|
||||||
id: 'esbuild',
|
minifyJS: code => js.queue(code),
|
||||||
element: (node, next) => {
|
});
|
||||||
if (node.type === 'text' && node.parent && node.parent.type === 'script' && jsMime.has(node.parent.attribs.type)) {
|
return js.finalise(res);
|
||||||
node.data = js.queue(node.data);
|
}
|
||||||
}
|
: content => htmlMinifier.minify(content, htmlMinifierCfg),
|
||||||
next();
|
'minimize': testJsMinification
|
||||||
},
|
? async (content) => {
|
||||||
}],
|
const js = new EsbuildAsync();
|
||||||
}).parse(content);
|
const plugins = [];
|
||||||
return js.finalise(res);
|
if (testJsMinification) {
|
||||||
},
|
plugins.push({
|
||||||
|
id: 'esbuild',
|
||||||
|
element: (node, next) => {
|
||||||
|
if (node.type === 'text' && node.parent && node.parent.type === 'script' && jsMime.has(node.parent.attribs.type)) {
|
||||||
|
node.data = js.queue(node.data);
|
||||||
|
}
|
||||||
|
next();
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
const res = new minimize({plugins}).parse(content);
|
||||||
|
return js.finalise(res);
|
||||||
|
}
|
||||||
|
: content => new minimize().parse(content),
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue