-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbrowserify-debug-size.js
executable file
·47 lines (35 loc) · 1.25 KB
/
browserify-debug-size.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/home/ruben/.nvm/versions/node/v0.12.10/bin/node
var _ = require('lodash');
var fs = require('fs');
var exec = require("child_process").exec;
var exclude = ['browserify'];
exec("browserify " + process.argv[2] + " --list", function(err, stdout, stderr) {
var files = stdout.split("\n");
var moduleSizes = {};
files.filter(function(f) { return !!f; }).forEach(function(file) {
var modules = file.match(/node_modules\/(.+?)\//g);
if (modules) {
var module = null;
modules.forEach(function(_module, i) {
if (module) {
return;
}
_module = _module.substr(13, _module.length - 14);
if (exclude.indexOf(_module) === -1 || i === modules.length - 1) {
module = _module;
}
});
} else {
module = "self";
}
if (!moduleSizes[module]) {
moduleSizes[module] = {
module: module,
size: 0
}
}
moduleSizes[module]['size'] += fs.statSync(file)['size'];
});
console.log(_.sortBy(moduleSizes, 'size'));
console.log(_.sum(_.map(moduleSizes, function(module) { return module.size; })));
});