Created
September 29, 2015 13:41
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
}) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
awesome you should a PR somehow! 👍