Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share chunks between multiple ESM Workers #18068

Open
7 tasks done
ferferga opened this issue Sep 10, 2024 · 1 comment
Open
7 tasks done

Share chunks between multiple ESM Workers #18068

ferferga opened this issue Sep 10, 2024 · 1 comment
Labels
enhancement New feature or request feat: web workers p2-nice-to-have Not breaking anything but nice to have (priority)

Comments

@ferferga
Copy link

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:

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

Reproduction

https://stackblitz.com/edit/vue3-vite-typescript-starter-rayp8m

Steps to reproduce

  1. Run npm ci && npm run build in the StackBlitz project
  2. Go to the dist folder and observe the output of the main thread's chunks (remember, called main and secondary)
    image
  3. Observe the emitted chunks for the worker and how both have Comlink's expose inlined (with FancyWorker1 inlining isBool too!)
    image

System Info

System:
    OS: Linux 5.0 undefined
    CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
    Memory: 0 Bytes / 0 Bytes
    Shell: 1.0 - /bin/jsh
  Binaries:
    Node: 18.20.3 - /usr/local/bin/node
    Yarn: 1.22.19 - /usr/local/bin/yarn
    npm: 10.2.3 - /usr/local/bin/npm
    pnpm: 8.15.6 - /usr/local/bin/pnpm
  npmPackages:
    @vitejs/plugin-vue: 5.1.3 => 5.1.3 
    vite: 5.4.3 => 5.4.3

Used Package Manager

npm

Logs

No response

Validations

Copy link

stackblitz bot commented Sep 10, 2024

@sapphi-red sapphi-red changed the title ESM WebWorkers inlines imported modules instead Share chunks between multiple ESM Workers Sep 10, 2024
@sapphi-red sapphi-red added enhancement New feature or request feat: web workers p2-nice-to-have Not breaking anything but nice to have (priority) labels Sep 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request feat: web workers p2-nice-to-have Not breaking anything but nice to have (priority)
Projects
None yet
Development

No branches or pull requests

2 participants