worker-loader
worker-loader
This loader registers the script as Web Worker.
Install
npm i -D worker-loader
or
yarn add worker-loader --dev
Usage
Import the worker file:
// main.js var MyWorker = require("worker-loader!./file.js"); var worker = new MyWorker(); worker.postMessage({a: 1}); worker.onmessage = function(event) {...}; worker.addEventListener("message", function(event) {...});
You can also inline the worker as a blob with the inline
parameter:
var MyWorker = require("worker-loader?inline!./myWorker.js");
Inline mode will also create chunks