Netlify
Netlify offers hosting and serverless backend services for web applications and static websites. Any Vite site can be hosted on Netlify!
This guide includes instructions for deploying to Netlify through the website UI or Netlify’s CLI.
Project configuration
Section titled “Project configuration”Follow the Netlify adapter guide.
How to deploy
Section titled “How to deploy”You can deploy to Netlify through the website UI or using Netlify’s CLI (command line interface). The process is the same for both static and on-demand rendered Vite sites.
Website UI deployment
Section titled “Website UI deployment”If your project is stored in GitHub, GitLab, BitBucket, or Azure DevOps, you can use the Netlify website UI to deploy your Vite site.
-
Click Add a new site in your Netlify dashboard
-
Choose Import an existing project
When you import your Vite repository from your Git provider, Netlify should automatically detect and pre-fill the correct configuration settings for you.
-
Make sure that the following settings are entered, then press the Deploy button:
- Build Command:
vite buildornpm run build - Publish directory:
dist
After deploying, you will be redirected to the site overview page. There, you can edit the details of your site.
- Build Command:
Any future changes to your source repository will trigger preview and production deploys based on your deployment configuration.
netlify.toml file
Section titled “netlify.toml file”You can optionally create a new netlify.toml file at the top level of your project repository to configure your build command and publish directory, as well as other project settings including environment variables and redirects. Netlify will read this file and automatically configure your deployment.
To configure the default settings, create a netlify.toml file with the following contents:
[build] command = "npm run build" publish = "dist"CLI deployment
Section titled “CLI deployment”You can also create a new site on Netlify and link up your Git repository by installing and using the Netlify CLI.
-
Install Netlify’s CLI globally
Terminal window npm install --global netlify-cli -
Run
netlify loginand follow the instructions to log in and authorize Netlify -
Run
netlify initand follow the instructions -
Confirm your build command (
vite build)The CLI will automatically detect the build settings (
vite build) and deploy directory (dist), and will offer to automatically generate anetlify.tomlfile with those settings. -
Build and deploy by pushing to Git
The CLI will add a deploy key to the repository, which means your site will be automatically rebuilt on Netlify every time you
git push.
Set a Node.js version
Section titled “Set a Node.js version”If you are using a legacy build image (Xenial) on Netlify, make sure that your Node.js version is set. Vite requires v22.12.0 or higher.
You can specify your Node.js version in Netlify using:
- a
.nvmrcfile in your base directory. - a
NODE_VERSIONenvironment variable in your site’s settings using the Netlify project dashboard.
Using Netlify Functions
Section titled “Using Netlify Functions”No special configuration is required to use Netlify Functions with Vite. Add a netlify/functions directory to your project root and follow the Netlify Functions documentation to get started!