Share chunks between multiple ESM Workers #18068
Labels
enhancement
New feature or request
feat: web workers
p2-nice-to-have
Not breaking anything but nice to have (priority)
Describe the bug
When bundling WebWorkers in the
es
format, all the modules imported by the worker are inlined inside the worker chunk and no import syntax is used.In the following reproduction, there's the following setup:
main
andseconday
validation
that is imported bymain.ts
andsecondary.ts
By analyzing the build output, 3 chunks are emitted:
validation-[hash].js
, which includes the code shared between bothmain
andsecondary
outputs.main-[hash].js
, the code for themain
output.secondary-[hash].js
, the code for thesecondary
output.For WebWorkers in ESM format, the same behaviour is expected: instead of inlining the imported modules in the worker's chunk, the worker should import from another common chunk.
Specifically, in the reproduction, I expect the shared chunk to contain the contents of
isBool
(fromvalidation.ts
) and comlink'sexpose
and that both are imported by the workers (FancyWorker1
just needs to importexpose
).To better see the problem, minification is already disabled.
Reproduction
https://stackblitz.com/edit/vue3-vite-typescript-starter-rayp8m
Steps to reproduce
npm ci && npm run build
in the StackBlitz projectdist
folder and observe the output of the main thread's chunks (remember, calledmain
andsecondary
)expose
inlined (withFancyWorker1
inliningisBool
too!)System Info
Used Package Manager
npm
Logs
No response
Validations
The text was updated successfully, but these errors were encountered: