sw.js文件如果放在public文件夹中运行报错,如提示 sw.js:2 Uncaught SyntaxError: Cannot use import statement outside a module 错误的话.
// 使用 importScripts 替代 import
javascript
// 使用 importScripts 替代 import
importScripts('https://storage.googleapis.com/workbox-cdn/releases/7.0.0/workbox-sw.js');
const { skipWaiting, clientsClaim } = workbox.core;
const { precacheAndRoute } = workbox.precaching;
const { registerRoute } = workbox.routing;
const { StaleWhileRevalidate, CacheFirst } = workbox.strategies;
skipWaiting();
clientsClaim();
precacheAndRoute(self.__WB_MANIFEST || []);