Skip to content

Commit 656ba01

Browse files
authored
Add size-limit bundle-size checks on PRs
Add size-limit with `@size-limit/preset-small-lib` to enforce a 160 kB budget on the main entry point. A GitHub Actions workflow builds the project on each PR, runs size-limit from local node_modules (bypassing npx version mismatch with the old andresz1 action), and posts a comment with current sizes. Fails the check if any budget is exceeded. Closes #11
1 parent 38b9d55 commit 656ba01

4 files changed

Lines changed: 1455 additions & 218 deletions

File tree

.github/workflows/size.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
# Bundle-size check for pull requests.
2+
#
3+
# Runs size-limit from local node_modules (avoids npx version mismatch).
4+
# Posts a PR comment with current sizes and fails if any budget is exceeded.
5+
6+
name: Size
7+
8+
on:
9+
pull_request:
10+
types: [opened, synchronize, reopened]
11+
branches: [main]
12+
13+
permissions:
14+
contents: read
15+
pull-requests: write
16+
17+
jobs:
18+
size:
19+
name: Bundle size
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout
23+
uses: actions/checkout@v6
24+
with:
25+
persist-credentials: false
26+
27+
- name: Set up Node.js
28+
uses: actions/setup-node@v6
29+
with:
30+
node-version: "22"
31+
cache: npm
32+
33+
- name: Install dependencies
34+
run: npm ci
35+
36+
- name: Build
37+
run: npm run build
38+
39+
- name: Check bundle size
40+
id: size
41+
run: |
42+
./node_modules/.bin/size-limit --json > size-output.json
43+
cat size-output.json
44+
45+
- name: Post size comment
46+
if: always() && steps.size.conclusion != 'skipped'
47+
uses: actions/github-script@v7
48+
with:
49+
script: |
50+
const fs = require('fs');
51+
if (!fs.existsSync('size-output.json')) return;
52+
let results;
53+
try { results = JSON.parse(fs.readFileSync('size-output.json', 'utf8')); }
54+
catch { return; }
55+
const rows = results.map(r => {
56+
const status = r.exceeded ? '❌' : '✅';
57+
const size = r.size != null ? `${(r.size / 1024).toFixed(1)} kB` : 'n/a';
58+
const limit = r.sizeLimit || 'none';
59+
return `| ${r.name || r.path} | ${size} | ${limit} | ${status} |`;
60+
}).join('\n');
61+
const body = `## Bundle size\n\n| Entry | Size | Budget | Status |\n|-------|------|--------|--------|\n${rows}`;
62+
await github.rest.issues.createComment({
63+
owner: context.repo.owner,
64+
repo: context.repo.repo,
65+
issue_number: context.issue.number,
66+
body
67+
});

.size-limit.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export default [
2+
{
3+
path: "dist/index.js",
4+
limit: "160 kB",
5+
modifyEsbuildConfig(config) {
6+
config.platform = "node";
7+
return config;
8+
},
9+
},
10+
];

0 commit comments

Comments
 (0)