Skip to content

Latest commit

 

History

History
34 lines (25 loc) · 640 Bytes

README.md

File metadata and controls

34 lines (25 loc) · 640 Bytes

next-worker

Makes it simple to create and manage Web Workers in NextJS. Detects imports to *.worker.[js|ts] and manages the hard stuff for you.

Caution: This package is still under development.

Without next-worker:

useEffect(() =>  {
  worker = new Worker(new URL('./bg-task.js', import.meta.url));;
}, []);

With next-worker:

import { useWorker } from './bg-task.worker.js'

  ...
  const {isReady, postMessage} = useWorker(e => {});
  ...

Usage

In your next.config.json:

const { NextWorkerPlugin } = require('next-worker');

module.exports = {
  webpack: NextWorkerPlugin()
}