Security News
PyPI’s New Archival Feature Closes a Major Security Gap
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
worker-plugin
Advanced tools
The worker-plugin npm package is a Webpack plugin that allows you to use Web Workers with Webpack seamlessly. It simplifies the process of bundling and using Web Workers in your application by handling the necessary configurations and dependencies.
Automatic Web Worker bundling
This feature allows you to automatically bundle Web Workers with your Webpack configuration. By adding the WorkerPlugin to your Webpack plugins array, you can seamlessly use Web Workers in your application without additional configuration.
const WorkerPlugin = require('worker-plugin');
module.exports = {
// Other Webpack configuration options...
plugins: [
new WorkerPlugin()
]
};
Inline Web Worker support
This feature allows you to create Web Workers inline using the new URL syntax. The WorkerPlugin handles the necessary bundling and ensures that the Web Worker is correctly loaded and executed.
const worker = new Worker(new URL('./worker.js', import.meta.url));
worker.postMessage('Hello, worker!');
TypeScript support
The WorkerPlugin also supports TypeScript, allowing you to create and use Web Workers written in TypeScript. This feature ensures that your TypeScript Web Workers are correctly transpiled and bundled.
const worker = new Worker(new URL('./worker.ts', import.meta.url));
worker.postMessage('Hello, TypeScript worker!');
The worker-loader package is another Webpack loader that allows you to bundle Web Workers. It provides similar functionality to worker-plugin but requires more manual configuration. With worker-loader, you need to explicitly specify the loader in your Webpack configuration and import statements.
Comlink is a library that simplifies the use of Web Workers by providing a proxy-based API. It allows you to call functions in Web Workers as if they were local functions. While Comlink focuses on simplifying the communication between the main thread and Web Workers, worker-plugin focuses on bundling and configuration.
Threads.js is a library that provides a high-level API for working with Web Workers and threads in JavaScript. It offers features like thread pools and message-based communication. Compared to worker-plugin, threads.js provides more advanced threading capabilities and abstractions.
Automatically bundle & compile Web Workers within Webpack.
Automatically compiles modules loaded in Web Workers:
const worker = new Worker('./foo.js', { type: 'module' });
^^^^^^^^^^
gets bundled using webpack
The best part? That worker constructor works just fine without bundling turned on too.
Workers created from Blob & data URLs or without the { type:'module' }
option are left unchanged.
npm install -D worker-plugin
Then drop it into your webpack.config.js:
plugins: [
+ new WorkerPlugin()
]
worker.js: (our worker module)
// This is a module worker, so we can use imports (in the browser too!)
import { calculatePi } from './some-other-module';
addEventListener('message', event => {
postMessage(calculatePi(event.data));
});
main.js: (our demo, on the main thread)
const piWorker = new Worker('./worker.js', { type: 'module' });
piWorker.onmessage = event => {
console.log('pi: ' + event.data);
};
piWorker.postMessage(42);
Apache-2.0
FAQs
Webpack plugin to bundle Workers automagically.
The npm package worker-plugin receives a total of 129,618 weekly downloads. As such, worker-plugin popularity was classified as popular.
We found that worker-plugin demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
PyPI now allows maintainers to archive projects, improving security and helping users make informed decisions about their dependencies.
Research
Security News
Malicious npm package postcss-optimizer delivers BeaverTail malware, targeting developer systems; similarities to past campaigns suggest a North Korean connection.
Security News
CISA's KEV data is now on GitHub, offering easier access, API integration, commit history tracking, and automated updates for security teams and researchers.