Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

worker-loader

Package Overview
Dependencies
Maintainers
9
Versions
34
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

worker-loader

worker loader module for webpack

  • 3.0.4
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
319K
decreased by-55.08%
Maintainers
9
Weekly downloads
 
Created

What is worker-loader?

The worker-loader npm package is a webpack loader that allows you to create web workers from your JavaScript files. It simplifies the process of offloading tasks to background threads, which can help improve the performance of your web applications by handling CPU-intensive operations without blocking the main thread.

What are worker-loader's main functionalities?

Basic Web Worker Setup

This feature allows you to set up a basic web worker using worker-loader. The code demonstrates how to import a worker script, create a new worker instance, send a message to the worker, and handle messages received from the worker.

const Worker = require('worker-loader!./worker.js');
const worker = new Worker();
worker.postMessage({ message: 'Hello, Worker!' });
worker.onmessage = function(event) {
  console.log('Received from worker:', event.data);
};

Handling Multiple Workers

This feature demonstrates how to handle multiple web workers simultaneously. The code shows how to import and create instances of different worker scripts, send tasks to each worker, and handle their responses independently.

const Worker1 = require('worker-loader!./worker1.js');
const Worker2 = require('worker-loader!./worker2.js');
const worker1 = new Worker1();
const worker2 = new Worker2();
worker1.postMessage({ task: 'Task 1' });
worker2.postMessage({ task: 'Task 2' });
worker1.onmessage = function(event) {
  console.log('Worker 1 completed:', event.data);
};
worker2.onmessage = function(event) {
  console.log('Worker 2 completed:', event.data);
};

Using Web Workers with TypeScript

This feature illustrates how to use worker-loader with TypeScript. The code demonstrates importing a TypeScript worker script, creating a worker instance, sending a message to the worker, and handling the response.

import Worker from 'worker-loader!./worker.ts';
const worker = new Worker();
worker.postMessage({ message: 'Hello, TypeScript Worker!' });
worker.onmessage = function(event) {
  console.log('Received from TypeScript worker:', event.data);
};

Other packages similar to worker-loader

Keywords

FAQs

Package last updated on 09 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc