Registry / devops / rollup-plugin-web-worker-loader

rollup-plugin-web-worker-loader

JSON →
library1.7.0jsnpmunverified

Rollup plugin for bundling Web Workers, Service Workers, Shared Workers, Audio Worklets, and Paint Worklets. Current stable version is 1.7.0; published regularly. Supports inlining worker code or emitting separate script files via code-splitting. Handles worker dependencies, source maps, and Node.js environments. Differentiators include support for multiple worker/worklet types, Node.js compatibility, and automatic platform detection. Requires Rollup 1.9+ up to 4.x.

npm install rollup-plugin-web-worker-loader
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-WEB-
R
rollup-plugin-web-worker-loader
devopsjavascriptv1.7.0
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 (plugin function)
import webWorkerLoader from 'rollup-plugin-web-worker-loader';
const webWorkerLoader = require('rollup-plugin-web-worker-loader');
ESM default export; CJS require() works with some bundlers but not recommended.
Web Worker import
import DataWorker from 'web-worker:./DataWorker';
import DataWorker from 'rollup-plugin-web-worker-loader!./DataWorker';
The plugin uses a prefix scheme (default: 'web-worker:') in the import specifier; no query syntax.
Service Worker import
import ServiceWorker from 'service-worker:./ServiceWorker';
const ServiceWorker = require('service-worker:./ServiceWorker');
ESM-only import; ServiceWorker returns a Promise<ServiceWorkerRegistration>.

Minimal Rollup config with the plugin and a Web Worker import example.

import webWorkerLoader from 'rollup-plugin-web-worker-loader'; import { defineConfig } from 'rollup'; export default defineConfig({ input: 'src/index.js', plugins: [ webWorkerLoader({ targetPlatform: 'auto', preserveSource: false, external: [] }) ], output: { dir: 'dist', format: 'esm' } }); // src/index.js import MyWorker from 'web-worker:./MyWorker'; const worker = new MyWorker(); worker.postMessage('hello'); // src/MyWorker.js self.onmessage = (e) => { postMessage('received: ' + e.data); };
Debug
Known issues
gotchaThe plugin can only be used with Rollup's module format (ESM or CJS). It does not support UMD or IIFE output formats.
fix
Set output.format to 'esm' or 'cjs'.
affects: >=0.1.0
deprecatedUsing 'web-worker:' prefix without specifying a targetPlatform may produce inline code in some cases; the 'auto' mode attempts to detect the environment but can misbehave in mixed contexts.
fix
Explicitly set targetPlatform to 'browser' or 'node'.
affects: <1.5.0
breakingVersion 1.0.0 changed the import pattern from a query string (?worker) to a prefix scheme (web-worker:). Old imports using ?worker will fail.
fix
Replace import MyWorker from './MyWorker?worker' with import MyWorker from 'web-worker:./MyWorker'.
affects: <1.0.0
Errors
Common errors & fixes
SyntaxError: Named export 'default' not found. The requested module 'rollup-plugin-web-worker-loader' is a CommonJS module, which may not support all module.exports as named exports.
The plugin is an ESM-only default export; CommonJS require() or named import destructuring fails.
fix
Use import webWorkerLoader from 'rollup-plugin-web-worker-loader' (ESM) or if using CJS, use const webWorkerLoader = require('rollup-plugin-web-worker-loader').default.
Error: The 'web-worker' prefix is not configured. Use the 'webWorkerLoader' plugin options to set a custom pattern.
The import specifier uses a custom prefix not defined in the plugin config.
fix
Either use the default 'web-worker:' prefix, or configure a custom RegEx in the plugin options under the 'web-worker' key.
Upgrade
Version history
1.7.0latest on npm
Audit
Dependencies
rolluprequiredpeer dependency: required to function as a Rollup plugin, versions ^1.9.2 || ^2.0.0 || ^3.0.0 || ^4.0.0
Agent activity
4 hits · last 30 days
node
4
Resources
rollup-plugin-web-worker-loader — npm install rollup-plugin-web-worker-loader · libregistry