{"id":22287,"library":"rollup-plugin-web-worker-loader","title":"rollup-plugin-web-worker-loader","description":"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.","status":"active","version":"1.7.0","language":"javascript","source_language":"en","source_url":"https://github.com/darionco/rollup-plugin-web-worker-loader","tags":["javascript","rollup","rollup-plugin","webworker","web-worker","worker"],"install":[{"cmd":"npm install rollup-plugin-web-worker-loader","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-web-worker-loader","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-web-worker-loader","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: required to function as a Rollup plugin, versions ^1.9.2 || ^2.0.0 || ^3.0.0 || ^4.0.0","package":"rollup","optional":false}],"imports":[{"note":"ESM default export; CJS require() works with some bundlers but not recommended.","wrong":"const webWorkerLoader = require('rollup-plugin-web-worker-loader');","symbol":"default (plugin function)","correct":"import webWorkerLoader from 'rollup-plugin-web-worker-loader';"},{"note":"The plugin uses a prefix scheme (default: 'web-worker:') in the import specifier; no query syntax.","wrong":"import DataWorker from 'rollup-plugin-web-worker-loader!./DataWorker';","symbol":"Web Worker import","correct":"import DataWorker from 'web-worker:./DataWorker';"},{"note":"ESM-only import; ServiceWorker returns a Promise<ServiceWorkerRegistration>.","wrong":"const ServiceWorker = require('service-worker:./ServiceWorker');","symbol":"Service Worker import","correct":"import ServiceWorker from 'service-worker:./ServiceWorker';"}],"quickstart":{"code":"import webWorkerLoader from 'rollup-plugin-web-worker-loader';\nimport { defineConfig } from 'rollup';\n\nexport default defineConfig({\n  input: 'src/index.js',\n  plugins: [\n    webWorkerLoader({\n      targetPlatform: 'auto',\n      preserveSource: false,\n      external: []\n    })\n  ],\n  output: {\n    dir: 'dist',\n    format: 'esm'\n  }\n});\n\n// src/index.js\nimport MyWorker from 'web-worker:./MyWorker';\nconst worker = new MyWorker();\nworker.postMessage('hello');\n\n// src/MyWorker.js\nself.onmessage = (e) => {\n  postMessage('received: ' + e.data);\n};","lang":"javascript","description":"Minimal Rollup config with the plugin and a Web Worker import example."},"warnings":[{"fix":"Set output.format to 'esm' or 'cjs'.","message":"The plugin can only be used with Rollup's module format (ESM or CJS). It does not support UMD or IIFE output formats.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Explicitly set targetPlatform to 'browser' or 'node'.","message":"Using '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.","severity":"deprecated","affected_versions":"<1.5.0"},{"fix":"Replace import MyWorker from './MyWorker?worker' with import MyWorker from 'web-worker:./MyWorker'.","message":"Version 1.0.0 changed the import pattern from a query string (?worker) to a prefix scheme (web-worker:). Old imports using ?worker will fail.","severity":"breaking","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"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.","cause":"The plugin is an ESM-only default export; CommonJS require() or named import destructuring fails.","error":"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."},{"fix":"Either use the default 'web-worker:' prefix, or configure a custom RegEx in the plugin options under the 'web-worker' key.","cause":"The import specifier uses a custom prefix not defined in the plugin config.","error":"Error: The 'web-worker' prefix is not configured. Use the 'webWorkerLoader' plugin options to set a custom pattern."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}