Skip to main content

$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';

此模块仅适用于 服务工作者

¥This module is only available to service workers.

base

部署的 base 路径。通常,这相当于 config.kit.paths.base,但它是从 location.pathname 计算出来的,这意味着如果将站点部署到子目录,它将继续正常工作。请注意,有 base 但没有 assets,因为如果指定了 config.kit.paths.assets,则无法使用服务工作线程。

¥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.

const base: string;

build

表示 Vite 生成的文件的 URL 字符串数组,适合使用 cache.addAll(build) 进行缓存。在开发过程中,这是一个空数组。

¥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.

const build: string[];

files

表示静态目录中的文件或 config.kit.files.assets 指定的任何目录中的 URL 字符串数组。你可以使用 config.kit.serviceWorker.files 自定义从 static 目录包含哪些文件

¥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

const files: string[];

prerendered

对应于预渲染页面和端点的路径名数组。在开发过程中,这是一个空数组。

¥An array of pathnames corresponding to prerendered pages and endpoints. During development, this is an empty array.

const prerendered: string[];

version

参见 config.kit.version。它对于在服务工作线程中生成唯一的缓存名称很有用,以便以后部署应用可以使旧缓存无效。

¥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.

const version: string;
上一页 下一页