Registry / web-framework / worker-plugin

worker-plugin

JSON →
library5.0.1jsnpmunverified

Webpack plugin that automatically bundles and compiles Web Workers (including SharedWorkers) integrated into your build. Version 5.0.1 supports both Webpack 4 and 5, with fixes for malformed options objects. It simplifies worker usage by allowing standard `new Worker('./worker.js', { type: 'module' })` syntax, which works without bundling but becomes universally compatible when bundled. Unlike Webpack 5's built-in worker support (which uses `new URL` syntax), worker-plugin uses the more traditional approach and adds SharedWorker support. It does not require runtime changes and supports ESM modules in workers.

npm install worker-plugin
INSTALL
IMPORT
SIG · WORKER-PLUGIN
W
worker-plugin
web-frameworkjavascriptv5.0.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

WorkerPlugin
✓ const WorkerPlugin = require('worker-plugin');
✗ import WorkerPlugin from 'worker-plugin';
CommonJS require is the default and recommended usage. ESM import is not supported by the package.
WorkerPlugin (ESM)
✓ import WorkerPlugin from 'worker-plugin';
✗ const WorkerPlugin = require('worker-plugin').default;
If using ESM, the default import works as the package exports a single function. Do not try to use .default with CommonJS.
WorkerPlugin (TypeScript)
✓ import WorkerPlugin from 'worker-plugin';
✗ const WorkerPlugin = require('worker-plugin');
TypeScript users should use default import for type inference. The package provides types.

Shows basic setup: install worker-plugin, add to webpack config, create a simple worker module and invoke it from main thread.

const WorkerPlugin = require('worker-plugin'); // webpack.config.js module.exports = { output: { filename: '[name].bundle.js' }, plugins: [ new WorkerPlugin() ] }; // In your application code: // worker.js self.addEventListener('message', event => { self.postMessage('Hello from worker'); }); // main.js const worker = new Worker('./worker.js', { type: 'module' }); worker.onmessage = event => console.log(event.data); worker.postMessage('');
Debug
Known issues
breakingIn v3.0.0, plugins are no longer inherited by default. You must explicitly pass plugins via the 'plugins' option if you need them in worker compilation.
fix
Use the 'plugins' option to specify which plugins to apply to workers, e.g., new WorkerPlugin({ plugins: ['SomePlugin'] })
affects: >=3.0.0
deprecatedWebpack 5 now includes built-in worker bundling. worker-plugin is still useful for SharedWorker support and simpler syntax, but consider migrating to Webpack 5's native support using `new Worker(new URL('./worker.js', import.meta.url))`.
fix
Evaluate whether to migrate to Webpack 5's built-in worker support or continue using this plugin.
affects: >=5.0.0
gotchaWorkerPlugin only bundles workers with string URL/filename arguments. Dynamic URLs, Blob URLs, data URLs, or not providing { type: 'module' } will leave the worker unmodified and print a warning.
fix
Ensure you always pass a static string filename and { type: 'module' } option to the Worker constructor.
affects: >=1.0.0
gotchaIf output.filename is set to a static name (e.g., 'bundle.js'), multiple workers will overwrite each other's output files.
fix
Set output.filename to a dynamic pattern like '[name].bundle.js' to give each worker a unique filename.
affects: >=1.0.0
gotchaSetting output.globalObject to 'window' (common for web targets) breaks Hot Module Replacement in workers. WorkerPlugin will emit a warning.
fix
Either avoid setting globalObject to 'window' or pass globalObject: false to WorkerPlugin to suppress the warning.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Module not found: Error: Can't resolve './worker.js'
The worker file path is incorrect or not handled by webpack loaders.
fix
Ensure the worker filename is a string literal and the path is relative to the current module. For TypeScript, use .ts extension: new Worker('./worker.ts', { type: 'module' })
Warning: WorkerPlugin: No workers found. Ensure you are using `new Worker(fileURL)` syntax with a string argument.
The plugin did not detect any Worker constructor calls with string arguments and { type: 'module' }.
fix
Double-check that you are using the exact syntax: new Worker('./path.js', { type: 'module' }). Dynamic variables or missing module type will not be bundled.
Error: WorkerPlugin: SharedWorker is not supported in this version of Webpack
SharedWorker support requires webpack 5.
fix
Upgrade to webpack 5 or disable sharedWorker option in WorkerPlugin.
Upgrade
Version history
5.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
12
Amazon
1
OpenAI (training)
1
Resources
worker-plugin — npm install worker-plugin · libregistry