Dev Server
vite
Start the Vite development server in the current directory.vite dev, vite serve
Parameters
The root directory to serve. Defaults to current directory.
Command Options
Specify the hostname for the server. Use
0.0.0.0 or true to listen on all addresses, including LAN and public addresses.Specify the port number. Default is
5173.Automatically open the app in the browser on server start. Can optionally specify a URL path.
Enable CORS for the development server.
Exit if the specified port is already in use, instead of automatically trying the next available port.
Force the optimizer to ignore the cache and re-bundle dependencies.
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
The root directory to build. Defaults to current directory.
Command Options
Transpile target for the build. Determines browser compatibility.
Output directory for the production build.
Directory under
outDir to place assets in.Static asset base64 inline threshold in bytes. Assets smaller than this will be inlined as base64.
Build specified entry for server-side rendering.
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
Enable/disable minification, or specify the minifier to use.
Emit a
manifest.json file in the output directory with a mapping of non-hashed asset filenames to their hashed versions.Emit an SSR manifest file for determining style links and asset preload directives in production.
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.
Enable watch mode. Rebuilds when modules have changed on disk.
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 fromoutDir (default: dist).
Parameters
The root directory containing the build. Defaults to current directory.
Command Options
Specify the hostname for the preview server.
Specify the port number. Default is
4173.Exit if the specified port is already in use.
Automatically open the app in the browser on server start.
Output directory to serve.
Terminal Output
When starting the preview server, you’ll see output like:Optimize
vite optimize
Pre-bundle dependencies. This command was used to manually trigger dependency optimization, but it’s now done automatically when starting the dev server.Parameters
The root directory. Defaults to current directory.
Command Options
Force the optimizer to ignore the cache and re-bundle dependencies.
NPM Scripts
Typical usage inpackage.json:
package.json
package.json