@milencode/bundlewatch-parsers
v2.2.4
Published
Parse existing bundle analyzer outputs instead of re-analyzing files.
Readme
@milencode/bundlewatch-parsers
Parse existing bundle analyzer outputs instead of re-analyzing files.
Why?
Existing tools like webpack-bundle-analyzer and rollup-plugin-visualizer already do excellent analysis and visualization. Instead of duplicating that work, BundleWatch parses their output and adds:
- ✅ Time-series tracking (git-based storage)
- ✅ Build comparisons
- ✅ Trend analysis
- ✅ CI/CD integration
- ✅ Alerting
Result: 10-100x faster than re-analyzing files!
Supported Formats
Webpack Stats
import { parseWebpackStats } from '@milencode/bundlewatch-parsers';
import stats from './stats.json';
const metrics = parseWebpackStats(stats, {
branch: 'main',
commit: 'abc123',
estimateCompression: true, // Estimate gzip/brotli sizes
});
// metrics is now in BuildMetrics format
// Ready for comparison, storage, etc.Coming Soon
parseRollupVisualizer()- Parse rollup-plugin-visualizer outputparseViteManifest()- Parse Vite's .vite/manifest.jsonparseNextjsStats()- Parse Next.js build output
Usage with Webpack
// webpack.config.js
const { BundleAnalyzerPlugin } = require('webpack-bundle-analyzer');
module.exports = {
plugins: [
new BundleAnalyzerPlugin({
analyzerMode: 'json', // Generate stats.json
generateStatsFile: true,
statsFilename: 'stats.json',
}),
],
};Then in your CI/post-build:
import { parseWebpackStats } from '@milencode/bundlewatch-parsers';
import { GitStorage } from '@milencode/bundlewatch-core';
import fs from 'fs';
// Read their stats
const stats = JSON.parse(fs.readFileSync('dist/stats.json', 'utf-8'));
// Parse to our format (< 1ms)
const metrics = parseWebpackStats(stats);
// Add our layer (time-series tracking)
const storage = new GitStorage();
await storage.save(metrics);
// Compare against baseline
const baseline = await storage.load('main');
const comparison = compare(metrics, baseline);
console.log(comparison); // See what changed!Performance
Before (re-analyzing files):
- Read all files from disk: ~500ms
- Compress with gzip: ~800ms
- Compress with brotli: ~600ms
- Total: ~2 seconds
After (parsing stats):
- Parse JSON: <1ms
- Total: <1ms ⚡
~2000x faster!
API
parseWebpackStats(stats, options)
Converts webpack stats.json to BuildMetrics format.
Parameters:
stats- Webpack stats object (from stats.json)options(optional):branch- Git branch namecommit- Git commit hashestimateCompression- Estimate gzip/brotli sizes (default: true)
Returns: BuildMetrics object
License
MIT
