|
| 1 | +# Bundle Analyzer |
| 2 | + |
| 3 | +Measures bundle sizes for layerchart across different use-case scenarios, helping track the cost of common chart configurations and detect regressions over time. |
| 4 | + |
| 5 | +## Quick start |
| 6 | + |
| 7 | +```bash |
| 8 | +# Build layerchart first (required) |
| 9 | +pnpm --filter layerchart package |
| 10 | + |
| 11 | +# Run analysis on all scenarios |
| 12 | +pnpm bundle:analyze |
| 13 | + |
| 14 | +# Compare two reports |
| 15 | +pnpm bundle:compare -- path/to/new.json path/to/old.json |
| 16 | +``` |
| 17 | + |
| 18 | +## How it works |
| 19 | + |
| 20 | +For each scenario, the analyzer: |
| 21 | + |
| 22 | +1. Creates a temporary entry file that imports the specified components from `layerchart` |
| 23 | +2. Builds it with Vite + esbuild (minified, tree-shaken, Svelte externalized) |
| 24 | +3. Measures the resulting bundle size (raw + gzipped) |
| 25 | +4. Saves results to `bundle-reports/latest.json` |
| 26 | + |
| 27 | +Svelte runtime is excluded from measurements since it's shared across all components. The reported sizes reflect layerchart code + its dependencies (d3, dagre, etc.). |
| 28 | + |
| 29 | +## Scenarios |
| 30 | + |
| 31 | +Scenarios are defined in [`define-scenarios.ts`](./define-scenarios.ts) and represent real-world usage patterns: |
| 32 | + |
| 33 | +| Scenario | Description | |
| 34 | +|----------|-------------| |
| 35 | +| `core` | Bare minimum: `Chart` + `Svg` | |
| 36 | +| `line-chart` | Line chart with axes and grid | |
| 37 | +| `line-chart-interactive` | Line chart with tooltip and highlight | |
| 38 | +| `area-chart` | Area chart with axes | |
| 39 | +| `bar-chart` | Bar chart with axes | |
| 40 | +| `scatter-chart` | Scatter plot with points | |
| 41 | +| `pie-chart` | Pie/donut chart with arcs | |
| 42 | +| `high-level-charts` | All high-level chart components | |
| 43 | +| `geo` | Geographic map with paths | |
| 44 | +| `geo-tiles` | Geographic map with tile layer | |
| 45 | +| `geo-full` | All geo components | |
| 46 | +| `force` | Force-directed graph | |
| 47 | +| `hierarchy-tree` | Tree layout | |
| 48 | +| `hierarchy-treemap` | Treemap layout | |
| 49 | +| `hierarchy-pack` | Circle packing | |
| 50 | +| `dagre` | Dagre directed graph | |
| 51 | +| `sankey` | Sankey flow diagram | |
| 52 | +| `chord` | Chord diagram | |
| 53 | +| `canvas` | Canvas-based rendering | |
| 54 | +| `all` | Everything from layerchart | |
| 55 | + |
| 56 | +## CLI options |
| 57 | + |
| 58 | +```bash |
| 59 | +# Analyze all use-case scenarios (default) |
| 60 | +pnpm bundle:analyze |
| 61 | + |
| 62 | +# Also measure individual components |
| 63 | +pnpm bundle:analyze -- --components |
| 64 | + |
| 65 | +# Analyze specific scenarios or components by name |
| 66 | +pnpm bundle:analyze -- geo dagre |
| 67 | + |
| 68 | +# Compare two report files |
| 69 | +pnpm bundle:compare -- report-new.json report-old.json |
| 70 | +``` |
| 71 | + |
| 72 | +## CI integration |
| 73 | + |
| 74 | +Two GitHub Actions workflows automate bundle tracking: |
| 75 | + |
| 76 | +- **`bundle-analysis.yml`** - Runs on PRs that touch `packages/layerchart/` or `bundle-analyzer/`. Posts a comment comparing bundle sizes against the baseline. |
| 77 | +- **`update-bundle-baseline.yml`** - Runs on pushes to `next`. If sizes changed, opens a PR to update `bundle-reports/latest.json`. |
| 78 | + |
| 79 | +## Adding scenarios |
| 80 | + |
| 81 | +Edit [`define-scenarios.ts`](./define-scenarios.ts) to add new scenarios to the `scenarios` array: |
| 82 | + |
| 83 | +```ts |
| 84 | +{ |
| 85 | + name: "my-scenario", |
| 86 | + description: "What this scenario represents", |
| 87 | + imports: ["Chart", "Svg", "MyComponent"], |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +## Output |
| 92 | + |
| 93 | +Reports are saved to `bundle-reports/`: |
| 94 | +- `latest.json` - Current baseline (committed to git) |
| 95 | +- `bundle-report-{timestamp}.json` - Timestamped snapshots (gitignored) |
0 commit comments