Service Worker
Archibald integrates a Workbox-based service worker into web projects: offline-capable caching for API responses, fonts, images and runtime assets, compiled as part of the regular Archibald build.
Setup
The scaffolder is built into @archibald/cli, so there is no integration package to install. In an Archibald project:
archibald add service-worker
This:
- installs
workbox-cacheable-response@7,workbox-expiration@7,workbox-routing@7andworkbox-strategies@7as dev dependencies (Workbox v7 only — the command aborts if another Workbox major is already present), - copies the starter service-worker sources (bootstrap, cache registrations, helpers) into
src/{platform}/service-worker, - enables
cli.serviceWorkerinarchibald.json:
{
"cli": {
"serviceWorker": {
"active": true,
"options": {
"swSrc": "src/{platform}/service-worker",
"swDest": "service-worker.js",
"injectionPoint": "__WB_MANIFEST"
}
}
}
}
Configuration
The cli.serviceWorker block controls the service-worker compilation:
active— turns service-worker compilation on.options.swSrc— path of the service-worker source read during the build, relative to the working directory.options.swDest— filename of the emitted worker, relative todist/client(must end in.js).options.injectionPoint— the placeholder Workbox replaces with the precache manifest.
The scaffolded sources are ordinary project files under src/{platform}/service-worker — customize the cache registrations (API, font, image, runtime caches) there; they participate in file shadowing like any other source.
Further documentation
- archibald.json reference — where
cli.serviceWorkerlives. - Workbox documentation