Reference
Architecture
vue-worker-kit
│
├── defineWorkerHandler() (vue-worker-kit/worker)
│ Wires the run/cancel message protocol; starts a message loop only
│ inside a Dedicated-/SharedWorkerGlobalScope, no-op elsewhere
│ Phantom-typed __input/__output marker — read by useWorker/
│ createWorkerPool/useWorkerComputed through a conditional type
│
├── useWorker() (main entry)
│ Lazily creates one worker via the passed factory
│ idleTimeout / retries / retryDelay / hardCancelOnAbort / cache / streaming
│ onScopeDispose auto-termination inside setup(), plus a public terminate()
│
├── createWorkerPool() / useWorkerPool() (vue-worker-kit/pool)
│ Lazily creates up to `size` workers as tasks arrive
│ pool.run() / pool.map() with bounded concurrency + per-item transfer
│ onProgress / onChunk callbacks on run()/map() for per-task progress & streaming
│
├── useWorkerComputed() (vue-worker-kit/computed)
│ computed() that reruns a worker on reactive source changes
│ Generation-number race handling — stale results silently dropped
│
├── useSharedWorker() (vue-worker-kit/shared)
│ Wraps a single SharedWorker connection shared across tabs/windows
│ connect() / disconnect() own the whole lifecycle (no idleTimeout)
│
└── Devtools (vue-worker-kit/devtools)
createWorkerActivityMonitor() + <WorkerActivityPanel> — reactive,
subscription-driven (no polling), no @vue/devtools-api dependencyBundler support. No worker-loader/worker-plugin or other webpack-era workarounds needed — this uses the native ESM worker import (new URL('./x.worker.ts', import.meta.url) + { type: 'module' }), which Vite (and Nuxt 3/4) picks up and bundles as its own chunk automatically. If you're on classic Webpack (Vue CLI), you'll need worker-plugin or equivalent — that's a bundler limitation, not this package's.
SSR compatibility
useWorker/useWorkerComputed/useWorkerPool are safe to call in setup() on the server — the constructor is passed as a factory (() => new Worker(...)) and only invoked from inside run(), i.e. only on the client in normal usage. If run() is nonetheless called during SSR, you get a WorkerUnavailableError with a clear message rather than a crash. Guard client-only usage with <ClientOnly> in Nuxt:
<ClientOnly>
<ProgressBar v-if="isRunning" :value="progress" />
</ClientOnly>Bundle size & peer dependencies
| Entry point | Peer deps | Notes |
|---|---|---|
vue-worker-kit | vue ^3.4 (required) | Main entry — useWorker() |
vue-worker-kit/worker | vue ^3.4 (required) | defineWorkerHandler() — worker-side |
vue-worker-kit/pool | vue ^3.4 (required) | createWorkerPool()/useWorkerPool() |
vue-worker-kit/computed | vue ^3.4 (required) | useWorkerComputed() |
vue-worker-kit/shared | vue ^3.4 (required) | useSharedWorker() |
vue-worker-kit/devtools | vue ^3.4 (required) | Debug panel, no @vue/devtools-api dependency |
Zero dependencies beyond the vue peer — no other runtime dependency, on any entry point. sideEffects: false; every entry point is its own chunk, so importing one doesn't pull in the others.
Comparison
vue-worker (latest 1.2.1, published 2017) and vue-web-workers (latest 0.2.0, published 2020, depends on vue@^2.6.11 directly) are both effectively unmaintained Vue 2 plugins — verified against the npm registry, not from memory. Comlink (4.4.2, still actively maintained, zero dependencies) is a solid, Vue-agnostic RPC layer.
vue-worker / vue-web-workers | Comlink | vue-worker-kit | |
|---|---|---|---|
| Composition API | ✗ | — (not Vue-specific) | ✓ |
| Typed input/output | ✗ | manual wrap<T>() | inferred from the worker file |
| Worker pool | ✗ | ✗ | ✓ (createWorkerPool, pool.map with per-item transfer) |
| Reactive computed-in-worker | ✗ | ✗ | ✓ (useWorkerComputed) |
| SharedWorker (multi-tab) | ✗ | ✗ | ✓ (useSharedWorker) |
| Streaming results | ✗ | ✗ | ✓ (ctx.reportChunk, chunks.value) |
| Cancellation | ✗ | ✗ | ✓ (AbortSignal, per-task + global for pool) |
| Transferables | ✗ | ✓ (manual, both directions) | ✓ (RunOptions.transfer in, ctx.transfer() out, per-item for pool.map) |
| Worker warmup | ✗ | ✗ | ✓ (warmup() for single worker and pool) |
| Retry with backoff | ✗ | ✗ | ✓ (configurable delay function) |
| Result caching (LRU) | ✗ | ✗ | ✓ (cache: 'lru', maxCacheSize) |
| SSR-safe | ✗ | — | ✓ |
| Dependencies | — | none | none beyond vue |
License
MIT