SwoffSwoff

CLI Reference

Full documentation for every @swoff/cli command and flag.

CLI Reference

Full documentation for every @swoff/cli command and flag.

init

Creates swoff.config.json in your project root. Auto-detects:

  • Framework: checks for react, vue, svelte dependencies in package.json (falls back to "vanilla" if no package.json found)
swoff init
swoff init --framework react   # override auto-detection
FlagTypeDescription
--framework"react" | "nextjs" | "remix" | "tanstack-start-react" | "astro" | "nuxt" | "sveltekit" | "vike" | "vue" | "svelte" | "vanilla" | "no-bundler"Override framework auto-detection

generate

Generates the service worker and all supporting files into swoff/.

swoff generate
swoff generate --language js
FlagDescription
--language"ts" | "js" — override language auto-detection; forces .tsx/.ts or .jsx/.js output

What is generated

All files land in swoff/. See API Reference for the full reference.

FileConditionPurpose
client-injector.{ts|js}alwaysSingle entry point — wires SW registration, PWA install, mutation queue, cross-tab sync
config.{ts|js}serverPush.enabledProject configuration — API_BASE for server-push endpoint
connectivity.{ts|js}features.connectivity.enabledOnline/offline detection with HEAD heartbeat
db.{ts|js}auto-enabled when auth, mutation queue, or push notifications is enabledIndexedDB database open/init helpers
fetch/core.{ts|js}features.tagInvalidation.enabledUnified fetch with caching, auth, offline queue, auto-invalidation
cache/invalidate.{ts|js}features.tagInvalidation.enabledinvalidateByTag() / invalidateByTags()
cache/tags.{ts|js}features.tagInvalidation.enabledTag generation helpers from URL paths
storage.{ts|js}alwaysStorage estimation (getStorageEstimate / formatBytes)
reset.{ts|js}alwaysresetSwoff() — wipes caches, IndexedDB databases, localStorage, unregisters SW
auth/adapter.{ts|js}auth.enabledAuth provider adapter — generated template (cookie, bearer, or custom)
auth/store.{ts|js}auth.enabledToken/user persistence + cascading clearAuth + cross-tab sync
auth/state.{ts|js}auth.enabledOnline/offline × auth state detection (connectivity manager)
auth/check.{ts|js}auth.enabledCustom auth failure response detection
graphql/index.{ts|js}graphql.enabledGraphQL wrapper with body-hash caching
mutation/queue.{ts|js}mutationQueue.enabledOffline write queue in IndexedDB
mutation/state.{ts|js}mutationQueue.enabledPer-mutation status tracking
mutation/sync.{ts|js}mutationQueue.backgroundSyncBackground Sync API registration
push-notification/index.{ts|js}pushNotificationsPush notification subscription management
pwa/prompt.{ts|js}pwa.enabledInstall prompt handling (isInstallable, promptInstall)
server-push/client.{ts|js}serverPush.enabledSSE/WebSocket connection manager (runs in SW)
sw/template.jsalwaysService worker source — runs in SW scope
sw/injector.{ts|js}alwaysSW registration logic
sw/generator.mjsalwaysBuild-time script — embeds asset hashes
sw/version.{ts|js}alwaysSW_VERSION constant — embedded in SW for display / debugging
adapters/*.tsxReact-based framework onlyFramework adapters. Other frameworks use window.addEventListener (see Blueprint)
swoff.d.tsTypeScriptTypeScript declarations

PWA assets

PWA assets (icons, favicons, splash screens) are generated by the external @swoff/assets package — see below.


assets

PWA assets (icons, splash screens, manifests) are generated by the external @swoff/assets package:

npx @swoff/assets --source ./logo.svg

Run npx @swoff/assets --help for all flags (--source, --no-splash, --theme-color, etc.).

Generated assets by default:

FileDescription
public/icon-64.pngSmall PWA icon (64×64)
public/icon-192.pngStandard PWA icon (192×192)
public/icon-512.pngLarge PWA icon (512×512)
public/maskable-icon-512.pngMaskable PWA icon (512×512) with safe zone padding
public/apple-touch-icon.pngApple touch icon (180×180)
public/favicon.icoMulti-size favicon (16×16, 32×32, 48×48)
public/og-image.pngOpen Graph / social sharing image (1200×630) with centered logo
public/splash-*.pngApple splash screens (7 sizes for all iOS devices)

After generation, manually reference these assets in your app. Run swoff assets --help for a copy-paste guide with the exact <link> and <meta> tags for your HTML <head>.

validate

Validates swoff.config.json against the schema. Reports unknown fields, type mismatches, and structural errors.

swoff validate

clean

Removes generated Swoff files and config:

swoff clean
swoff clean --yes     # skip confirmation prompt
FlagDescription
--yes / -ySkip confirmation prompt

This deletes:

  • swoff/ directory (all generated files)
  • swoff.config.json

help [command]

Shows help text for a specific command.

swoff help
swoff help init
swoff help generate

Build script integration

The SW generator (sw/generator.mjs) must run after every build to produce the final service worker file. Run it directly:

node swoff/sw/generator.mjs

For Node.js projects, add it to your package.json build script:

"build": "vite build && node swoff/sw/generator.mjs"

The generator:

  1. Reads swoff.config.json for output dir and strategy config
  2. Reads sw/template.js — the service worker source code
  3. Collects all built assets from the output directory
  4. Replaces placeholders ([[CACHE_NAME]], [[ASSETS_LIST]], [[AUTO_SKIP_WAITING]]) with actual values
  5. Writes the final SW file to build.swOutput (e.g. dist/sw.js)

On this page