Sharing Chunks between main and worker builds not working #16554
Replies: 3 comments
-
|
|
Beta Was this translation helpful? Give feedback.
-
|
Side info: I also tried to disable tree-shaking (setting treeshake: false in all rollupOptions) but the export list at the bottom is still changing resulting in separate chunk hashes. This seem to be a Rollup problem. |
Beta Was this translation helpful? Give feedback.
-
|
I moved this as a discussion as I don't think this is a bug in Vite, but probably a configuration issue. Currently with two Rollup builds, there's no way to ensure to two chunks will contain the same contain to be able to share them. The reason we have two Rollup builds is to also ensure to not share the chunks, because worker builds have different resolving and runtime behaviour than normal browser builds, e.g. access to ESM, worker-specific globals etc. If you do want to make this work and understand the risks of the above, you could write a Rollup plugin using https://rollupjs.org/plugin-development/#this-emitfile and |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
I am trying to put a special dependency into a dedicated chunk which should be shared between the "main" build and the "worker" builds.
Vite creates two separate chunks with different content according to whats used in either the worker or main build.
I want one chunk for the dependency exposing everything needed by main and worker files.
I think the problem might be somewhere in the area of building the worker entry point here:
vite/packages/vite/src/node/plugins/worker.ts
Lines 71 to 120 in b7ddfae
I guess the fact that we run multiple individual compilation cause separate chunks due to different tree-shaking.
Reproduction
https://stackblitz.com/edit/vitejs-vite-cuquez?view=editor
Steps to reproduce
npm install && npm run buildSystem Info
System: OS: Windows 11 10.0.22631 CPU: (16) x64 Intel(R) Core(TM) i7-10700K CPU @ 3.80GHz Memory: 31.19 GB / 63.92 GB Binaries: Node: 20.9.0 - C:\Program Files\nodejs\node.EXE npm: 10.2.3 - C:\Program Files\nodejs\npm.CMD pnpm: 8.15.6 - ~\AppData\Local\pnpm\pnpm.EXE Browsers: Chrome: 124.0.6367.60 Edge: Chromium (123.0.2420.97) Internet Explorer: 11.0.22621.1 npmPackages: vite: ^5.1.4 => 5.2.1 ----------- 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.18.0 - /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: vite: ^5.1.4 => 5.2.10Used Package Manager
npm
Logs
Click to expand!
Beta Was this translation helpful? Give feedback.
All reactions