NodeJS

worker-loader

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) {});

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *