在较新的工作箱版本(包括本文发布时的 5.1.3)中,指定 precacheManifest 的注入点的参数已从正则表达式更改为字符串。参数的名称也发生了变化,据我所知,这不向后兼容......这意味着它不再使用正则表达式。
module.exports = {
"globDirectory": "build/",
"globPatterns": [
"**/*.{json,ico,html,png,js,txt,css,svg}"
],
"swDest": "build/sw.js",
"swSrc": "src/sw.js",
"injectionPoint": "injectionPoint"
}
在视频的其余部分之后,按照上面的方式更改该参数对我有用。
然后其他几个更新也影响了 sw.js 的编写方式......
importScripts("workbox-v5.1.3/workbox-sw.js");
workbox.setConfig({ modulePathPrefix: "workbox-v5.1.3/" });
const precacheManifest = [injectionPoint];
workbox.precaching.precacheAndRoute(precacheManifest);
您必须删除 .suppressWarnings() 命令。它已被删除。一个好的视频......需要一些更新。
链接到演示文稿 github,需要更新,所以......https://github.com/mikegeyser/building-pwas-with-react https://github.com/mikegeyser/building-pwas-with-react
手册链接:https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-build https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-build
@梅格菲利普斯91