This is npm package which enables to use WebWorker in webpack based projects.
- Importing the library
import Worker from ‘worker-loader!./Worker.js’;
- Webpack config
{ module: { rules: [ { test: /\.worker\.js$/, use: { loader: 'worker-loader' } } ] }}
- Use
const worker = new Worker();
worker.postMessage({ a: 1 });
worker.onmessage = function (event) {};
worker.addEventListener("message", function (event) {});