- You are using the default build output location (
dist). This location can be changed usingbuild.outDir, and you can extrapolate instructions from these guides in that case. - You are using npm. You can use equivalent commands to run the scripts if you are using Yarn or other package managers.
- Vite is installed as a local dev dependency in your project, and you have setup the following npm scripts:
package.json
It is important to note that
vite preview is intended for previewing the build locally and not meant as a production server.Building the App
You may runnpm run build command to build the app.
dist. You may deploy this dist folder to any of your preferred platforms.
Testing the App Locally
Once you’ve built the app, you may test it locally by runningnpm run preview command.
vite preview command will boot up a local static web server that serves the files from dist at http://localhost:4173. It’s an easy way to check if the production build looks OK in your local environment.
You may configure the port of the server by passing the --port flag as an argument.
package.json
preview command will launch the server at http://localhost:8080.
GitHub Pages
Update Vite Config
Set the correct
base in vite.config.js.If you are deploying to https://<USERNAME>.github.io/, or to a custom domain through GitHub Pages (eg. www.example.com), set base to '/'. Alternatively, you can remove base from the configuration, as it defaults to '/'.If you are deploying to https://<USERNAME>.github.io/<REPO>/ (eg. your repository is at https://github.com/<USERNAME>/<REPO>), then set base to '/<REPO>/'.Enable GitHub Pages
In your repository, go to Settings → Pages. Under Build and deployment, open the Source dropdown, and select GitHub Actions.GitHub will now deploy your site using a GitHub Actions workflow, which is necessary since Vite requires a build step for deployment.
Create a Workflow
Create a new file in your repository at
.github/workflows/deploy.yml. You can also click on “create your own” from the previous step, which will generate a starter workflow file for you.Here’s a sample workflow that installs dependencies with npm, builds the site, and deploys it whenever you push changes to the main branch.GitLab Pages and GitLab CI
Set the base in vite.config.js
If you are deploying to
https://<USERNAME or GROUP>.gitlab.io/, you can omit base as it defaults to '/'.If you are deploying to https://<USERNAME or GROUP>.gitlab.io/<REPO>/, for example your repository is at https://gitlab.com/<USERNAME>/<REPO>, then set base to '/<REPO>/'.Netlify
Netlify CLI
Install Netlify CLI
Install the Netlify CLI via
npm install -g netlify-cli.Netlify with Git
Push to git repository
Push your code to a git repository (GitHub, GitLab, BitBucket, Azure DevOps).
Import to Netlify
Import the project to Netlify.
Vercel
Vercel CLI
Install Vercel CLI
Install the Vercel CLI via
npm i -g vercel and run vercel to deploy.Deploy
Vercel will detect that you are using Vite and will enable the correct settings for your deployment.Your application is deployed! (e.g. vite-vue-template.vercel.app)
Vercel with Git
Import to Vercel
Import your Vite project into Vercel.
Deploy
Vercel will detect that you are using Vite and will enable the correct settings for your deployment.Your application is deployed! (e.g. vite-vue-template.vercel.app)
Cloudflare
Cloudflare Workers
The Cloudflare Vite plugin provides integration with Cloudflare Workers and uses Vite’s Environment API to run your server-side code in the Cloudflare Workers runtime during development. To add Cloudflare Workers to an existing Vite project, install the plugin and add it to your config:vite.config.js
wrangler.jsonc
npm run build, your application can now be deployed with npx wrangler deploy.
Cloudflare Pages
Cloudflare Pages with Git
Cloudflare Pages gives you a way to deploy directly to Cloudflare without having to manage a Wrangler file.Access Cloudflare dashboard
Log in to the Cloudflare dashboard and select your account in Account Home > Workers & Pages.
Configure build settings
Select the corresponding framework preset in the build setting depending on the Vite framework you have selected. Otherwise enter your build commands for your project and your expected output directory.Then save and deploy!
Google Firebase
Install firebase-tools
Install firebase-tools via
npm i -g firebase-tools.Other Platforms
Surge
Surge
Install Surge
Install surge via
npm i -g surge.surge dist yourdomain.com.Azure Static Web Apps
Azure Static Web Apps
You can quickly deploy your Vite app with Microsoft Azure Static Web Apps service. You need:
- An Azure account and a subscription key. You can create a free Azure account here.
- Your app code pushed to GitHub.
- The SWA Extension in Visual Studio Code.
/) and built file location /dist. The wizard will run and will create a GitHub action in your repo in a .github folder.The action will work to deploy your app (watch its progress in your repo’s Actions tab) and, when successfully completed, you can view your app in the address provided in the extension’s progress window by clicking the ‘Browse Website’ button that appears when the GitHub action has run.Render
Render
You can deploy your Vite app as a Static Site on Render.By default, any new commit pushed to the specified branch will automatically trigger a new deployment. Auto-Deploy can be configured in the project settings.You can also add a custom domain to your project.
Create a Render account
Create a Render account.
Create new Static Site
In the Dashboard, click the New button and select Static Site.
Configure project
Specify a project name and branch.
- Build Command:
npm install && npm run build - Publish Directory:
dist
Flightcontrol
Flightcontrol
Deploy your static site using Flightcontrol by following these instructions.
Kinsta Static Site Hosting
Kinsta Static Site Hosting
Deploy your static site using Kinsta by following these instructions.
Zephyr Cloud
Zephyr Cloud
Zephyr Cloud is a deployment platform that integrates directly into your build process and provides global edge distribution for module federation and other kind of applications.Zephyr follows a different approach than other cloud providers. It integrates directly with Vite build process, so every time you build or run the dev server for your application, it will be automatically deployed with Zephyr Cloud.Follow the steps in the Vite deployment guide to get started.
EdgeOne Pages
EdgeOne Pages
Deploy your static site using EdgeOne Pages by following these instructions.