In this tutorial, we will be focusing on how to deploy a Vite application that utilizes CSS. We will walk through the process of building your Vite application into static files, which can then be hosted on any static hosting provider.
By the end of this tutorial, you will learn:
Before deploying, you should build your Vite application into static files. It's as simple as running this command in your project directory:
npm run build
This command will create a dist
directory with your built project.
There are numerous hosting providers available. For this tutorial, we will use Vercel, but you can choose any provider that supports static sites (like Netlify or GitHub Pages).
First, install Vercel CLI by running:
npm i -g vercel
Then, in your project directory, simply run:
vercel
Follow the prompts and your application will be deployed!
Here's what happens when you run npm run build
:
$ npm run build
> vite build
vite v2.6.4 building for production...
✓ 10 modules transformed.
dist/assets/favicon.17e50649.svg 1.49kb
dist/assets/index.3e41ec8e.css 0.78kb / brotli: 0.43kb
dist/index.html 0.52kb
dist/assets/index.b311b06b.js 0.49kb / brotli: 0.29kb
The dist
directory now contains your built project, ready to be deployed.
When you run vercel
, you might see something like this:
$ vercel
Vercel CLI 23.1.2
? Set up and deploy “~/my-vite-app”? [Y/n] y
? Which scope do you want to deploy to? My User
? Link to existing project? [y/N] n
? What’s your project’s name? my-vite-app
? In which directory is your code located? ./
Auto-detected project settings (Vite.js):
- Build Command: `npm run build` or `yarn build`
- Output Directory: `dist`
- Development Command: vite dev --port $PORT
? Want to override the settings? [y/N] n
🔗 Linked to username/my-vite-app (created .vercel)
🔍 Inspect: https://vercel.com/username/my-vite-app/settings
✅ Production: https://my-vite-app.vercel.app [copied to clipboard]
Your application is now live at the provided URL!
In this tutorial, you learned how to build your Vite application into static files and deploy those files to a static hosting provider. The next step could be learning how to add dynamic features to your application, or how to use a CSS preprocessor like Sass with Vite.
For more about Vite, check out the official Vite documentation.
For each exercise, be sure to test your live application to ensure everything works as expected. Happy coding!