webpack-bundle-size-analyzer
Advanced tools
Comparing version 1.0.3 to 1.1.0
@@ -5,13 +5,22 @@ /// <reference path="typings/typings.d.ts" /> | ||
var size_tree = require('./size_tree'); | ||
commander.version('0.1.0') | ||
.usage('[options] <Webpack JSON output>') | ||
.description("Analyzes the JSON output from 'webpack --json'\n and displays the total size of JS modules\n contributed by each NPM package that has been included in the bundle."); | ||
function printStats(json) { | ||
var bundleStats = JSON.parse(json); | ||
var depTree = size_tree.dependencySizeTree(bundleStats); | ||
size_tree.printDependencySizeTree(depTree); | ||
} | ||
commander.version('1.1.0') | ||
.usage('[options] [Webpack JSON output]') | ||
.description("Analyzes the JSON output from 'webpack --json'\n and displays the total size of JS modules\n contributed by each NPM package that has been included in the bundle.\n \n The JSON output can either be supplied as the first argument or\n passed via stdin.\n "); | ||
commander.parse(process.argv); | ||
if (!commander.args[0]) { | ||
if (commander.args[0]) { | ||
printStats(fs.readFileSync(commander.args[0]).toString()); | ||
} | ||
else if (!process.stdin.isTTY) { | ||
var json = ''; | ||
process.stdin.on('data', function (chunk) { return json += chunk.toString(); }); | ||
process.stdin.on('end', function () { return printStats(json); }); | ||
} | ||
else { | ||
console.error('No Webpack JSON output file specified. Use `webpack --json` to generate it.'); | ||
process.exit(1); | ||
} | ||
var bundleStatsJson = fs.readFileSync(commander.args[0]).toString(); | ||
var bundleStats = JSON.parse(bundleStatsJson); | ||
var depTree = size_tree.dependencySizeTree(bundleStats); | ||
size_tree.printDependencySizeTree(depTree); |
@@ -85,4 +85,4 @@ /// <reference path="typings/typings.d.ts" /> | ||
parent.size += mod.size; | ||
packages.forEach(function (package) { | ||
var existing = parent.children.filter(function (child) { return child.packageName === package; }); | ||
packages.forEach(function (pkg) { | ||
var existing = parent.children.filter(function (child) { return child.packageName === pkg; }); | ||
if (existing.length > 0) { | ||
@@ -94,3 +94,3 @@ existing[0].size += mod.size; | ||
var newChild = { | ||
packageName: package, | ||
packageName: pkg, | ||
size: mod.size, | ||
@@ -97,0 +97,0 @@ children: [] |
{ | ||
"name": "webpack-bundle-size-analyzer", | ||
"version": "1.0.3", | ||
"version": "1.1.0", | ||
"description": "A utility to find how your dependencies are contributing to the size of your Webpack bundles", | ||
@@ -35,4 +35,4 @@ "main": "build/size_tree.js", | ||
"tsd": "^0.6.0-beta.5", | ||
"typescript": "^1.5.0-alpha" | ||
"typescript": "^1.6.2" | ||
} | ||
} |
@@ -23,4 +23,3 @@ Webpack Bundle Size Analyzer | ||
npm install -g webpack-bundle-size-analyzer | ||
webpack --json > bundle-stats.json | ||
analyze-bundle-size bundle-stats.json | ||
webpack --json | analyze-bundle-size | ||
```` | ||
@@ -27,0 +26,0 @@ |
10260
171
74