DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Last call! Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • CRUD Operations Using ReactJS Hooks and Web API
  • The Cypress Edge: Next-Level Testing Strategies for React Developers
  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide
  • Mastering React App Configuration With Webpack

Trending

  • Understanding and Mitigating IP Spoofing Attacks
  • MySQL to PostgreSQL Database Migration: A Practical Case Study
  • How to Build Local LLM RAG Apps With Ollama, DeepSeek-R1, and SingleStore
  • Build Your First AI Model in Python: A Beginner's Guide (1 of 3)
  1. DZone
  2. Coding
  3. JavaScript
  4. How Use and Deploy Vite With React

How Use and Deploy Vite With React

Simple Tutorial about project with Vite with React and deploy this project

By 
Evgenii Kravtsov user avatar
Evgenii Kravtsov
·
Dec. 25, 22 · Tutorial
Likes (2)
Comment
Save
Tweet
Share
5.8K Views

Join the DZone community and get the full member experience.

Join For Free

In this article, we will look at how to make a simple project using Vite and React. As a bonus, I will show you how to deploy our project.

First, let's create a folder for our project and start creating a project using Vite and its templates.

Shell
 
mkdir ViteProject

cd ViteProject

npm create vite@latest


Vite will prompt us to choose the name of our project, the template under which it will make it, and the compiler with which it will work. For our example, I chose the following options:

shell


That's all, our project is created! 

Let's study the structure of the created project:


vite react


  • node_modules - respectively modules used in our project 
  • public - directory with media files we use 
  • src - directory with the project code, where we will add our code and components 
  • .gitignore - file to describe ignored files for git
  • index.html - HTML file where our React application is mounted 
  • package-lock.json - a file for describing installed dependencies 
  • package.json - a file for describing the project and dependencies, script commands and other things vite.config.json - default vite config file

Let's run our project and see what we have now. 

Run the command in the terminal

npm run dev

In the terminal, we will see

terminal


In this image, we are told how much Vite has collected for our project and at what address we can open it.

 After opening the address http://localhost:5173/ we will see the standard Vite template for React, namely:

Vite + React


Yeah! our project is created and launched and we can further develop it!

Let's take a look at the Vite configuration and see how it's done.

JavaScript
 
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [react()],
})


We see that it is quite simple, and does not look like a similar webpack configuration. In this case, the Vite plugin for React is used, which uses esbuild and babel. You can read more detailed information about this plugin on the page of this plugin.

Support for Sass and Tailwind

With Vite, we can easily use Sass and Tailwind as they are supported out of the box!

I renamed the App.css file to App.scss and added an inline style for the h1.


App.css

But so far, after rebooting, we get this error

terminal


This is because we didn't install sass in our dependencies. 

We need to execute this command

npm install sass --save-dev

And after that, we see that the style has been applied to our h1 tag!


Vite + React


As for Tailwind, we also need to go through only the installation of Tailwind itself, namely:

  • instal tailwind css - npm install -D tailwindcss postcss autoprefixernpxtailwindcss init -p
  •  Configure your template paths - in file tailwind.config.cjs
JavaScript
 
/** @type {import('tailwindcss').Config} */
module.exports = {
  content: [
    "./index.html",
    "./src/**/*.{js,ts,jsx,tsx}",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}


  • Add in index.css tailwind directives tailwind directives


That's all you need to use Tailwind!

Deploy

In order to deploy our site, you first need to build it. 

This is done with the command

npm run build

The result of the Vite build is added to the dist directory

terminal


For subsequent testing of the built site, we can use the command

npm run preview

For deployment, we need to install Vercel CLI

npm i -g vercel

and run command

vercel

You will be asked to log in and asked a series of questions about your project and that's it!

terminal


Our project - Vite React Vercel App

Conclusion

In conclusion, I would like to say that in this article we have analyzed a simple way to create a project, its configuration and deployment. This is just an overview article on the topic. Hope it helps you and teaches you something!

JavaScript React (JavaScript library) Visual Studio Code

Opinions expressed by DZone contributors are their own.

Related

  • CRUD Operations Using ReactJS Hooks and Web API
  • The Cypress Edge: Next-Level Testing Strategies for React Developers
  • How to Build Scalable Mobile Apps With React Native: A Step-by-Step Guide
  • Mastering React App Configuration With Webpack

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!