Skip to main content

Getting started

lite-worker is a simple, minimal library for Web Workers. It lets you run heavy or isolated tasks off the main thread with a single execute call and an explicit terminate for cleanup.

What lite-worker gives you

  • Two approaches: createWorker(function-based) or createWorkerFromFile(file-based)
  • Promise API: execute(...args) -> Promise, terminate() for cleanup
  • Robust errors & lifecycle: propagates name/message/stack, rejects on worker errors, cleans up listeners
  • Modern & minimal: ESM workers, bundler‑friendly (Vite/webpack), zero dependencies

Compatibility

  • TypeScript & JavaScript: ships with bundled declaration files, so editors get full IntelliSense while plain JS projects keep working with no additional setup.
  • ESM only: import using import { createWorker } from 'lite-worker';. Legacy CommonJS require is not supported.
  • Bundler-friendly: no custom configuration needed—works with Vite, Webpack, Rspack, Parcel, and other modern bundlers that understand native ESM.

Installation

Install lite-worker by running this command.

npm install --save lite-worker

Works in both TypeScript and JavaScript

The package ships ESM entry points and bundled declaration files. Import it with

import { createWorker } from 'lite-worker';

in .ts, .tsx, .js, .jsx or .mjs files, no extra configuration required.

Choosing the api you need

If you need to put simple function to web workers, use createWorker

Usage with Functions

If you need external dependencies, use createWorkerFromFile

Usage with File

If you are not sure, check out both pages.