メインコンテンツへスキップ

$サービスワーカー

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から算出されます。つまりサイトがサブディレクトリにデプロイされても正しく動作します。config.kit.paths.assetsが指定されている場合、サービスワーカーは使用できないため、baseはありますが、assetsはありません。

const base: string;

build

Vite で生成されたファイルを `cache.addAll(build)` でキャッシュできる、URL文字列の配列。開発中は空の配列になります。

const build: string[];

files

静的ディレクトリまたはconfig.kit.files.assetsで指定したディレクトリのファイルを表す、URL文字列の配列。config.kit.serviceWorker.filesを使用して、静的ディレクトリから含めるファイルをカスタマイズできます。

const files: string[];

prerendered

プレレンダリングされたページとエンドポイントに対応するパス名の配列。開発中は空の配列になります。

const prerendered: string[];

version

config.kit.versionを参照。アプリの後続のデプロイメントで古いキャッシュを無効にできるように、サービスワーカー内で一意のキャッシュ名を生成するために役立ちます。

const version: string;

このページをGitHubで編集する

前へ 次へ