How to build with Vite in Docker using yarn workspaces focus --production? #488
-
Hi Vite team, We're using Vite in a monorepo with yarn workspaces and building our frontend in Docker. The goal is to avoid installing devDependencies in the build step (due to license compliance issues — e.g., glob@10.4.5 pulled via Vite), so we use:
However, Vite is a devDependency — and the build fails because vite.config.ts can’t resolve the Vite module. We tried a few approaches:
This still failed with module resolution errors, likely because the local vite.config.ts expects Vite to be installed in node_modules. -Run full yarn install We'd prefer a cleaner way where Vite is only present during the build step, but not in the production image or lockfile (for license scanning). Ideally, something like this: Dev dependencies like vite, @vitejs/plugin-react, etc., are isolated from runtime References:
Can you recommend a best practice for this? Thanks a lot! |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
What I use and I think should fit your need is the docker builder pattern, where I first install all deps in one layer, run |
Beta Was this translation helpful? Give feedback.
What I use and I think should fit your need is the docker builder pattern, where I first install all deps in one layer, run
vite build
and import only the dist folder in the second layer where only "runtime deps" are installed