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.
npm install esbuild-plugin-inline-workerVerified import paths — ran on the pinned version, not inferred.
Shows how to use the plugin in an esbuild build and import a .worker.ts file to create an inlined Web Worker.
Rename worker files to include '.worker' before the extension, e.g., 'myWorker.worker.js'.
Use postMessage to pass data to the worker; avoid relying on closures.
Use dynamic import() or switch to ESM for the consuming project.
Do not include these properties in the config passed to inlineWorkerPlugin().
Ensure you are importing the default export: import inlineWorkerPlugin from 'esbuild-plugin-inline-worker'
Add a global declaration file: declare module '*.worker.js' { const Worker: new () => Worker; export default Worker; }Run esbuild with the inlineWorkerPlugin() included in plugins array.