Skip to content

Commit 64c178f

Browse files
committed
Add RelativeCI for bundle size monitoring
1 parent 14092ec commit 64c178f

File tree

4 files changed

+50
-13
lines changed

4 files changed

+50
-13
lines changed

.github/workflows/test.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,18 @@ jobs:
3939
- uses: ./.github/actions/setup-test-env
4040
- name: Check dependency versions
4141
run: pnpm check-dependency-versions
42+
bundle-sizes:
43+
runs-on: ubuntu-latest
44+
steps:
45+
- uses: actions/checkout@v3
46+
- uses: ./.github/actions/setup-test-env
47+
- name: Build all packages (so they can require each other)
48+
run: pnpm build
49+
- name: Build test bundles
50+
run: pnpm -F=test-bundles test-build
51+
- name: Send bundle stats to RelativeCI
52+
uses: relative-ci/agent-action@v2
53+
with:
54+
webpackStatsFile: ./packages/test-bundles/dist/react-read-webpack-stats.json
55+
key: ${{ secrets.RELATIVE_CI_KEY }}
56+
token: ${{ secrets.GITHUB_TOKEN }}

packages/test-bundles/build.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import react from "@vitejs/plugin-react-swc";
2+
import { webpackStats } from "rollup-plugin-webpack-stats";
3+
24
import fs from "fs";
35
import { join, parse } from "path";
46
import { visualizer } from "rollup-plugin-visualizer";
@@ -7,20 +9,27 @@ import { build } from "vite";
79

810
const bundleDir = fileURLToPath(new URL("bundles", import.meta.url));
911
const entrypoints = fs.readdirSync(bundleDir);
10-
12+
console.log(entrypoints);
1113
for (const entrypoint of entrypoints) {
1214
const parsed = parse(entrypoint);
1315
const name = parsed.name;
1416

15-
const visualizerPlugin = visualizer({
16-
emitFile: true,
17-
filename: `${name}-stats.html`,
18-
template: "treemap",
19-
brotliSize: true,
20-
gzipSize: true,
21-
}) as any;
17+
const plugins = [
18+
// Output webpack-stats.json file
19+
webpackStats({ fileName: `${name}-webpack-stats.json` }),
20+
// Output visualized bundle stats for developers
21+
visualizer({
22+
emitFile: true,
23+
filename: `${name}-stats.html`,
24+
template: "treemap",
25+
brotliSize: true,
26+
gzipSize: true,
27+
}) as any,
28+
];
2229

23-
const plugins = parsed.ext.endsWith("x") ? [react(), visualizerPlugin] : [visualizerPlugin];
30+
if (parsed.ext.endsWith("x")) {
31+
plugins.push(react());
32+
}
2433

2534
await build({
2635
plugins,

packages/test-bundles/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
"vite": "^4.4.7"
2020
},
2121
"devDependencies": {
22-
"rollup-plugin-visualizer": "^5.9.2"
22+
"rollup-plugin-visualizer": "^5.9.2",
23+
"rollup-plugin-webpack-stats": "^0.2.1"
2324
}
2425
}

pnpm-lock.yaml

Lines changed: 15 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)