Skip to content

Conversation

@samdenty
Copy link

@samdenty samdenty commented Mar 18, 2020

Searched around and came across webpack/webpack#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

@wood1986
Copy link

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

@onzag
Copy link

onzag commented Apr 3, 2020

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.

@developit
Copy link
Collaborator

developit commented Jun 23, 2020

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants