How to build with Vite in Docker using yarn workspaces focus --production? #20142
calinLazuran
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
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., [email protected] pulled via Vite), so we use:
RUN yarn workspaces focus --production
However, Vite is a devDependency — and the build fails because vite.config.ts can’t resolve the Vite module.
We tried a few approaches:
Installing Vite globally (did not work)
This still failed with module resolution errors, likely because the local vite.config.ts expects Vite to be installed in node_modules.
Fallback solution that works (but not ideal)
-Run full yarn install
-Build the frontend
-Delete node_modules afterward
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
We can build using yarn workspaces focus --production or similar.
References:
https://vite.dev/guide/dep-pre-bundling#automatic-dependency-discovery
https://stackoverflow.com/a/76142476
#1803
Can you recommend a best practice for this?
Maybe a pattern that works well in workspaces + Docker setups for CI/CD pipelines?
Thanks a lot!
Beta Was this translation helpful? Give feedback.
All reactions