Registry / devops / rollup-plugin-off-main-threads

rollup-plugin-off-main-threads

JSON →
library1.0.0jsnpmunverified

Rollup plugin to seamlessly use Web Workers with ES modules by shimming AMD/ESM support for workers. Current stable version is 1.0.0. It auto-bundles workers referenced via `new URL` patterns, and also supports importing workers as URLs via the `omt:` scheme. Differentiators: it works with Rollup's native worker support and handles complex worker bundling scenarios, including Service Workers with `useEval`. It enforces AMD or ESM output format for workers due to limited native module support in browsers.

npm install rollup-plugin-off-main-threads
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-OFF-
R
rollup-plugin-off-main-threads
devopsjavascriptv1.0.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

OMT
import OMT from '@surma/rollup-plugin-off-main-thread'
const OMT = require('@surma/rollup-plugin-off-main-thread')
The package exports a default function. ESM-only since v1; no CJS support.
omt: URL import
import workerURL from 'omt:./worker.js'
import workerURL from './worker.js'
The `omt:` scheme is a special import scheme that tells the plugin to bundle the worker as a separate chunk and return its URL.
workerRegexp option
OMT({ workerRegexp: /new Worker\(([^)]+)\)/ })
OMT({ workerRegexp: /new Worker\(([^)]+)\)/g })
The regexp must have a capture group for the file path, and should not use the global flag.

Basic Rollup config using OMT plugin. Output format must be 'amd' or 'esm' for workers to work.

import OMT from '@surma/rollup-plugin-off-main-thread'; export default { input: 'src/main.js', output: { dir: 'dist', format: 'amd' }, plugins: [OMT()] };
Debug
Known issues
gotchaOutput format must be 'amd' or 'esm'; other formats (e.g., 'cjs', 'iife') will cause worker bundling to fail.
fix
Set output.format to 'amd' or 'esm'.
affects: >=0.0.1
deprecatedLiteral Worker paths (e.g., new Worker('./worker.js', {type: 'module'})) are deprecated. Use new URL pattern for portability.
fix
Use new URL('worker.js', import.meta.url) instead.
affects: >=0.0.1
gotchaUsing useEval: true is not CSP compliant and may be blocked in environments with strict CSP.
fix
Avoid useEval unless necessary for Service Workers; prefer default <script> tag approach.
affects: >=0.0.1
breakingThe plugin changed its export from default export to named export in v1.0.0.
fix
Use import OMT from '@surma/rollup-plugin-off-main-thread' instead of import { OMT } from '...'.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Could not resolve 'omt:./worker.js'
The OMT plugin is not properly configured or included in the Rollup plugins list.
fix
Add OMT() to the plugins array: plugins: [OMT()].
TypeError: worker is not a constructor
Worker URL is not correctly resolved because the output format is not 'amd' or 'esm'.
fix
Set output.format to 'amd' or 'esm'.
Cannot find module '@surma/rollup-plugin-off-main-thread'
Package not installed or ESM import used in CommonJS environment.
fix
Run npm install @surma/rollup-plugin-off-main-thread and ensure your project uses ESM (e.g., 'type': 'module' in package.json).
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies
rolluprequiredPeer dependency: designed as a Rollup plugin.
Agent activity
2 hits · last 30 days
node
2
Resources
rollup-plugin-off-main-threads — npm install rollup-plugin-off-main-threads · libregistry