Open samdenty opened 4 years ago
But https://github.com/webpack/webpack/issues/7879#issuecomment-412414526 said webpack did not support
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.
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).
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 definewebpackConfig.splitChunks.cacheGroups
And make sure globalObject is set to self