我正在尝试为Webpack设置WorkboxPlugin,我确实按照https://developers.google.com/web/tools/workbox/guides/get-started提供的教程,但无法摆脱上次失败的审核:
Users will not be prompted to install the Web App:
Failures: service worker does not successfully serve the manifest's start url
我基本上提供了一个离线页面/offline
,但无法弄清楚如何在插件中进行路由。
webpackplugin:
new WorkboxPlugin.GenerateSW({
swDest: 'sw.js',
clientsClaim: true,
skipWaiting: true,
runtimeCaching: [
{
urlPattern: new RegExp('/offline'),
handler: 'staleWhileRevalidate',
},
{
urlPattern: new RegExp('/'),
handler: 'staleWhileRevalidate',
},
],
}),
],
我的清单中的startUrl指向:"start_url": "./",
生成的sw.js:
importScripts("https://storage.googleapis.com/workbox-cdn/releases/3.1.0/workbox-sw.js");
importScripts(
"/precache-manifest.b0461f0dafa721eb54bbbe7cf6e3d452.js"
);
self.__precacheManifest = [].concat(self.__precacheManifest || []);
workbox.precaching.suppressWarnings();
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
workbox.routing.registerRoute(/\/offline/, workbox.strategies.staleWhileRevalidate(), 'GET');
workbox.routing.registerRoute(/\//, workbox.strategies.staleWhileRevalidate(), 'GET');
precache-manifest看起来也很好
我缺少什么?
非常感谢!
答案 0 :(得分:1)
修复方法是将"start_url": "./"
设置为Webapps url,例如:
"start_url": "https://webapp.app"