@vettvangur/workbox
v1.0.50
Published
Thin wrapper around [`workbox-cli`](https://developer.chrome.com/docs/workbox/modules/workbox-cli) that generates a service worker using a sane default config — scoped to the `dest` directory you already declare in `vettvangur.config.mjs`.
Maintainers
Keywords
Readme
@vettvangur/workbox
Thin wrapper around workbox-cli that generates a service worker using a sane default config — scoped to the dest directory you already declare in vettvangur.config.mjs.
Install
pnpm add -D @vettvangur/workboxCLI
vettvangur-workbox buildThis:
- Reads
vettvangur.config.mjsfromcwd(must exportdefaultwith a non-emptydeststring). - Resolves
destto an absolute path. - Runs
workbox generateSWagainst it with the bundledworkbox-config.cjs. - Writes
service-worker.jsintodest.
If vettvangur.config.mjs is missing or dest is invalid, the loader throws a clear error pointing at the project root.
What the bundled config caches
| Pattern | Strategy | Notes |
| --- | --- | --- |
| *.js, *.css, assets/**/*.{js,css} | Precache | Up to 512KB per file. |
| Image extensions (png/jpe?g/webp/avif/svg/gif/ico) | CacheFirst | Capped at 120 entries / 30 days. |
| Other .js / .css | StaleWhileRevalidate | Used at runtime for late-loaded resources. |
Excluded from precache: source maps, *.test.js / *.spec.js, *.d.ts, __tests__/test/tests/coverage/sourcemaps directories, the generated service-worker.js / sw.js itself, and any workbox-*.js runtime files.
navigateFallback is set to /index.html and outdated caches are cleaned on activation.
Library usage (no CLI)
import { build } from '@vettvangur/workbox'
await build()The library entrypoint is side-effect free — importing it does not register process.on('unhandledRejection' | 'uncaughtException') handlers. Those live in cli.mjs (the file the vettvangur-workbox bin points at) so they only attach when the CLI is invoked.
Customizing the config
If you need to tweak the workbox config (different glob patterns, different runtime caching), copy workbox-config.cjs into your project, edit it, and call workbox generateSW path/to/your-config.cjs directly — bypass the wrapper for that case.
