Bun's Web Worker constructor supports some extra options on top of the API browsers have.
interface
WorkerOptions
interface WorkerOptions
- argv?: any[]
List of arguments which would be stringified and appended to
Bun.argv/process.argvin the worker. This is mostly similar to thedatabut the values will be available on the globalBun.argvas if they were passed as CLI options to the script. - env?: Record<string, string> | typeof SHARE_ENV
If set, specifies the initial value of process.env inside the Worker thread. As a special value, worker.SHARE_ENV may be used to specify that the parent thread and the child thread should share their environment variables; in that case, changes to one thread's process.env object affect the other thread as well. Default: process.env.
- name?: string
A string specifying an identifying name for the DedicatedWorkerGlobalScope representing the scope of the worker, which is mainly useful for debugging purposes.
- preload?: string | string[]
An array of module specifiers to preload in the worker.
These modules load before the worker's entry point is executed.
Equivalent to passing the
--preloadCLI argument, but only for this Worker. - ref?: boolean
When
true, the worker will keep the parent thread alive until the worker is terminated orunref'd. Whenfalse, the worker will not keep the parent thread alive.By default, this is
false. - smol?: boolean
Use less memory, but make the worker slower.
Internally, this sets the heap size configuration in JavaScriptCore to be the small heap instead of the large heap.