Skip to content

interlock-webworkers #21

@divmain

Description

@divmain

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); };
};
  • allow access to split bundles from inside the web worker by inserting a runtime module provider that uses the importScripts global function instead of creating <script> tags
  • the worker should be configurable, such that a SharedWorker can be created instead [0] [1]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions