"injectionPointRegexp" 在使用工作箱向导时不是受支持的参数

"injectionPointRegexp" is not a supported parameter when using workbox wizard

我正在使用工作箱向导创建工作箱-config.js 如文档所述:

https://github.com/mikegeyser/workbox-wizardry/blob/master/overview.md#level-2-template-service-worker

我的配置如下所示:

module.exports = {
  "globDirectory": "public/",
  "globPatterns": [
    "**/*.{ico,html,png,json,txt}"
  ],
  "swDest": "public/sw.js",
  "swSrc": "src/sw.js",
  "injectionPointRegexp": /(const precacheManifest = )\[\](;)/
}

尝试注入清单时出现以下错误:

 ✘ alxxo@Axxxx  ~/Documents/coda/pwa-xx   workbox ●✚  workbox injectManifest workbox-config.js
Using configuration from /xxxxx/workbox-config.js.

Your configuration is invalid:
{
  "globDirectory": "public/",
  "globPatterns": [
    "**/*.{ico,html,png,json,txt}"
  ],
  "swDest": "public/sw.js",
  "swSrc": "src/sw.js",
  "injectionPointRegexp" [1]: {}
}

[1] "injectionPointRegexp" is not a supported parameter.

出现在文档中怎么会是不支持的参数呢?

我假设您使用的是最新版本的 Workbox。

如果您使用的是 Workbox v5 或更高版本,则正确的参数名称是 injectionPoint。如果您需要覆盖默认值,您现在可以传入一个字符串,而不是 RegExp。

default behavior in v5 是在您的 swSrc 文件中的某处查找符号 self.__WB_MANIFEST,并将其替换为预缓存清单。