我一直在尝试使用 SvelteKit 为我的网站创建 ServiceWorker,但在这里遇到了问题。我创建了一个文件/src/service-worker.ts,并在其中添加了以下代码
import { build, files, prerendered, version } from '$service-worker';
const applicationCache = `applicationCache-v${version}`;
const staticCache = `staticCache-v${version}`;
const returnSSRpage = (path) =>
caches.open("ssrCache").then((cache) => cache.match(path));
// Caches the svelte app (not the data)
self.addEventListener("install", (event) => {
event.waitUntil(
Promise.all([
caches
.open("ssrCache")
.then((cache) => cache.addAll(["/"])),
caches
.open(applicationCache)
.then((cache) => cache.addAll(build)),
caches
.open(staticCache)
.then((cache) => cache.addAll(files))
])
.then(self.skipWaiting()),
)
})
... reduced code
Run Code Online (Sandbox Code Playgroud)
运行npm run build此代码时,编译效果非常好,并且代码在浏览器中运行。然而,我的 VSCode 智能感知出现了一些错误。最值得注意的是,它说 的waitUntil属性event不存在。
Property …