Lighthouse CI 使用教程

Lighthouse CI 使用教程

lighthouse-ciA useful wrapper around Google Lighthouse CLI项目地址:https://gitcode.com/gh_mirrors/lig/lighthouse-ci

1、项目介绍

Lighthouse CI 是一个用于在持续集成(CI)过程中使用 Lighthouse 的工具套件。Lighthouse 是一个开源的自动化工具,用于提高网页质量,它提供了多种网页性能指标,包括性能、可访问性、最佳实践、SEO 和 PWA。Lighthouse CI 通过一系列工具,使得在 CI 过程中持续运行、保存、检索和断言 Lighthouse 结果变得非常容易。

2、项目快速启动

安装 Lighthouse CI CLI

首先,你需要在本地安装 Lighthouse CI CLI。你可以通过 npm 来安装:

npm install -g @lhci/cli

配置 lighthouserc.js

在你的项目根目录下创建一个 lighthouserc.js 文件,并添加以下配置:

module.exports = {
  ci: {
    collect: {
      staticDistDir: './dist',
    },
    upload: {
      target: 'temporary-public-storage',
    },
  },
};

运行 Lighthouse CI

在你的项目根目录下运行以下命令来执行 Lighthouse CI:

lhci autorun

3、应用案例和最佳实践

应用案例

Lighthouse CI 可以集成到 GitHub Actions 中,自动在每次 Pull Request 时运行 Lighthouse 测试,并在 PR 中显示结果。以下是一个简单的 GitHub Actions 配置示例:

name: CI
on: [push]
jobs:
  lighthouseci:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - uses: actions/setup-node@v3
        with:
          node-version: 18
      - run: npm install && npm install -g @lhci/cli@0.14.x
      - run: npm run build
      - run: lhci autorun

最佳实践

  1. 持续监控:使用 Lighthouse CI 持续监控你的网页性能,确保每次代码变更不会导致性能下降。
  2. 性能预算:设置性能预算,确保你的网页在性能方面始终保持在可接受的水平。
  3. 减少变量:通过多次运行 Lighthouse 测试来减少结果的变量,确保测试结果的准确性。

4、典型生态项目

Lighthouse CI GitHub Action

这是一个 GitHub Action,可以在每次 Pull Request 时自动运行 Lighthouse CI,无需额外的基础设施。

Lighthouse CI Starter Example

这是一个最小化的示例仓库,你可以将其用作从头开始的模板,提供了一个使用 create-react-app 的初学者友好的快速启动指南。

Community Guides

社区编写的一系列非官方博客文章、教程和指南,帮助你更好地使用 Lighthouse CI。


通过以上步骤,你可以快速上手并使用 Lighthouse CI 来持续监控和提升你的网页性能。

lighthouse-ciA useful wrapper around Google Lighthouse CLI项目地址:https://gitcode.com/gh_mirrors/lig/lighthouse-ci

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

范垣楠Rhoda

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值