worker-plugin icon indicating copy to clipboard operation
worker-plugin copied to clipboard

Support for SplitChunksPlugin

Open samdenty opened this issue 4 years ago • 3 comments

Searched around and came across https://github.com/webpack/webpack/issues/6472, worker-injector-generator-plugin and a stackoverflow answer

This adds support for sharing chunks between workers / main entry points.

To use it, you can put your rules under webpackConfig.splitChunks. Make sure to define webpackConfig.splitChunks.cacheGroups And make sure globalObject is set to self

samdenty avatar Mar 18 '20 22:03 samdenty

But https://github.com/webpack/webpack/issues/7879#issuecomment-412414526 said webpack did not support

wood1986 avatar Mar 29 '20 19:03 wood1986

But webpack/webpack#7879 (comment) said webpack did not support

It can be done, but I wish it was handled internally by webpack.

By the way it can also be done asynchronously (even when it's bad for debugging), by using fetch rather than importScripts, then executing as function, in that sense, all fetching will be done at once, rather than importScripts which is sync, however, fetch is terrible for debugging purposes.

onzag avatar Apr 03 '20 06:04 onzag

Shouldn't this already work just by adding SplitChunksPlugin? We're adding WebWorkerTemplate, which generates chunks and a runtime that use importScripts or XHR+eval for code loading.

Update: I can confirm that chunk loading was already working, shown in this test that does code splitting via dynamic import (fixture).

developit avatar Jun 23 '20 17:06 developit