All jobs

Add Lighthouse CI to a Vite React App

Yes. An agent builds your Vite React app, audits the preview with Lighthouse CI while the API is mocked, sets budgets from measured scores and adds a PR workflow.

Run this on RushOpens the console with this prompt ready to send, in a Project that has your repository.

What the agent does

The agent reads how the app builds, serves and talks to its API before it audits anything, because a Lighthouse score of a page that cannot load its data is noise. In the apps/react-vite application of alan2207/bulletproof-react, yarn build runs tsc && vite build --base=/, vite.config.ts sets base: './', serves preview on port 3000 and tells Rollup to split with experimentalMinChunkSize, and index.html loads the Inter font from rsms.me before the /src/main.tsx module. src/main.tsx calls enableMocking() from src/testing/mocks before it renders, and .env.example sets VITE_APP_ENABLE_API_MOCKING=true with the API URL, so a build made from that file serves its own data through public/mockServiceWorker.js and needs no backend. That is the configuration the agent audits: it is what .github/workflows/react-vite-ci.yml already builds in its all-cli-checks job after mv .env.example .env, while the e2e job uses .env.example-e2e and a separate mock server on port 8080 for Playwright.

Routing decides which pages to measure. src/app/router.tsx lazy-loads / from routes/landing.tsx, /auth/login and /auth/register, and everything under /app behind authentication, with react-router 7. The landing, login and register pages are reachable without a session, so the agent audits those three; the dashboard, discussions and users routes need the registration flow that e2e/tests/auth.setup.ts walks through in Playwright, and the agent leaves them out of this pass and says so rather than auditing a redirect to the login page.

It adds @lhci/cli as a dev dependency and a lighthouserc.cjs whose collect section starts yarn preview, waits for port 3000, runs each of the three URLs three times, and whose assert section is written from what it measured: it runs the audit in its sandbox with headless Chrome, reads the median performance, accessibility, best-practices and SEO scores per page, and sets each category's minimum a little below the median so a normal run passes and a regression fails, instead of the lighthouse:recommended preset, which fails on the external font request alone. upload.target is temporary-public-storage, which puts a report link in the check; the pull request notes that this uploads the report to a public URL and shows the filesystem target with an artifact upload as the private alternative.

The workflow change is a third job in react-vite-ci.yml, with the same working-directory, Node and .env.example steps as the first, that builds and runs npx lhci autorun. The agent adds .lighthouseci/ to the ignore file and documents the budget numbers in the config next to the medians they came from, so the next person who tightens them knows the baseline.

Start it with one API call

POST https://api.phoenix.so/o/{org}/sessions with this body:

{
  "agent": "claude",
  "input": "Add Lighthouse CI to the Vite React app in this repository. Read package.json, vite.config.ts, index.html, src/main.tsx, src/app/router.tsx, the .env.example files and the existing CI workflow first. Audit the production build served by vite preview with API mocking enabled, on the landing, login and register routes, three runs each. Run the audit in your sandbox, set per-category score assertions from the medians you measure rather than a preset, use a report upload target and say what it exposes, and add a Lighthouse job to the existing workflow with the same working directory, Node version and env file steps. Open a pull request that lists the measured scores and the budgets you set.",
  "resources": [
    {
      "url": "https://github.com/your-org/your-app"
    }
  ]
}
  1. Get an API key. In the console, open Settings, then API keys, and create a key for your org. Send it in the Authorization header as a Bearer token.
  2. Send the request. POST the body in request.json to https://api.phoenix.so/o/{org}/sessions, with your repository as the resources URL. The run starts in its own cloud sandbox.
  3. Read what came back. Follow the run on its live stream or wait for the run.completed webhook, then read the result and its trajectory.

What comes back

What comes back is a pull request on its own branch adding apps/react-vite/lighthouserc.cjs, a lighthouse job in .github/workflows/react-vite-ci.yml, @lhci/cli in devDependencies with yarn.lock updated, and an ignore entry for .lighthouseci/. No source file under src/ and nothing in the other two apps changes.

The description holds a table of the median scores per route and category from the sandbox audit, the budget set for each and the margin between them, a sentence on why the external font request keeps the performance score below the preset's bar, and the upload target with what it publishes. It also names the authenticated routes it skipped and what a follow-up would need to audit them.

Before merging, a reviewer runs the job once on the pull request to see how much the scores move on GitHub's runners, loosens a budget that sits too close to the runner's variance, and decides between the public report link and the artifact upload.

Run it on every new Vite app in your organization

A handler on your server receives GitHub's organization repository event, since GitHub signs its webhooks and cannot add the Authorization header a Rush webhook trigger needs, checks the signature and, when the new repository has a vite.config.ts, sends this body to POST /o/{org}/sessions with the repository in resources. It sends a request_id that is a UUID v5 of the delivery id, so a redelivery returns the run already started.

With a webhook_url on the key, Rush POSTs run.completed when the turn ends, and the handler reads the pull request from the session and posts it to the team that owns the repository. Each new app then starts with a Lighthouse budget measured from its own first build rather than copied from another project.

The use case this job follows, with its automation and trigger: Hand off a long task.

Why run it on Rush?

Lighthouse CI is easy to add and easy to make useless: audit a page that cannot load its API and every score is a loading spinner; take the recommended preset and the first pull request fails on a font. The agent reads the mocking switch, the router and the existing workflow, audits the pages that actually render, and sets budgets from numbers it measured.

On Rush the build, the preview server and headless Chrome run in the agent's own sandbox, and the transcript keeps the audit output the budgets came from, so a reviewer can see the baseline rather than take it on trust. Many front ends can get their own measured budget at once, each in its own sandbox with its own pull request.

Frequently asked questions

Why audit with API mocking on?

Because the production build with VITE_APP_ENABLE_API_MOCKING=true serves its own data through the service worker and renders complete pages with no backend, which is what the existing CI builds. Auditing against a live API would make the scores depend on that API's latency and on credentials the runner does not have.

Why not the lighthouse:recommended preset?

It fails on things the app does on purpose, such as the Inter font loaded from rsms.me, so every run would be red from day one. Budgets set a little under the measured medians pass today and fail on a regression, and the config records the medians so they can be tightened deliberately.

Are the authenticated routes audited?

Not in this pass. Pages under /app redirect to the login page without a session, so auditing them would measure the login page twice. A follow-up can reuse the registration steps from the Playwright setup to obtain a session and add those URLs.

Where does the report go?

With temporary-public-storage the report is uploaded to a public URL that the check links to, which is convenient and visible to anyone with the link. The pull request shows the filesystem target with an upload-artifact step as the alternative that keeps reports inside the repository's Actions.

More Vite + React jobs

The same job on other stacks

Keep reading