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-pluginVerified import paths — ran on the pinned version, not inferred.
Shows basic setup: install worker-plugin, add to webpack config, create a simple worker module and invoke it from main thread.
Use the 'plugins' option to specify which plugins to apply to workers, e.g., new WorkerPlugin({ plugins: ['SomePlugin'] })Evaluate whether to migrate to Webpack 5's built-in worker support or continue using this plugin.
Ensure you always pass a static string filename and { type: 'module' } option to the Worker constructor.Set output.filename to a dynamic pattern like '[name].bundle.js' to give each worker a unique filename.
Either avoid setting globalObject to 'window' or pass globalObject: false to WorkerPlugin to suppress the warning.
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' })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.Upgrade to webpack 5 or disable sharedWorker option in WorkerPlugin.
No dependency data recorded yet.