Skip to content

Commit 34cd90c

Browse files
feat: add bundle size tracking GH Actions workflow
1 parent feec2c4 commit 34cd90c

File tree

4 files changed

+119
-2
lines changed

4 files changed

+119
-2
lines changed
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
on:
2+
pull_request:
3+
paths:
4+
- 'packages/toolbar/**'
5+
- '**/package.json'
6+
- 'pnpm-lock.yaml'
7+
name: Toolbar bundle size diff
8+
9+
jobs:
10+
build-head-stats:
11+
name: 'Build head (bundle stats)'
12+
runs-on: ubuntu-latest
13+
timeout-minutes: 15
14+
steps:
15+
- uses: actions/checkout@v4
16+
- name: Setup pnpm
17+
uses: pnpm/action-setup@v4
18+
- name: Setup Node.js
19+
uses: actions/setup-node@v4
20+
with:
21+
node-version: '23'
22+
cache: 'pnpm'
23+
- name: Install dependencies
24+
run: pnpm install --frozen-lockfile
25+
- name: Build toolbar and generate bundle analysis
26+
working-directory: packages/toolbar
27+
env:
28+
NODE_OPTIONS: '--max-old-space-size=4096'
29+
run: |
30+
# Build with bundle analysis and generate stats file
31+
pnpm build:analyze
32+
- name: Upload bundle analysis artifacts
33+
uses: actions/upload-artifact@v4
34+
if: ${{ !cancelled() }}
35+
with:
36+
name: head-toolbar-bundle-stats
37+
path: packages/toolbar/rspack-stats.json
38+
if-no-files-found: error
39+
40+
build-base-stats:
41+
name: 'Build base (bundle stats)'
42+
runs-on: ubuntu-latest
43+
timeout-minutes: 15
44+
steps:
45+
- uses: actions/checkout@v4
46+
with:
47+
ref: ${{ github.base_ref }}
48+
- name: Setup pnpm
49+
uses: pnpm/action-setup@v4
50+
- name: Setup Node.js
51+
uses: actions/setup-node@v4
52+
with:
53+
node-version: '23.5.0'
54+
cache: 'pnpm'
55+
- name: Install dependencies
56+
run: pnpm install --frozen-lockfile
57+
- name: Build toolbar and generate bundle analysis
58+
working-directory: packages/toolbar
59+
env:
60+
NODE_OPTIONS: '--max-old-space-size=4096'
61+
run: |
62+
# Build with bundle analysis and generate stats file
63+
pnpm build:analyze
64+
- name: Upload bundle analysis artifacts
65+
uses: actions/upload-artifact@v4
66+
if: ${{ !cancelled() }}
67+
with:
68+
name: base-toolbar-bundle-stats
69+
path: packages/toolbar/rspack-stats.json
70+
if-no-files-found: error
71+
72+
compare-bundle-sizes:
73+
name: 'Compare toolbar bundle sizes'
74+
runs-on: ubuntu-latest
75+
needs: [build-base-stats, build-head-stats]
76+
steps:
77+
- uses: actions/checkout@v4
78+
- name: Download base bundle artifacts
79+
uses: actions/download-artifact@v4
80+
with:
81+
name: base-toolbar-bundle-stats
82+
path: base-stats
83+
- name: Download head bundle artifacts
84+
uses: actions/download-artifact@v4
85+
with:
86+
name: head-toolbar-bundle-stats
87+
path: head-stats
88+
- name: Compare toolbar bundle sizes
89+
uses: launchdarkly-labs/webpack-bundle-diff-action@c903b35abed2d2315a06128757cb5c80a6b7abca # pin@main
90+
with:
91+
github-token: ${{ secrets.GITHUB_TOKEN }}
92+
base-bundle-analysis-report-path: ./base-stats/rspack-stats.json
93+
head-bundle-analysis-report-path: ./head-stats/rspack-stats.json
94+
increase-label: '⚠️ toolbar bundle increase'
95+
decrease-label: '🎉 toolbar bundle decrease'
96+
# No bundle size budgets - just track changes for now
97+
should-block-pr-on-exceeded-budget: false
98+
skip-comment-on-no-changes: true

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ node_modules
88
dist/
99
storybook-static
1010

11+
# Bundle analysis
12+
rspack-stats.json
13+
bundle-analyzer-report.json
14+
1115
# IDE
1216
.vscode/*
1317
!.vscode/extensions.json

packages/toolbar/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
],
4949
"scripts": {
5050
"build": "rslib build && node ../../scripts/fix-base-url.cjs dist/js/index.js",
51+
"build:analyze": "ANALYZE_BUNDLE=true rslib build && cp dist/bundle-analyzer-report.json ./rspack-stats.json",
5152
"dev": "rslib build --watch",
5253
"test": "vitest run",
5354
"lint": "oxlint",
@@ -81,7 +82,8 @@
8182
"@storybook/test": "^9.0.0-alpha.2",
8283
"typescript": "^5.8.3",
8384
"vitest": "^3.2.2",
84-
"webpack": "5.101.3"
85+
"webpack": "5.101.3",
86+
"webpack-bundle-analyzer": "^4.10.2"
8587
},
8688
"peerDependencies": {
8789
"launchdarkly-js-client-sdk": "^3.9.0",

packages/toolbar/rslib.config.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { pluginReact } from '@rsbuild/plugin-react';
22
import { defineConfig } from '@rslib/core';
33
import { VanillaExtractPlugin } from '@vanilla-extract/webpack-plugin';
4+
import { BundleAnalyzerPlugin } from 'webpack-bundle-analyzer';
45

56
export default defineConfig({
67
source: {
@@ -32,7 +33,19 @@ export default defineConfig({
3233
plugins: [pluginReact()],
3334
tools: {
3435
rspack: {
35-
plugins: [new VanillaExtractPlugin()],
36+
plugins: [
37+
new VanillaExtractPlugin(),
38+
...(process.env.ANALYZE_BUNDLE === 'true'
39+
? [
40+
new BundleAnalyzerPlugin({
41+
analyzerMode: 'json',
42+
reportFilename: 'bundle-analyzer-report.json',
43+
openAnalyzer: false,
44+
}),
45+
]
46+
: []),
47+
],
48+
stats: process.env.ANALYZE_BUNDLE === 'true' ? 'verbose' : 'normal',
3649
},
3750
},
3851
});

0 commit comments

Comments
 (0)