Webpack loader to offload modules to Worker threads seamlessly using Comlink.
comlink-loader version 2 changes the behavior of the singleton
option, making it simpler than before and allowing TypeScript types work without any casting.
Now, importing a module using the comlink-loader?singleton!
prefix immediately runs the module in a Web Worker and returns/reflects the module's exports:
worker.js | index.js |
---|---|
|
|
Note: seamless TypeScript support requires comlink-loader
to be configured to apply to .worker.ts
files in your Webpack configuration.
worker-loader
error when using ?singleton
(thanks @jackyef!)?multi
option to allow multiple instances of the worker:import Foo from 'comlink-loader?multi!./foo.worker';
await new Foo() // creates a new worker
await new Foo() // creates another new worker
Initial release!