Skip to main content
Vite provides a command-line interface for development, building, and previewing your application.

Dev Server

vite

Start the Vite development server in the current directory.
Aliases: vite dev, vite serve

Parameters

string
The root directory to serve. Defaults to current directory.

Command Options

string
Specify the hostname for the server. Use 0.0.0.0 or true to listen on all addresses, including LAN and public addresses.
number
Specify the port number. Default is 5173.
boolean | string
Automatically open the app in the browser on server start. Can optionally specify a URL path.
boolean
Enable CORS for the development server.
boolean
Exit if the specified port is already in use, instead of automatically trying the next available port.
boolean
Force the optimizer to ignore the cache and re-bundle dependencies.
boolean
Enable experimental full bundle mode. This is highly experimental.

Terminal Output

When starting the dev server, you’ll see output like:

CLI Shortcuts

While the dev server is running, you can use these keyboard shortcuts:
  • r + enter - Restart the server
  • u + enter - Show server URLs
  • o + enter - Open in browser
  • c + enter - Clear console
  • q + enter - Quit the server
  • h + enter - Show help

Build

vite build

Build your application for production.

Parameters

string
The root directory to build. Defaults to current directory.

Command Options

string
default:"baseline-widely-available"
Transpile target for the build. Determines browser compatibility.
string
default:"dist"
Output directory for the production build.
string
default:"assets"
Directory under outDir to place assets in.
number
default:4096
Static asset base64 inline threshold in bytes. Assets smaller than this will be inlined as base64.
string
Build specified entry for server-side rendering.
boolean | 'inline' | 'hidden'
default:false
Output source maps for the build.
  • true - Generate separate sourcemap files
  • 'inline' - Inline sourcemaps in the output files
  • 'hidden' - Generate sourcemaps but don’t reference them in files
boolean | 'terser' | 'esbuild'
default:"esbuild"
Enable/disable minification, or specify the minifier to use.
boolean | string
Emit a manifest.json file in the output directory with a mapping of non-hashed asset filenames to their hashed versions.
boolean | string
Emit an SSR manifest file for determining style links and asset preload directives in production.
boolean
Force Vite to empty the output directory even if it’s outside of the project root. By default, Vite will warn and not empty it.
boolean
Enable watch mode. Rebuilds when modules have changed on disk.
boolean
Build all environments. Same as setting builder: {} in config. This is experimental.

Terminal Output

When building for production, you’ll see output like:

Preview

vite preview

Locally preview the production build. This command starts a static web server that serves the files from outDir (default: dist).
vite preview is intended for previewing the build locally and is not meant to be used as a production server.

Parameters

string
The root directory containing the build. Defaults to current directory.

Command Options

string
Specify the hostname for the preview server.
number
Specify the port number. Default is 4173.
boolean
Exit if the specified port is already in use.
boolean | string
Automatically open the app in the browser on server start.
string
default:"dist"
Output directory to serve.

Terminal Output

When starting the preview server, you’ll see output like:

Optimize

vite optimize

Deprecated: The pre-bundle process runs automatically during development and does not need to be called manually.
Pre-bundle dependencies. This command was used to manually trigger dependency optimization, but it’s now done automatically when starting the dev server.

Parameters

string
The root directory. Defaults to current directory.

Command Options

boolean
Force the optimizer to ignore the cache and re-bundle dependencies.

NPM Scripts

Typical usage in package.json:
package.json
You can specify additional CLI options using flags:
package.json
Then run: