A Rollup plugin that adds code splitting for JavaScript module Workers (Web Workers, Shared Workers, Service Workers) and Worklets (AudioWorklet, PaintWorklet, LayoutWorklet, AnimationWorklet). Current stable version: 2.1.1. Works with Rollup >= 1.11.0. It transforms Worker/Worklet import patterns into separate output chunks, enabling dynamic code splitting for multithreaded applications. Unlike generic worker plugins, this plugin specifically targets module-type workers and supports ES module format in workers. Does not include a module loader; users must handle chunk loading.
npm install rollup-plugin-workersVerified import paths — ran on the pinned version, not inferred.
Demonstrates basic Rollup configuration with the workers plugin to enable code splitting for module workers.
Upgrade Rollup to version 1.11.0 or higher.
Provide a module loader or use a bundler that supports automatic chunk loading (e.g., Vite).
Ensure worklet registration uses the pattern obj.worklet.addModule, where worklet is one of: AudioWorklet, PaintWorklet, LayoutWorklet, AnimationWorklet.
Always pass { type: 'module' } as second argument to Worker/SharedWorker constructors, and for ServiceWorker use { type: 'module' } in register().Install the package: npm install -D rollup-plugin-workers. Use import syntax instead of require.
Change import to default import: import worker from 'rollup-plugin-workers'.
Upgrade Rollup to version >= 1.11.0.