{"id":22292,"library":"rollup-plugin-worker","title":"rollup-plugin-worker","description":"Rollup plugin to bundle Web Workers using a custom prefix import syntax (e.g., `worker!./worker.js`). v3.0.4 supports Rollup 3.x. It allows specifying worker-specific plugins and enables uglification. Provides TypeScript types. Differentiator: uses a prefix syntax rather than URL or inline blob, enabling easy bundling.","status":"active","version":"3.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/wesmile2020/rollup-plugin-worker","tags":["javascript","rollup-plugin-worker","typescript"],"install":[{"cmd":"npm install rollup-plugin-worker","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-worker","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-worker","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since v3; CommonJS require() works in Node.","wrong":"const worker = require('rollup-plugin-worker');","symbol":"default","correct":"import worker from 'rollup-plugin-worker'"},{"note":"Default import from the prefix path, not a named export.","wrong":"import { Worker } from 'worker!./workers/worker.js'","symbol":"Worker","correct":"import Worker from 'worker!./workers/worker.js'"},{"note":"The default export is named WebWorker in the declaration.","wrong":"declare module 'worker!*' { export class WebWorker extends Worker { constructor(); } }","symbol":"WebWorker (TypeScript declaration)","correct":"declare module 'worker!*' { class WebWorker extends Worker { constructor(); } export default WebWorker; }"}],"quickstart":{"code":"// rollup.config.js\nimport worker from 'rollup-plugin-worker';\n\nexport default {\n  input: 'src/main.js',\n  plugins: [\n    worker({\n      prefix: 'worker!',\n      plugins: [],\n      uglify: false,\n    }),\n  ],\n  output: {\n    file: 'dist/bundle.js',\n    format: 'iife',\n  },\n};\n\n// src/main.js\nimport MyWorker from 'worker!./worker.js';\nconst w = new MyWorker();\nw.postMessage('hello');","lang":"javascript","description":"Configures rollup-plugin-worker in rollup.config.js and shows usage in main.js with a custom worker import prefix."},"warnings":[{"fix":"Upgrade to Rollup 3.x or use rollup-plugin-worker@2.x for Rollup 2 compatibility.","message":"Plugin requires Rollup ^3.0.0; does not work with Rollup 2.x.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use the same prefix in both plugin options and import paths.","message":"The prefix 'worker!' is required by default; if changed, ensure import statements match.","severity":"gotcha","affected_versions":"all"},{"fix":"Define separate plugins array for worker processing if needed.","message":"Plugins passed in the `plugins` option are used only for worker bundle; do not include the main bundle plugins unintentionally.","severity":"gotcha","affected_versions":"all"},{"fix":"Set uglify: false and use @rollup/plugin-terser for minification.","message":"uglify option is boolean; consider using terser or other minifier plugins instead.","severity":"deprecated","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"npm install rollup-plugin-worker --save-dev","cause":"Package not installed or incorrect import path.","error":"Error: Cannot find module 'rollup-plugin-worker'"},{"fix":"Use default import: import worker from 'rollup-plugin-worker'","cause":"Using default import incorrectly (e.g., import { worker } instead of import worker).","error":"TypeError: worker is not a function"},{"fix":"Check that rollup-plugin-worker is in plugins array and prefix matches import path (e.g., 'worker!').","cause":"Plugin not properly configured or prefix mismatch.","error":"Error: Could not resolve 'worker!./worker.js'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}