Webpack 5 supports building a separate entrypoint for Workers or SharedWorkers just by adding the following code to a file:
new SharedWorker(new URL('./worker.js', import.meta.url));
Webpack generates a separate chunk for this worker: 123.s0m3ha2h.esm.js
I believe its name contains its content's hash.
When a SharedWorker is instantiated, the browser checks if there is one already with same URL, and if not, starts a new ShraredWorker.
I would like to avoid having 2 versions of my SharedWorker running at the same time after code update. How can one achieve this when using SharedWorkers with webpack?