-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
Description
Create a plugin that provides a simple API for using web workers from your application code.
Typically, web worker scripts will be generated in a separate build, or minimally by defining a separate entry-point. This can prove cumbersome, especially since there's boilerplate to setup for message passing, and lots of associated build config to get right.
This plugin will alleviate these issues by fulfilling the following requirements:
- provide a
require.worker("./path/to/worker")mechanism in app code - set up a separate, specialized entry point for the specified worker module automatically (which will be bundled as normal)
- replace
require.worker("./path/to/worker")with a dynamically generated module that looks something like:
const worker = new Worker("./path/to/worker.bundle.js");
module.exports = onMessage => {
worker.addEventListener("message", onMessage);
return msg => { worker.postMessage(msg); };
};