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:
2 script outputs: main and seconday
One module validation that is imported by main.ts and secondary.ts
By analyzing the build output, 3 chunks are emitted:
validation-[hash].js, which includes the code shared between both main and secondary outputs.
main-[hash].js, the code for the main output.
secondary-[hash].js, the code for the secondary 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 (from validation.ts) and comlink's expose and that both are imported by the workers (FancyWorker1 just needs to import expose).
To better see the problem, minification is already disabled.
[X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
[X] Make sure this is a Vite issue and not a framework-specific issue. For example, if it's a Vue SFC related bug, it should likely be reported to vuejs/core instead.
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