Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@netlify/plugin-lighthouse

netlify105kMIT6.0.1

Netlify Plugin to run Lighthouse on each build

netlify, netlify-plugin, lighthouse

readme

Netlify Plugin Lighthouse

[!IMPORTANT] Contributions and bug reports to the project are not being accepted at this time.

A Netlify plugin to generate a Lighthouse report for every deploy

Installation options

You can install the plugin for your site using your netlify.toml file or the Netlify UI.

For the most customization options, we recommend installing the Lighthouse plugin with a netlify.toml file.

netlify.toml file-based installation allows you to:

Install plugin through the Netlify UI

For UI-based installation, you can install this plugin from the Integrations Hub, the Plugins directory, or through this direct installation link.

Install plugin with a netlify.toml file

To install the plugin manually:

From your project's base directory, use npm, yarn, or any other Node.js package manager to add the plugin to devDependencies in package.json.

npm install -D @netlify/plugin-lighthouse

Then add the plugin to your netlify.toml configuration file:

[[plugins]]
  package = "@netlify/plugin-lighthouse"

  # optional, deploy the lighthouse report to a path under your site
  [plugins.inputs.audits]
    output_path = "reports/lighthouse.html"

The lighthouse scores are automatically printed to the Deploy log in the Netlify UI. For example:

2:35:07 PM: ────────────────────────────────────────────────────────────────
2:35:07 PM:   @netlify/plugin-lighthouse (onSuccess event)  
2:35:07 PM: ────────────────────────────────────────────────────────────────
2:35:07 PM: 
2:35:07 PM: Serving and scanning site from directory dist

...

2:35:17 PM: {
2:35:17 PM:   results: [
2:35:17 PM:     { title: 'Performance', score: 0.91, id: 'performance' },
2:35:17 PM:     { title: 'Accessibility', score: 0.93, id: 'accessibility' },
2:35:17 PM:     { title: 'Best Practices', score: 0.93, id: 'best-practices' },
2:35:17 PM:     { title: 'SEO', score: 0.81, id: 'seo' },
2:35:17 PM:     { title: 'Progressive Web App', score: 0.4, id: 'pwa' }
2:35:17 PM:   ]
2:35:17 PM: }

Lighthouse plugin configuration options

To customize how Lighthouse runs audits, you can make changes to the netlify.toml file.

By default, the plugin will run after your build is deployed on the live deploy permalink, inspecting the home path /. You can add additional configuration and/or inspect a different path, or multiple additional paths by adding configuration in the netlify.toml file:

[[plugins]]
  package = "@netlify/plugin-lighthouse"

  # Set minimum thresholds for each report area
  [plugins.inputs.thresholds]
    performance = 0.9

  # to audit a path other than /
  # route1 audit will use the top level thresholds
  [[plugins.inputs.audits]]
    path = "route1"

    # you can optionally specify an output_path per audit, relative to the path, where HTML report output will be saved
    output_path = "reports/route1.html"

  # to audit a specific absolute url
  [[plugins.inputs.audits]]
    url = "https://www.example.com"

    # you can specify thresholds per audit
    [plugins.inputs.audits.thresholds]
      performance = 0.8

Fail a deploy based on score thresholds

By default, the lighthouse plugin will run after your deploy has been successful, auditing the live deploy content.

To run the plugin before the deploy is live, use the fail_deploy_on_score_thresholds input to instead run during the onPostBuild event. This will statically serve your build output folder, and audit the index.html (or other file if specified as below). Please note that sites or site paths using SSR/ISR (server-side rendering or Incremental Static Regeneration) cannot be served and audited in this way.

Using this configuration, if minimum threshold scores are supplied and not met, the deploy will fail. Set the threshold based on performance, accessibility, best-practices, seo, or pwa.

[[plugins]]
  package = "@netlify/plugin-lighthouse"

  # Set the plugin to run prior to deploy, failing the build if minimum thresholds aren't set 
  [plugins.inputs]
    fail_deploy_on_score_thresholds = "true"

  # Set minimum thresholds for each report area
  [plugins.inputs.thresholds]
    performance = 0.9
    accessibility = 0.7

  # to audit an HTML file other than index.html in the build directory
  [[plugins.inputs.audits]]
    path = "contact.html"

  # to audit an HTML file other than index.html in a sub path of the build directory
  [[plugins.inputs.audits]]
    path = "pages/contact.html"

  # to serve only a sub directory of the build directory for an audit
  # pages/index.html will be audited, and files outside of this directory will not be served
  [[plugins.inputs.audits]]
    serveDir = "pages"

Run Lighthouse audits for desktop

By default, Lighthouse takes a mobile-first performance testing approach and runs audits for the mobile device experience. You can optionally run Lighthouse audits for the desktop experience by including preset = "desktop" in your netlify.toml file:

[[plugins]]
  package = "@netlify/plugin-lighthouse"

  [plugins.inputs.settings]
    preset = "desktop" # Optionally run Lighthouse using a desktop configuration

Updates to netlify.toml will take effect for new builds.

To return to running Lighthouse audits for the mobile experience, just remove the line preset = "desktop". New builds will run Lighthouse for the mobile experience.

Generate Lighthouse results in other languages

By default, Lighthouse results are generated in English. To return Lighthouse results in other languages, include the language code from any Lighthouse-supported locale in your netlify.toml file.

For the latest Lighthouse supported locales or language codes, check out this official Lighthouse code.

Updates to netlify.toml will take effect for new builds.

Example to generate Lighthouse results in Spanish

[[plugins]]
  package = "@netlify/plugin-lighthouse"

  [plugins.inputs.settings]
    locale = "es" # generates Lighthouse reports in Español

Run Lighthouse Locally

Fork and clone this repo.

Create a .env file based on the example and run

yarn install
yarn local

Preview Lighthouse results within the Netlify UI

The Netlify UI allows you to view Lighthouse scores for each of your builds on your site's Deploy Details page with a much richer format.

You'll need to first install the Lighthouse build plugin on your site.

Deploy view with Lighthouse visualizations

If you have multiple audits (e.g. multiple paths) defined in your build, we will display a roll-up of the average Lighthouse scores for all the current build's audits plus the results for each individual audit.

Deploy details with multiple audit Lighthouse results

changelog

3.2.0 (2022-08-01)

Features

  • feat: reduce summary sent to only id and score (#448) (969cc58)

6.0.1 (2024-10-21)

Bug Fixes

  • skip is-crawlable audit when running onSuccess against DEPLOY_URL (#621) (4be7b46)

6.0.0 (2024-01-30)

⚠ BREAKING CHANGES

  • mark compatible with Node v20 and up (#612)

Features

  • mark compatible with Node v20 and up (#612) (0681a72)

Bug Fixes

5.0.0 (2023-07-13)

⚠ BREAKING CHANGES

  • Run plugin on live deploy URL by default (#588)

Features

  • Run plugin on live deploy URL by default (#588) (1116f78)

4.1.1 (2023-04-21)

Bug Fixes

  • Fix chrome-launcher error preventing reports being generated (#573) (ae6e28e)

4.1.0 (2023-04-13)

Features

  • Allow plugin to run onSuccess with toml setting or env var LIGHTHOUSE_RUN_ON_SUCCESS (#570) (7de67f4)

4.0.7 (2023-01-25)

Bug Fixes

  • deps: Revert "fix(deps): Upgrade puppeteer using cache utils (#540)" (#544) (7ea7fb9)

4.0.6 (2023-01-24)

Bug Fixes

  • deps: Upgrade puppeteer using cache utils (#540) (f831eb1)

Miscellaneous Chores

  • chore: Internal refactor to use ES modules (#533) (bbb55c9)

4.0.5 (2023-01-16)

Bug Fixes

  • deps: Revert "fix(deps) upgrade puppeteer to v 19.5.2 (#532)" (#536) (a319044)

4.0.4 (2023-01-16)

Bug Fixes

  • deps: update dependency puppeteer to v19.5.2 (#532) (fa216b2)

    Miscellaneous Chores

  • deps: update dependency prettier to v2.8.2 (#530) (2adadfe)

4.0.3 (2022-11-17)

Bug Fixes

  • deps: update dependency lighthouse to v9.6.8 (#512) (1edb983)

4.0.2 (2022-10-27)

Bug Fixes

  • Surface runtime errors in Deploy Log and Deploy Summary (#505) (77ccef3)

4.0.1 (2022-10-10)

Bug Fixes

  • deps: update dependency express to v4.18.2 (#489) (5afd383)
  • deps: update dependency puppeteer to v18.2.1 (#491) (eeb38de)

4.0.0 (2022-10-07)

⚠ BREAKING CHANGES

  • The path audit input option no longer affects the served directory for an audit. Use serveDir instead. Use path to specify the sub directory or html file within the served directory that should be audited.

Features

  • Allow running lighthouse on other pages available in publish folder (#487) (ea0856b)

Bug Fixes

  • deps: update dependency dotenv to v16.0.3 (#480) (c204252)

3.7.1 (2022-10-04)

Bug Fixes

3.7.0 (2022-10-03)

Features

3.6.0 (2022-09-30)

Features

  • adds reporting around installable status and config settings (#476) (37ddec7)

3.5.0 (2022-09-29)

Features

  • Add initial support for Lighthouse settings (#474) (587f9d6)

Bug Fixes

  • adds score rounding to avoid floating point errors (#473) (8b2f4cf)
  • deps: update dependency dotenv to v16.0.2 (#462) (d76b6a6)
  • deps: update dependency lighthouse to v9.6.7 (#463) (43dfe6d)
  • deps: update dependency puppeteer to v18 (#472) (bf1c432)

3.4.1 (2022-09-21)

Bug Fixes

  • run replacements function before HTML minification (#469) (1e74d86)

3.4.0 (2022-09-21)

Features

  • Add support for theme matching and scroll reporting via postMessage (#461) (42822bc)

3.3.0 (2022-08-26)

Features

  • inject theme-querying snippets to each report (#455) (646a06d)

Bug Fixes

  • deps: update dependency lighthouse to v9.6.5 (#447) (72fe792)
  • deps: update dependency lighthouse to v9.6.6 (#456) (194b212)
  • deps: update dependency puppeteer to v16 (#451) (a0b315e)
  • deps: update dependency puppeteer to v16.2.0 (#457) (19c9ee8)

3.2.1 (2022-08-09)

Bug Fixes

3.1.0 (2022-07-27)

Features

Bug Fixes

  • deps: update dependency puppeteer to v15.4.2 (088882f)
  • deps: update dependency puppeteer to v15.5.0 (#446) (5e5ef31)

3.0.1 (2022-07-12)

Bug Fixes

3.0.0 (2022-07-07)

Features

⚠ BREAKING CHANGES

  • deps: update dependency lighthouse to v9 (#422)
  • drop support for Node 12. add support for node 16 (#422)

Bug Fixes

  • deps: update dependency express to v4.17.3 (4458347)
  • deps: update dependency puppeteer to v13.1.2 (af97807)
  • deps: update dependency puppeteer to v13.1.3 (73459cb)
  • deps: update dependency puppeteer to v13.3.1 (5a61a72)
  • deps: update dependency puppeteer to v13.4.0 (efab3d9)
  • deps: update dependency puppeteer to v13.4.1 (16cdb32)
  • deps: update dependency puppeteer to v13.5.1 (d900737)
  • deps: update dependency puppeteer to v13.5.2 (c0f07fb)
  • update changelog to reflect already released (#430) (5825fdb)

2.1.3 (2022-01-10)

Bug Fixes

  • deps: update dependency chalk to v4.1.2 (b4c1baf)
  • deps: update dependency chrome-launcher to ^0.15.0 (a04050c)
  • deps: update dependency chrome-launcher to v0.14.2 (96f4f87)
  • deps: update dependency express to v4.17.2 (94a9737)
  • deps: update dependency lighthouse to v8.2.0 (7820eee)
  • deps: update dependency lighthouse to v8.3.0 (e18ba36)
  • deps: update dependency lighthouse to v8.5.1 (12316ad)
  • deps: update dependency lighthouse to v8.6.0 (56a440f)
  • deps: update dependency puppeteer to v13 (#342) (1b44c45)

2.1.2 (2021-06-13)

Bug Fixes

  • replace http-server by express to enable gzip compression (#222) (a1962e5)

2.1.1 (2021-06-07)

Bug Fixes

  • deps: update dependency chalk to v4.1.1 (a7ef976)
  • deps: update dependency chrome-launcher to ^0.14.0 (ac5599a)
  • deps: update dependency dotenv to v10 (#206) (5fe5ce8)
  • deps: update dependency dotenv to v9 (#195) (da1fdca)
  • deps: update dependency dotenv to v9.0.2 (c10486b)
  • deps: update dependency lighthouse to v7.4.0 (852f93a)
  • deps: update dependency lighthouse to v7.5.0 (a620593)
  • deps: update dependency lighthouse to v8 (#216) (5481656)
  • deps: update dependency puppeteer to v10 (#217) (0a163bb)
  • deps: update dependency puppeteer to v9 (#185) (272ed72)

2.1.0 (2021-04-21)

Features

  • allow publishing the generated html repo (#180) (53886d5)

2.0.0 (2021-03-03)

⚠ BREAKING CHANGES

  • deps: update dependency lighthouse to v7 (#134)
  • drop support for Node 10 (#165)

Bug Fixes

  • deps: update dependency lighthouse to v7 (#134) (9ee4580)

Miscellaneous Chores

1.4.3 (2021-03-01)

Bug Fixes

  • deps: update dependency puppeteer to v7 (#153) (9da372f)
  • deps: update dependency puppeteer to v8 (#162) (d5668d0)
  • docs: align readme with plugins installation flow (fe5d80e)
  • docs: update local dev instructions (#151) (3841d96)

1.4.2 (2020-09-10)

Bug Fixes

  • report relevant error on invalid jsons (#80) (7417e91)

1.4.1 (2020-09-03)

Bug Fixes

  • use onPostBuild instead of onSuccess (#75) (e998d06)

1.4.0 (2020-07-22)

Bug Fixes

  • deps: update dependency puppeteer to v5.2.1 (#54) (176049b)

Features

  • list relevant audits on category failure (#56) (6b9a854)

1.3.2 (2020-07-13)

Bug Fixes

  • only set env.DEBUG_COLORS='true' for the plugin (#51) (b2ace7e)

1.3.1 (2020-07-13)

Bug Fixes

  • lighthouse: hide logs timestamp when running in tty (#50) (b2187ca)

1.3.0 (2020-07-12)

Features

  • support multiple audits urls and paths (#45) (74dd46d)

1.2.2 (2020-07-05)

Bug Fixes

  • deps: update dependency lighthouse to v6.1.0 (#34) (b12f94e)
  • deps: update dependency puppeteer to v4.0.1 (#35) (191c086)
  • deps: update dependency puppeteer to v5 (#39) (a1dbd9a)

1.2.1 (2020-06-21)

Bug Fixes

  • logger: pass colors=true to debug module (#30) (d54f4ae)

1.2.0 (2020-06-21)

Bug Fixes

  • deps: update dependency puppeteer to v4 (#27) (86670f2)

Features

1.1.0 (2020-06-11)

Features

1.0.1 (2020-06-11)

Bug Fixes

  • report error to failBuild (#19) (334a282)
  • package.json: add bugs and repository fields (#16) (03d957d)

1.0.0 (2020-06-10)

Bug Fixes