Registry / web-framework / webworkify-webpack-dropin

webworkify-webpack-dropin

JSON →
library1.1.9jsnpmunverified

Launches web workers that can use require() in the browser with webpack. Version 1.1.9 is the latest stable release, with no active development. It works by bundling a separate entry point for the worker, allowing Node.js-style module loading inside workers. Compared to alternatives like worker-loader or native worker blob URLs, this library provides a simpler API that mimics the original webworkify but is compatible with webpack's bundling. It is primarily used in webpack-based projects that need inline workers without separate files.

npm install webworkify-webpack-dropin
INSTALL
IMPORT
SIG · WEBWORKIFY-WEBPACK
W
webworkify-webpack-dropin
web-frameworkjavascriptv1.1.9
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

default
import work from 'webworkify-webpack'
const work = require('webworkify-webpack')
The package exports a default function. In CommonJS, require returns the default export directly.
work
let w = work(require('./worker.js'))
let w = work('./worker.js')
The argument must be a module reference obtained via require, not a string path. This is required for webpack to bundle the worker module.
module.exports in worker
module.exports = function worker(self) { ... }
export default function(self) { ... }
The worker function must be assigned to module.exports. Named functions are recommended to avoid issues with anonymous functions.

Demonstrates creating a web worker from a module that uses require() inside the worker, with messaging and a dependency (gamma).

// main.js import work from 'webworkify-webpack'; let w = work(require('./worker.js')); w.addEventListener('message', event => { console.log(event.data); }); w.postMessage(4); // worker.js import gamma from 'gamma'; module.exports = function worker(self) { self.addEventListener('message', (event) => { const startNum = parseInt(event.data); setInterval(() => { const r = startNum / Math.random() - 1; self.postMessage([startNum, r, gamma(r)]); }, 500); }); };
Debug
Known issues
gotchawebpack devtool with eval configuration breaks the worker generation since version 1.1.0.
fix
Set devtool to a non-eval option like 'source-map' or 'cheap-module-source-map'.
affects: >=1.1.0
gotchaPassing anonymous functions as the worker export can cause issues. Workers may not work correctly in some browsers.
fix
Use named functions in module.exports: module.exports = function worker(self) { ... }.
affects: all
Errors
Common errors & fixes
Cannot find module './worker.js'
Using a string path instead of require() in the work() call.
fix
Use work(require('./worker.js')) instead of work('./worker.js').
Uncaught ReferenceError: require is not defined
Worker code is not bundled because the module path is not passed through require().
fix
Ensure the main script uses require('./worker.js') inside work().
Upgrade
Version history
1.1.9latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
9 hits · last 30 days
node
8
OpenAI (training)
1
Resources
webworkify-webpack-dropin — npm install webworkify-webpack-dropin · libregistry