vite build: Production Bundles in CI
vite build bundles your app for production using Rollup, writing hashed, minified assets to dist/.
In CI, vite build is the gate that turns source into deployable assets. It runs Rollup, applies minification, and fails fast on unresolved imports.
What it does
vite build runs a production Rollup build: it tree-shakes, minifies with esbuild by default, hashes filenames, and emits to dist/. It reads mode-specific env files (.env.production) based on --mode.
Common usage
vite build
vite build --mode staging
vite build --outDir build --base /app/
# preview the built output locally
vite preview --port 4173Options
| Flag | What it does |
|---|---|
| --mode <mode> | Set the mode (default production for build); loads .env.<mode> |
| --outDir <dir> | Output directory (default dist) |
| --base <path> | Public base path for assets |
| --sourcemap | Emit source maps |
| --minify <t> | Minifier: esbuild (default), terser, or false |
| --emptyOutDir | Force-empty outDir even when outside root |
In CI
Set the correct --mode so the right .env file loads; a missing VITE_ prefixed var silently becomes undefined. Cache node_modules and Vite's node_modules/.vite dep cache between runs to speed rebuilds.
Common errors in CI
"[vite]: Rollup failed to resolve import \"X\" from \"src/...\"" means a dependency is not installed or a path is wrong; it often passes locally because of a stale node_modules. "Could not load /... (imported by ...)" points at a missing file, usually a case-sensitivity mismatch that only fails on Linux runners. "Cannot find module" during config load means vite.config is importing something not in devDependencies.