lighthouse/build
Connor Clark 8a2f18a025
clients(devtools): require third-party-web to be provided (#16166)
2024-09-04 17:21:17 -07:00
..
changelog-generator misc: adopt minimal license headers (#15456) 2023-09-15 16:49:41 -07:00
plugins misc: adopt minimal license headers (#15456) 2023-09-15 16:49:41 -07:00
test misc: adopt minimal license headers (#15456) 2023-09-15 16:49:41 -07:00
build-bundle.js clients(devtools): require third-party-web to be provided (#16166) 2024-09-04 17:21:17 -07:00
build-cdt-lib.js misc: adopt minimal license headers (#15456) 2023-09-15 16:49:41 -07:00
build-cdt-strings.js misc: adopt minimal license headers (#15456) 2023-09-15 16:49:41 -07:00
build-dt-report-resources.js misc: adopt minimal license headers (#15456) 2023-09-15 16:49:41 -07:00
build-extension.js clients(extension): add locale selector (#15574) 2023-10-27 17:35:07 -07:00
build-lightrider-bundles.js misc: adopt minimal license headers (#15456) 2023-09-15 16:49:41 -07:00
build-pack.sh
build-report-components.js misc: adopt minimal license headers (#15456) 2023-09-15 16:49:41 -07:00
build-report.js misc: adopt minimal license headers (#15456) 2023-09-15 16:49:41 -07:00
build-sample-reports.js core: remove budgets (#15950) 2024-04-17 11:25:54 -07:00
build-smokehouse-bundle.js misc: adopt minimal license headers (#15456) 2023-09-15 16:49:41 -07:00
build-treemap.js misc: adopt minimal license headers (#15456) 2023-09-15 16:49:41 -07:00
build-viewer.js misc: adopt minimal license headers (#15456) 2023-09-15 16:49:41 -07:00
esbuild-plugins.js misc: adopt minimal license headers (#15456) 2023-09-15 16:49:41 -07:00
gh-pages-app.js clients(viewer): fix preload links (#15515) 2023-10-04 11:00:43 -07:00
process-global.js misc(build): replace rollup with esbuild (#15239) 2023-07-14 15:32:02 -07:00
readme.md docs: update explainer for devtools build (#15414) 2023-09-06 12:35:47 -07:00

readme.md

Building Lighthouse

Lighthouse is built into browser-friendly bundles for two clients:

  • Chrome DevTools (CDT) Lighthouse Panel
  • Lightrider, the backend of PageSpeed Insights

Additionally, there are build processes for:

Building for DevTools

To build the Lighthouse bundle for CDT and roll them into a local checkout of the CDT repo:

yarn devtools

One of the commands that the above runs - yarn build-devtools - creates these files:

dist
├── dt-report-resources
│   ├── report-generator.mjs
│   └── report-generator.mjs.d.ts
├── lighthouse-dt-bundle.js
├── lighthouse-dt-bundle.js.map
└── report
    ├── bundle.esm.js
  1. the biggest file is lighthouse-dt-bundle.js. This is a bundle of core via clients/devtools/devtools-entry.js, and is run inside a worker in CDT.
  2. the much smaller report-generator.mjs bundle. This is assigned to the global object as Lighthouse.ReportGenerator
    • This bundle has inlined the dist/report/standalone.js and standalone-template.html files (these are not transformed in any way). We call these the report generator assets.
    • report-generator.mjs.d.ts is an empty type definition file to make the CDT build happy
  3. Finally, report/bundle.esm.js is an ES modules bundle of the report code (note: this is copied to CDT as report/bundle.js).

How the Lighthouse Panel uses the Lighthouse CDT build artifacts

[LighthouseWorkerService](https://source.chromium.org/chromium/chromium/src/+/main:third_party/devtools-frontend/src/front_end/entrypoints/lighthouse_worker/LighthouseWorkerService.ts) uses self.navigation, one of the exports of lighthouse-dt-bundle.js. It also uses the other Lighthouse modes based on what the user selects in the Lighthouse Panel.

LighthousePanel uses LighthouseReportRenderer, which wraps LighthouseReport.renderReport, (defined here) which is exported by report.js. This renderer takes a Lighthouse result and a rootEl DOM element - it then renders the report to the target element. The CSS used by the report is embedded inside bundle.esm.js and is injected by the ReportRenderer via a call to dom.createComponent('styles').

A Lighthouse report (including what is shown within the Lighthouse panel) can also Export as HTML. Normally the report just uses documentElement.outerHTML, but from DevTools we get quine-y and use Lighthouse.ReportGenerator. This generator is defined in report-generator.js.

report-generator.js takes a Lighthouse result and creates an HTML file - it concats all of the report generator assets to create a standalone HTML document. See: ee3a9dfd66/core/report/report-generator.js (L35) . Normally when run in Node.js the report assets (JavaScript, which also contains the css; and the html template) are read from disk. But in DevTools, these assets have been inlined in the report-generator.mjs bundle.

In short, a Lighthouse report is rendered in two ways inside DevTools:

  1. The LighthousePanel presents a report to the user via: the renderer as exported by bundle.esm.js. This file has inlined all the CSS and JS necessary to render a report.

  2. The Lighthouse report exposes a "Save as HTML" feature: we can't scrape the outerHTML like we normally do, because we render some things a bit special for DevTools, and we're not the only thing in that DOM (we would get all of DevTools). So we override the getReportHtml function in the renderer here to instead use Lighthouse.ReportGenerator, as defined by report-generator.js.