Skip to content
Latchkey

vite build Command: Build Frontends in CI

vite build creates an optimized production bundle using Rollup under the hood.

vite is a modern frontend build tool: a fast dev server plus a Rollup-based production build. In CI you almost always run vite build, which type-agnostically bundles, minifies, and hashes assets into a dist directory.

Common flags

  • vite build - produce a production build into dist/
  • --mode production|staging - select the .env mode and define vars
  • -c / --config FILE - use a specific vite config
  • --outDir DIR - output directory (default dist)
  • --base /path/ - public base path for deployed assets
  • --sourcemap - emit source maps for the build
  • --emptyOutDir - clear the out dir before building

Example in CI

Run a production build with a staging mode and source maps in CI:

shell
vite build --mode staging --sourcemap --outDir dist

Common errors in CI

  • [vite]: Rollup failed to resolve import "X" - missing dep or wrong path/alias
  • Could not load /path (imported by Y) - file missing or case-sensitive path mismatch
  • Build failed: Transform failed - a syntax error in source
  • JavaScript heap out of memory - large build; raise Node memory limit

Key takeaways

  • vite build is the CI command; the dev server is for local use only.
  • --mode picks the env file and import.meta.env define values.
  • "Rollup failed to resolve import" is the most common CI build failure.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →