Sharing Chunks between main and worker builds not working #16554
Replies: 3 comments
-
Start a new pull request in StackBlitz Codeflow. |
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.
-
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 build
System Info
Used Package Manager
npm
Logs
Click to expand!
Beta Was this translation helpful? Give feedback.
All reactions