Skip to content

Commit a061df3

Browse files
committed
feat(performance): add bundle analyzer and lighthouse performance metric
1 parent b35c73b commit a061df3

6 files changed

Lines changed: 244 additions & 1 deletion

File tree

.github/workflows/lighthouse.yml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: Lighthouse CI
2+
3+
on:
4+
push:
5+
branches: [master, main]
6+
pull_request:
7+
branches: [master, main]
8+
9+
jobs:
10+
lighthouse:
11+
name: Lighthouse Performance Audit
12+
runs-on: ubuntu-latest
13+
if: github.server_url == 'https://github.com'
14+
steps:
15+
- uses: actions/checkout@v4
16+
17+
- name: Setup pnpm
18+
uses: pnpm/action-setup@v4
19+
with:
20+
version: 9
21+
22+
- name: Setup Node.js
23+
uses: actions/setup-node@v4
24+
with:
25+
node-version: '20'
26+
cache: 'pnpm'
27+
28+
- name: Install dependencies
29+
run: pnpm install --frozen-lockfile
30+
31+
- name: Build project
32+
run: pnpm build
33+
34+
- name: Run Lighthouse CI
35+
uses: treosh/lighthouse-ci-action@v12
36+
with:
37+
urls: |
38+
http://localhost:3000
39+
http://localhost:3000/docs
40+
uploadArtifacts: true
41+
temporaryPublicStorage: true
42+
runs: 3

.lighthouserc.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Alternative JS config for more flexibility
2+
module.exports = {
3+
ci: {
4+
collect: {
5+
startServerCommand: 'pnpm start',
6+
startServerReadyPattern: 'Ready',
7+
url: ['http://localhost:3000', 'http://localhost:3000/docs'],
8+
numberOfRuns: 3,
9+
},
10+
assert: {
11+
preset: 'lighthouse:recommended',
12+
assertions: {
13+
'categories:performance': ['error', { minScore: 0.8 }],
14+
'categories:accessibility': ['error', { minScore: 0.9 }],
15+
'categories:best-practices': ['error', { minScore: 0.9 }],
16+
'categories:seo': ['error', { minScore: 0.9 }],
17+
},
18+
},
19+
upload: {
20+
target: 'temporary-public-storage',
21+
},
22+
},
23+
}

lighthouserc.json

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
{
2+
"ci": {
3+
"collect": {
4+
"startServerCommand": "pnpm start",
5+
"startServerReadyPattern": "Ready",
6+
"url": [
7+
"http://localhost:3000",
8+
"http://localhost:3000/docs"
9+
],
10+
"numberOfRuns": 3
11+
},
12+
"assert": {
13+
"preset": "lighthouse:recommended",
14+
"assertions": {
15+
"categories:performance": ["error", { "minScore": 0.8 }],
16+
"categories:accessibility": ["error", { "minScore": 0.9 }],
17+
"categories:best-practices": ["error", { "minScore": 0.9 }],
18+
"categories:seo": ["error", { "minScore": 0.9 }]
19+
}
20+
},
21+
"upload": {
22+
"target": "temporary-public-storage"
23+
}
24+
}
25+
}

next.config.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,9 @@ const nextConfig: NextConfig = {
44
/* config options here */
55
}
66

7-
export default nextConfig
7+
// Bundle analyzer configuration
8+
const withBundleAnalyzer = require('@next/bundle-analyzer')({
9+
enabled: process.env.ANALYZE === 'true',
10+
})
11+
12+
export default withBundleAnalyzer(nextConfig)

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"scripts": {
1111
"dev": "next dev --turbopack",
1212
"build": "next build",
13+
"build:analyze": "cross-env ANALYZE=true next build",
1314
"start": "next start",
1415
"lint": "next lint",
1516
"format": "prettier --write .",
@@ -60,13 +61,15 @@
6061
"zod": "^3.25.76"
6162
},
6263
"devDependencies": {
64+
"@next/bundle-analyzer": "^15.5.2",
6365
"@commitlint/cli": "^20.1.0",
6466
"@commitlint/config-conventional": "^20.0.0",
6567
"@eslint/eslintrc": "^3.3.1",
6668
"@tailwindcss/postcss": "^4.1.11",
6769
"@types/node": "^20.19.9",
6870
"@types/react": "19.1.2",
6971
"@types/react-dom": "19.1.2",
72+
"cross-env": "^7.0.3",
7073
"eslint": "^9.32.0",
7174
"eslint-config-next": "15.3.1",
7275
"husky": "^9.1.7",

0 commit comments

Comments
 (0)