$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
表示由 Vite 產生的檔案的 URL 字串陣列,適合使用 cache.addAll(build)
進行快取。在開發期間,這是一個空陣列。
const build: string[];
files
表示您的靜態目錄中的檔案的 URL 字串陣列,或 config.kit.files.assets
所指定的任何目錄。您可以使用config.kit.serviceWorker.files
自訂要從 static
目錄中包含的檔案。
const files: string[];
prerendered
對應於預先渲染的頁面和端點的路徑名稱陣列。在開發期間,這是一個空陣列。
const prerendered: string[];
version
請參閱config.kit.version
。它對於在您的服務工作者內產生唯一的快取名稱非常有用,以便稍後部署您的應用程式時可以使舊的快取失效。
const version: string;