Web Workers
Rslib supports using Web Workers in libraries. When Rslib encounters new Worker(new URL(..., import.meta.url)), it emits the referenced module as a separate Web Worker chunk and rewrites the URL to point to the generated file.
Web Worker is supported in ESM output. CJS output does not support Web Worker.
Usage
The Web Worker request must be statically analyzable. Use a relative path string and import.meta.url directly inside new URL():
Bundle mode
In bundle mode, no additional configuration is required. The Web Worker module and its dependencies are bundled into a separate Web Worker chunk:
Bundleless mode
In bundleless mode, every source file matched by source.entry is treated as an entry. Web Worker files must be excluded from the entry glob because they are emitted separately as Web Worker chunks.
Using a .worker.ts naming convention makes it easy to exclude all Web Worker files:
With the source files from the example above, Rslib emits index.ts and helper.ts as regular bundleless outputs. The Web Worker chunk is emitted separately and imports the generated helper.js:
