All cheatsheetsFrontend Development

vite

Vite 5+

Quick reference for Vite CLI commands: dev server, build, preview, dependency pre-bundling, plugin management, environment variables, and project inspection — with common options and practical examples.

30 commands

Dev server

vite

Start the dev server using `vite.config.*` from the project root. Binds to `http://localhost:5173` by default; auto-detects framework preset.

--port <N>; --host <0.0.0.0|...> expose on network; --open open browser; --strict enforce port; --force re-prebundle deps

vite --port 4000 --host
vite --port <N>

Bind the dev server to a specific port (the next free port is used if busy unless `--strict` is also passed).

vite --port 4000 --strict
vite --host

Expose the dev server on every network interface (default is `localhost`). Combined with `--port` for a stable LAN URL.

vite --host 0.0.0.0 --port 5173
vite --open

Open the default browser to the dev server URL once it's ready.

--open /path/to/route open to a specific route

vite --open /admin
vite --force

Force re-running dependency pre-bundling (esbuild) on the next request. Use when adding a new dep or after a `.vite` cache corruption.

vite --force

Build

vite build

Produce a production bundle into `dist/` by default. Uses Rollup; supports code-splitting, tree-shaking, CSS extraction, source maps, and asset hashing.

--mode development|production; --target es2020|...; --sourcemap; --minify esbuild|terser; --outDir dist

vite build
vite build --watch

Production build that re-runs whenever a watched source file changes. Rarely needed; mainly for embedding Vite inside another build pipeline.

vite build --watch
vite build --mode <name>

Pick a mode that drives `globalThis._importMeta_.env.MODE` and `.env.<mode>` overrides (`.env.development`, `.env.staging`).

vite build --mode staging && vite build --mode production
vite build --sourcemap

Emit external `.map` files (default is hidden in production). Pair with deploy Sentry / LogRocket for stack traces.

vite build --sourcemap

Preview

vite preview

Serve the freshly-built `dist/` over a local static server so you can sanity-check the production bundle before deploying.

--port <N>; --host; --strict; --outDir dist

vite preview --port 4173 --strict

Optimize deps

vite optimizeDeps

Manual trigger of dependency pre-bundling without starting the dev server. Useful in CI to pre-populate `node_modules/.vite/deps`.

--force; --config <file>

vite optimizeDeps --force
vite optimizeDeps include <pkg>

Force pre-bundling of a CommonJS dep that's not detected automatically. Edit `optimizeDeps.include` in `vite.config.ts` instead of using CLI.

vite optimizeDeps

Diagnostics

vite --version

Print Vite's version.

vite --version
vite info

Print environment details (Node version, OS, package manager, Vite version, key plugin versions) — paste this into bug reports.

vite info
vite --debug

Enable verbose internal logging. Pipe to a file when chasing plugin / HMR issues.

vite --debug > vite-debug.log 2>&1

Configuration

vite --config <file>

Point Vite at a custom config file (CI often uses `vite.config.ci.ts` with extra plugins).

vite --config vite.config.ci.ts build
vite --configLoader <runner>

Vite 6+ — choose how to load the config (`bundle` is the default since Vite 6; `runner` / `native` / `transform` are alternates for non-Node environments).

vite --configLoader runner build

Plugin CLI

vite plugin <name>

Stub commands registered by some Vite plugins (e.g. `vite-plugin-pwa`'s `vite pwa-asset-generate`). Pass through.

vite pwa-asset-generate

Customization

vite --base <path>

Set the public path for production assets (default `/`). Use `/my-site/` when serving from a sub-path behind a reverse proxy.

vite build --base /gurutoolkit/
vite --logLevel <level>

Control how much Vite logs: `info` (default) / `warn` / `error` / `silent`.

vite build --logLevel warn
vite --clearScreen false

Don't clear the terminal between reloads — useful when piping Vite output to another tool (tmux / logs).

vite --clearScreen false | tee vite.log

Build targets

vite build --target <browserslist>

Tell Rollup the minimum browser targets. Vite handles syntax down-leveling per esbuild config; legacy targets emit larger bundles.

vite build --target es2020,edge88,firefox78,chrome87,safari14
vite build --cssCodeSplit

Emit CSS as separate chunks per route (default true since Vite 4). Pass `--cssCodeSplit=false` to inline everything into one file.

vite build --cssCodeSplit=false
vite build --minify <esbuild|terser>

Choose the minifier. esbuild is the fast default; `terser` produces slightly smaller output for legacy browsers.

vite build --minify terser

Cache

vite --force

Drop `node_modules/.vite/deps` and re-bundle — fix for stale pre-bundled deps after a major upgrade.

rm -rf node_modules/.vite && vite --force
rm -rf node_modules/.vite

Manually wipe the Vite cache. Same effect as `vite --force` on next dev start.

rm -rf node_modules/.vite && vite

Misc

vite --help

List every CLI flag with a one-line description.

vite --help
vite create <name>

Scaffold a Vite project (the old `create-vite` binary). Modern usage is `npm create vite@latest` (which routes through `npx`).

--template vue | react | svelte | lit | vanilla | etc.

npm create vite@latest my-app -- --template vue-ts
npx vite-node <script.ts>

Run a TypeScript script in the same environment Vite uses for SSR — full module resolution, aliases, and env variables.

--options.transformMode ssr | web

npx vite-node scripts/seed.ts
vite --cjs

Force Vite to load its config as a CommonJS file (legacy projects). Use only when migrating from a CJS-only stack.

vite --cjs build

Related command cheatsheets

About Vite

Vite (French for "fast") is a next-generation frontend build tool authored by Evan You (the creator of Vue.js) and maintained by the Vite team, with the 1.0 release in April 2021 and the current stable line at Vite 5 / 6. Vite serves source code over native ESM during development — esbuild pre-bundles dependencies and Rollup-based HMR handles source updates in milliseconds — then bundles for production with Rollup. Compared to webpack, Vite skips the bundling step during dev so cold-start times drop from seconds to <300 ms even on large projects. Vite is framework-agnostic: official templates exist for Vue, React, Svelte, Preact, Lit, Solid, Qwik, and vanilla TS; community plugins cover Astro, Nuxt, SvelteKit, Remix, and more. Configuration lives in `vite.config.ts` (or `.js`/`.mjs`) and uses the Rollup-compatible plugin API plus a curated set of Vite-specific hooks. Vite never uploads your code anywhere — all dev/build runs locally. Production bundles ship as static assets that you deploy anywhere (Vercel, Netlify, nginx, S3).

Cheatsheet version 1.0.0