GoogleChromeLabs / worker-plugin

👩‍🏭 Adds native Web Worker bundling support to Webpack.
https://npm.im/worker-plugin
Apache License 2.0
1.91k stars 79 forks source link

Start ShareWorker from Worker #104

Open cpatti97100 opened 3 years ago

cpatti97100 commented 3 years ago

Hello all and thanks for this lib :)

I can successfully start a Worker and SharedWorker from my react app, but I would like to initiate the SharedWorker from a Worker insted, so that I do not need to pass values around too much.

worker.js

const sharedWorkerInstance = new SharedWorker(
    '../sharedWorker/webSocket-shared-worker.ts',
    { type: 'module' }
);

webpack.config.js

new WorkerPlugin({
    sharedWorker: true,
}),

but unfortunately I get ReferenceError: SharedWorker is not defined

any ideas? thanks!

Notes: latest comlink + worker-plugin