adityadees/laravel-lighthouse

laravel 框架的包装器,可以让你更容易地运行 Google Lighthouse 来审计网站。

v1.0.0 2023-04-22 09:03 UTC

This package is auto-updated.

Last update: 2024-09-17 18:41:29 UTC


README

laravel 框架的 Google Lighthouse 包装器,可以让你更容易地运行 Google Lighthouse 来审计网站。已完成的审计结果将自动保存到你的服务器目录中。

运行 composer require adityadees/laravel-lighthouse 然后 php artisan vendor:publish --tag=laravel-lighthouse

在开始使用此包之前,您需要在 config/laravel-lighthouse.php 中定义变量作为全局配置

要使用它,您可以运行

# $url = optional, you can using global config or override it to this variable
# $device = optional, if blank will scan both, mobile and desktop mode
$lighouse = (new LaravelLighthouse())->run($url,$device);

// using default config option
$lighouse = (new LaravelLighthouse())->run();

// run both mobile and desktop
$lighouse = (new LaravelLighthouse())->run('https://adityadees.com');

// run only mobile
$lighouse = (new LaravelLighthouse())->run('https://adityadees.com', 'mobile');

// run only desktop
$lighouse = (new LaravelLighthouse())->run('https://adityadees.com', 'desktop');

// run only mobile with global url defined on config
$lighouse = (new LaravelLighthouse())->run('', 'mobile');

// run only desktop with global url defined on config
$lighouse = (new LaravelLighthouse())->run('', 'desktop');

或者您可以使用自己的自定义配置,例如

# $url = optional, you can using global config or override it to this variable
# $flag = optional, you can use the config or define it on here
# $device = optional, if blank will scan both, mobile and desktop mode
$lighouse = (new LaravelLighthouse())->selfConfiguration($url,$flag,$device);


// using self configuration with config as default
$lighouse = (new LaravelLighthouse())->selfConfiguration('https://adityadees.com');

// run self configuration with override url, flag and both device
$lighouse = (new LaravelLighthouse())->selfConfiguration('https://adityadees.com', '--chrome-flags="--headless --no-sandbox --disable-gpu" --output html --output json --output-path ' . base_path() . '/public/laravel-lighthouse/mobile/result.html');

// run self configuration with override url, flag and device to mobile mode
$lighouse = (new LaravelLighthouse())->selfConfiguration('https://adityadees.com', '--chrome-flags="--headless --no-sandbox --disable-gpu" --output html --output json --output-path ' . base_path() . '/public/laravel-lighthouse/mobile/result.html', 'mobile');

// run self configuration with override url, flag and device to dekstop mode
$lighouse = (new LaravelLighthouse())->selfConfiguration('https://adityadees.com', '--chrome-flags="--headless --no-sandbox --disable-gpu" --preset=desktop --output html --output json --output-path ' . base_path() . '/public/laravel-lighthouse/desktop/result.html', 'desktop');

有关标志的更多信息,您可以访问 https://github.com/GoogleChrome/lighthouse

如果您遵循配置示例,结果应该像这样

  • public 文件夹中,您可以看到结果 .html.json

https://github.com/adityadees/laravel-lighthouse/tree/docs/example-results/laravel-lighthouse

image

如果您打开 .html,您可以看到这样的结果

桌面

image

移动 image