0

我正在尝试执行与此灯塔命令等效的操作,但我不知道如何操作。

lighthouse --config-path=custom-config.js https://www.example.com

有没有人有任何示例可以分享,关于如何以编程方式为灯塔设置自定义配置文件(带有自定义收集器和审计)?

4

1 回答 1

0

我自己找到了答案,所以我把它贴在下面:

// This how I call lighthouse programmatically
const lhr = await lighthouse(url, config.lighthouseFlags, config.lighthouseConfigs);

var url = "https://www.example.com";
var config = {};
// The 2nd parameter in the lighthouse function is some of the flags you can pass to lighthouse. I'm posting a few examples below:
conig.lighthouseFlags = {
  "output": [
    "html"
  ],
  "emulatedFormFactor": "none",
  "disableStorageReset": "true",
  "disableDeviceEmulation": "true"
};
// The 3rd parameter includes the configuration on how to run the tests in lighthouse
conig.lighthouseConfigs = {
  "extends": "lighthouse:default",
  "passes": [{
    "passName": "defaultPass",
    "gatherers": [
      "gatherer_more_seo"
    ]
  }],
  "audits": [
    "audit_seo_something"
  ],
  "categories": {
    "more_seo": {
      "title": "Friendly title",
      "description": "Friendly description",
      "auditRefs": [{
        "id": "more-seo-field",
        "weight": 1
      }]
    }
  }
};
于 2019-01-15T14:29:14.433 回答