Build ZIP
After a successful vite build, @mongez/vite can package the entire output directory into a single zip file ready for shipping. The typical Mongez deploy is vite build && scp dist/build.zip server:/var/www/.
Default behaviour
mongezVite(); // compressBuild: true, compressedFileName: "build.zip"After vite build:
dist/├── assets/│ └── index-<hash>.js├── index.html└── build.zip ← contains everything else aboveThe zip contains the contents of the output directory, not the directory itself. Unzipping at the destination drops the files in directly.
Opting out
mongezVite({ compressBuild: false });The post-build zip step is skipped entirely. Everything else (.htaccess, prerender.php, env loading, etc.) still runs.
Custom filename
Static string
mongezVite({ compressedFileName: "myapp.zip" });Sync function
mongezVite({ compressedFileName: () => `myapp-${process.env.BUILD_NUMBER}.zip`,});Async function
mongezVite({ compressedFileName: async () => { const tag = await readVersionTag(); return `myapp-${tag}.zip`; },});The function is awaited inside the writeBundle handler. Use this for any filename that needs an external lookup (git tag, deploy ID, build timestamp from a service).
Output location
The zip ends up inside the build output directory:
compressBuildreadsconfig.build?.outDir || "dist".- Creates the zip at
<cwd>/<filename>. - Moves it to
<cwd>/<outDir>/<filename>.
For a custom outDir:
export default defineConfig({ build: { outDir: "build" }, plugins: [mongezVite()],});// → produces build/build.zipAwaited writeBundle
compressBuild runs inside Vite’s writeBundle hook with sequential: true and awaits the archive pipeline directly. By the time vite build exits, <outDir>/<filename> is on disk and chained scripts (vite build && upload.sh) see the finalised zip.
What’s inside the zip
Everything Vite emitted into outDir, including:
index.htmlassets/*.js,assets/*.css- Any static files Vite copied over from
public/ - The
.htaccess(ifhtaccess: trueran first) - The
prerender.php(ifpreRenderis set)
The zip itself is created at <cwd>/<filename> (outside outDir) and then moved into outDir after the archive finalises, so the zip does NOT contain itself — it captures the output-dir state from before the move.
Gotchas
- The zip moves into
outDirafter creation. If youroutDiris symlinked or behind a read-only mount, the move fails silently (the underlyingmoveFilecall from@mongez/fsswallows the error). compressBuildalways emits zip format. Other archive formats aren’t supported. Use a separate tool if you need.tar.gzor similar.- The function form runs once per build. Filenames that depend on
Date.now()produce a stable name across the build but new on each invocation.