Skip to main content

Command Palette

Search for a command to run...

How to install React JS using Vite: A Fast and Efficient Guide.

Updated
3 min read
How to install React JS using Vite: A Fast and Efficient Guide.
E

Top-secret cleared technical writer. Driven by ethics and quality contents to provide high-grade results, I feel the ability to listen is foremost in the ability to write as the details (or lack of), make the document.

Streamlined, easy-to-follow guides are a specialty that I have enhanced to a variety of audiences in my career. I'm comfortable collaborating with multiple teams or working alone on tight deadlines. Adding to the skill set is personal enjoyment, as writing is something I hold a passion for. I have always enjoyed knowing I can help people with my work.

Introduction:

Vite is a modern development server that provides a fast and efficient way to build and deploy web applications. In this article, I will take you through a step-by-step guide to installing React JS using Vite, allowing you to take advantage of its speedy development capabilities.

Step 1: Install Node.js

Before installing React with Vite, ensure you have Node.js installed on your computer. Download (https://nodejs.org/) and install Node.js from the official website if you haven’t already.

Step 2: Creating a New React.js Project

To create a new React.js project with Vite, open your terminal and run the following command:

npm create vite@latest my-react-app

(Replace my-react-app with your preferred project name.)

This command will generate a new project. Vite will provide you with a list of frameworks you can use, and since we are only interested in React.js, you can simply select React from the list and press enter on your keyboard. Vite will then provide you with a list of variants you can work with, from which you can select JavaScript or any other variant you want.

Step 3: Navigating to Your Project Directory

Once the project has been created, navigate to the directory using the following command:

cd my-react-app

(You can also replace my-react-app with the name you choose when creating you project.)

Step 4: Installing Dependencies

You can install the project dependencies by running the following command:

npm install or npm i

This command will install all the necessary dependencies specified in the package.json file, including React.js and Vite.

Step 5: Starting the Development Server

After the dependencies have been installed, you can start the development server by running the following command:

npm run dev

This command will start the Vite development server, which will serve your React.js application. You can access your application by navigating to link provided in your web browser.

Step 6: Exploring Your Project

The my-react-app directory will have the following structure:

my-react-app/

├── index.html # The main HTML file

├── main.jsx # The entry point for your React app

├── package.json # Project dependencies and scripts

└── public/# Static assets (images, fonts, etc.)

Step 7: Making Changes and Seeing Results Instantly

Vite excels at hot module replacement (HMR). As you modify your code (.jsx,.css, etc.), Vite automatically updates the browser without a full refresh, significantly enhancing your development workflow.

Step 8: Building for Production

Once you’re satisfied with your React.js application and ready to deploy it to production, you can build the project by running the following command:

npm run build

This command will generate a production-ready build of your application in the dist directory.

Conclusion

Vite offers a refreshingly fast and efficient way to develop React.js applications. With its lightning-fast development server and HMR, you can focus on creating exceptional user experiences without getting bogged down by lengthy build times. Dive into the world of React development with Vite and experience the difference!

More from this blog

Emmanuel A.O

12 posts

A front-end developer that is interested about immersive and interactive user experiences, as well as a technical writer who enjoys distilling down complicated concepts into easily digestible chunks.