{"id":21258,"library":"esbuild-plugin-inline-worker","title":"esbuild-plugin-inline-worker","description":"An esbuild plugin that inlines Web Worker code directly into the bundle, eliminating the need for a separate worker file. Version 0.1.1 is stable, with no recent updates. It supports importing .worker.js/.ts/.jsx/.tsx files to get a Worker constructor, bundling the worker code with a separate esbuild build. Unlike worker-loader for webpack, this plugin fully inlines the worker, making it ideal for libraries where worker file management is cumbersome. It ships TypeScript definitions and allows custom esbuild configuration for the worker build.","status":"active","version":"0.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/mitschabaude/esbuild-plugin-inline-worker","tags":["javascript","workers","esbuild","typescript"],"install":[{"cmd":"npm install esbuild-plugin-inline-worker","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-inline-worker","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-inline-worker","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency; plugin hooks into esbuild's build process","package":"esbuild","optional":false}],"imports":[{"note":"ESM-only. No default export in CommonJS; must use dynamic import or build tool that handles ESM.","wrong":"const inlineWorkerPlugin = require('esbuild-plugin-inline-worker')","symbol":"inlineWorkerPlugin","correct":"import inlineWorkerPlugin from 'esbuild-plugin-inline-worker'"},{"note":"Worker is a default export from the .worker file, treated as a class constructor.","wrong":"const { Worker } = require('./example.worker.js')","symbol":"Worker (from .worker.js import)","correct":"import Worker from './example.worker.js'"},{"note":"The argument is directly the esbuild build options object; not nested under extraConfig.","wrong":"inlineWorkerPlugin({ extraConfig: { format: 'iife' } })","symbol":"extraConfig (plugin options)","correct":"inlineWorkerPlugin({ format: 'iife' })"}],"quickstart":{"code":"import { build } from 'esbuild';\nimport inlineWorkerPlugin from 'esbuild-plugin-inline-worker';\n\nawait build({\n  entryPoints: ['src/index.ts'],\n  bundle: true,\n  outfile: 'dist/bundle.js',\n  plugins: [inlineWorkerPlugin()],\n});\n\n// src/index.ts\nimport Worker from './worker.worker.ts';\nconst worker = Worker();\nworker.onmessage = (e) => { console.log(e.data); };\nworker.postMessage('hello');","lang":"typescript","description":"Shows how to use the plugin in an esbuild build and import a .worker.ts file to create an inlined Web Worker."},"warnings":[{"fix":"Rename worker files to include '.worker' before the extension, e.g., 'myWorker.worker.js'.","message":"Worker files must use the .worker.js/.worker.ts (etc.) suffix; regular .js files will not be treated as workers.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use postMessage to pass data to the worker; avoid relying on closures.","message":"The worker code is bundled in a separate esbuild build, so global variables defined in main bundle are not available in worker unless explicitly passed.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use dynamic import() or switch to ESM for the consuming project.","message":"ESM-only: CommonJS require() will not work for this plugin. Users on older Node.js or CJS projects may encounter errors.","severity":"breaking","affected_versions":">=0.1.0"},{"fix":"Do not include these properties in the config passed to inlineWorkerPlugin().","message":"The plugin's configuration object cannot override entryPoints, outfile, or outdir; those are deleted internally.","severity":"deprecated","affected_versions":">=0.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Ensure you are importing the default export: import inlineWorkerPlugin from 'esbuild-plugin-inline-worker'","cause":"Incorrect import: the default export is a function, not an object with a setup property.","error":"Error: The plugin 'inline-worker' must have a `setup` function."},{"fix":"Add a global declaration file: declare module '*.worker.js' { const Worker: new () => Worker; export default Worker; }","cause":"TypeScript does not recognize .worker.js files without a type declaration.","error":"Cannot find module './example.worker.js' or its corresponding type declarations."},{"fix":"Run esbuild with the inlineWorkerPlugin() included in plugins array.","cause":"Attempting to import the worker file without bundling with esbuild; the plugin must be active.","error":"TypeError: Worker is not a constructor"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}