Skip to content

Instantly share code, notes, and snippets.

@bregenspan
Created September 29, 2015 13:41
Show Gist options
  • Save bregenspan/33f7791a78f6e4115af5 to your computer and use it in GitHub Desktop.
Save bregenspan/33f7791a78f6e4115af5 to your computer and use it in GitHub Desktop.
Sort Webpack analyze tool chunk list (e.g. http://webpack.github.io/analyse/#chunk/31) by size
var table = document.querySelectorAll('tbody')[1];
Array.prototype.slice.apply(table.querySelectorAll('tr')).forEach(function (el) {
var size = el.querySelector('td:nth-of-type(3)').innerHTML;
var num = parseInt(size,0);
if (size.indexOf('KiB') > -1) {
num = num * 1024;
}
el.setAttribute('data-size', num);
})
var rows = Array.prototype.slice.apply(table.querySelectorAll('tr'));
rows.forEach(function (row) {
var currentSize = parseInt(row.getAttribute('data-size'), 0);
var moved = false;
Array.prototype.slice.apply(table.querySelectorAll('tr')).forEach(function (irow) {
if (!moved && currentSize > parseInt(irow.getAttribute('data-size'), 0)) {
irow.parentNode.insertBefore(row, irow);
moved = true;
}
})
})
@Reggino
Copy link

Reggino commented Aug 12, 2016

awesome you should a PR somehow! 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment