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

Support for SplitChunksPlugin #63

Open samdenty opened 4 years ago

samdenty commented 4 years ago

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

wood1986 commented 4 years ago

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

onzag commented 4 years ago

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 commented 4 years ago

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