A Webpack loader that moves a module and its dependencies into a Web Worker, automatically reflecting exported functions as asynchronous proxies. Version 2.0.2 is current, supporting Webpack 5. It bundles a tiny RPC implementation, supports synchronous and async worker functions, and works with async/await. Key differentiators: no separate worker file needed, automatically wraps exports as async proxies, and allows instantiable Worker decorators.
npm install workerize-loaderVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic usage: exports a synchronous function from a worker module, imports via loader, and calls it asynchronously.
Use ES6 import syntax: import worker from 'workerize-loader!./worker'
Disable commonJS transform in Babel configuration (e.g., set modules: false).
Upgrade to webpack 5 or stay on workerize-loader 1.x.
Use named exports in worker file: export function foo() {}Set output.globalObject to 'this' or remove custom globalObject configuration.
Ensure worker module uses named exports: export function myFunc() {}Use correct import syntax: import worker from 'workerize-loader!./worker' or configure loader in webpack.config.
Use static import statements only in worker module files.
Use the correct option format: { loader: 'workerize-loader', options: { name: '[name].[contenthash:8]' } }