phyozawtun / laravel-google-lighthouse
此包为Google Lighthouse提供了Laravel的包装器,用于审计网页质量。
1.0.2
2023-06-23 16:35 UTC
Requires
- php: ^8.0
- illuminate/config: ^8|^9|^10
- illuminate/support: ^8|^9|^10
- symfony/process: ^5|^6
This package is auto-updated.
Last update: 2024-09-23 19:18:18 UTC
README
此包为Google Lighthouse提供了Laravel的包装器,用于审计网页质量。
安装
您可以通过Composer安装此包
composer require phyozawtun/laravel-google-lighthouse
包将自动注册自身。可选地,您可以使用以下命令发布配置文件:
php artisan vendor:publish --provider="Logiek\GoogleLighthouse\GoogleLighthouseServiceProvider" --tag="config"
使用方法
以下示例将执行默认的Google Lighthouse审计并将结果存储在指定的路径中。
use Logiek\GoogleLighthouse\GoogleLighthouse; (new GoogleLighthouse()) ->setOutput('report.html') ->audit('http://example.com');
类别
默认情况下,审计将运行所有可用的类别。要为特定列表的类别运行审计,您可以在以下示例中指定审计应运行的类别,任何缺少的类别将被跳过。
可用的类别有:performance
(性能)、pwa
(渐进式Web应用程序)、bestPractices
(最佳实践)、accessibility
(无障碍性)和seo
(搜索引擎优化)。
use Logiek\GoogleLighthouse\GoogleLighthouse; (new GoogleLighthouse()) ->performance() ->pwa() ->setOutput('report.html') ->audit('http://example.com');
输出
setOutput
方法接受第二个参数,可用于指定格式(基于配置)。如果省略格式参数,则使用文件扩展名来确定输出格式。如果文件扩展名没有指定受支持的格式,将抛出异常。
对于示例,以下代码将创建两个报告:example.report.html和example.report.json。
use Logiek\GoogleLighthouse\GoogleLighthouse; (new GoogleLighthouse()) ->setOutput('example', ['html', 'json']) ->audit('http://example.com');
选项
setOption
方法可用于指定某些选项,以根据您的喜好调整Google Lighthouse。
use Logiek\GoogleLighthouse\GoogleLighthouse; (new GoogleLighthouse()) ->setOption('--throttling.cpuSlowdownMultiplier', 4) ->setOutput('report.html') ->audit('http://example.com');
变更日志
有关最近更改的更多信息,请参阅CHANGELOG。
许可证
本项目是开源软件,根据MIT许可证授权。