Skip to content

Commit 0932c68

Browse files
committed
docs(plugin-lighthouse): document multiple URLs feature
1 parent ba90832 commit 0932c68

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed

packages/plugin-lighthouse/README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,81 @@ export default {
117117
};
118118
```
119119

120+
## Multiple URLs
121+
122+
The Lighthouse plugin supports running audits against multiple URLs in a single invocation. To do this, provide an array of URLs as the first argument to the plugin:
123+
124+
```ts
125+
import lighthousePlugin from '@code-pushup/lighthouse-plugin';
126+
127+
export default {
128+
// ...
129+
plugins: [
130+
// ...
131+
await lighthousePlugin(['https://example.com', 'https://example.com/contact']),
132+
],
133+
};
134+
```
135+
136+
### Assigning weights to URLs
137+
138+
You can assign custom weights to each URL by passing an object instead of an array. The keys are URLs, and the values are their weights:
139+
140+
```ts
141+
import lighthousePlugin from '@code-pushup/lighthouse-plugin';
142+
143+
export default {
144+
// ...
145+
plugins: [
146+
// ...
147+
await lighthousePlugin({
148+
'https://example.com': 2,
149+
'https://example.com/contact': 1,
150+
})
151+
];
152+
};
153+
```
154+
155+
These weights influence how results from each URL contribute to the overall category scores.
156+
157+
### Categories with multiple URLs
158+
159+
When running Lighthouse against multiple URLs, it is recommended to use the `mergeLighthouseCategories` utility. This helper ensures that categories are correctly expanded and results are aggregated per URL, whether you provide your own custom categories or use the plugin's default categories.
160+
161+
If you provide custom categories, you can reference both groups and audits as usual. The merging utility will expand each referenced group or audit for every URL, assigning the correct per-URL weight.
162+
163+
```ts
164+
import lighthousePlugin, { lighthouseAuditRef, lighthouseGroupRef } from '@code-pushup/lighthouse-plugin';
165+
166+
const lhPlugin = await lighthousePlugin(urls);
167+
168+
export default {
169+
// ...
170+
plugins: [lhPlugin],
171+
categories: mergeLighthouseCategories(lhPlugin, [
172+
{
173+
slug: 'performance',
174+
title: 'Performance',
175+
refs: [lighthouseGroupRef('performance'), lighthouseAuditRef('first-contentful-paint', 2)],
176+
},
177+
]),
178+
};
179+
```
180+
181+
If you do not provide custom categories, you can still use the merging utility to generate categories from the plugin's groups for all URLs.
182+
183+
**How weights are assigned:**
184+
185+
- If you assign weights to URLs, those weights take precedence for each expanded reference.
186+
- If a reference (audit or group) also has a weight, it is used as a fallback.
187+
- If neither is set, a default weight of `1` is used.
188+
189+
### Behavior Summary
190+
191+
- If you provide custom categories, the plugin expands all referenced audits and groups for each URL.
192+
- If you do not provide categories, the plugin auto-generates categories from Lighthouse groups.
193+
- If you provide an empty array (`categories: []`), no categories are created or expanded.
194+
120195
## Flags
121196

122197
The plugin accepts an optional second argument, `flags`.

0 commit comments

Comments
 (0)