$service-worker
import { const base: string
The base
path of the deployment. Typically this is equivalent to config.kit.paths.base
, but it is calculated from location.pathname
meaning that it will continue to work correctly if the site is deployed to a subdirectory.
Note that there is a base
but no assets
, since service workers cannot be used if config.kit.paths.assets
is specified.
base, const build: string[]
An array of URL strings representing the files generated by Vite, suitable for caching with cache.addAll(build)
.
During development, this is an empty array.
build, const files: string[]
An array of URL strings representing the files in your static directory, or whatever directory is specified by config.kit.files.assets
. You can customize which files are included from static
directory using config.kit.serviceWorker.files
files, const prerendered: string[]
An array of pathnames corresponding to prerendered pages and endpoints.
During development, this is an empty array.
prerendered, const version: string
See config.kit.version
. It’s useful for generating unique cache names inside your service worker, so that a later deployment of your app can invalidate old caches.
version } from '$service-worker';
此模块仅适用于 服务工作者。
base
部署的base
路径。通常这等效于config.kit.paths.base
,但它是根据location.pathname
计算的,这意味着如果站点部署到子目录,它将继续正常工作。请注意,存在base
但不存在assets
,因为如果指定了config.kit.paths.assets
,则无法使用服务工作者。
const base: string;
build
一个 URL 字符串数组,表示由 Vite 生成的文件,适用于使用cache.addAll(build)
进行缓存。在开发过程中,这是一个空数组。
const build: string[];
files
一个 URL 字符串数组,表示静态目录中的文件,或由config.kit.files.assets
指定的任何目录中的文件。您可以使用 config.kit.serviceWorker.files
自定义包含哪些文件。
const files: string[];
prerendered
一个路径名数组,对应于预渲染的页面和端点。在开发过程中,这是一个空数组。
const prerendered: string[];
version
参见 config.kit.version
。它对于在服务工作者内部生成唯一的缓存名称很有用,以便应用程序的后续部署可以使旧缓存失效。
const version: string;