Vite is a popular build tool among developers which offers fast development and reduced build times.
It is packed with features like instant server start, hot module reload (HMR) and pre-bundling.
If you have ever used the normal create react app offered by the developers of React, you will see that it takes time to create a React app even though you just want to use it for a simple project.
Another thing is that its folders are kind of bloated with files, which for a starter project might not be useful.
But with Vite, you can create a React app with less build time and the files in the folder are minimal with optimal output.
Here are the steps to follow to create a React app with Vite from scratch -
Pre-requisite:
Make sure to have node installed on your machine.
To see if you have node install, use the command
node -v
in your terminal to know the version of node that you have.If you dont have node install, you can go to their website and install it on your machine - it is that straight forward.
npm create vite@latest
and press enter.npm create vite@latest
, you will be asked to put a project name, so you can name it whatever you like and in this example, the project name where our React app will live is "start-react-project"
. Then click enter.To select React from the lists, you the up and down arrow key on your keyboard.
Note:
From the list you can see that Vite is not used only for React projects but for others as well.
It will also ask to choose a variant. The variant indicates if you would like to use Vanilla JavaScript or Typescript. So select your choice, but I will select JavaScript.
Then click enter.
cd start-react-project
npm install
to install all the dependencies React needs.npm run dev
and go to the provided URL.Good luck to using React + Vite 🎉