Using Vite Create a New React App

0 0
Read Time:1 Minute, 31 Second

I used to use create-react-app but these days I use Vite.

It’s a modern tool that provides a development server, is very fast, and many people in the JS community consider it optimal.

Also, it’s not a React-specific tool, so anything you learn about it can be ported to other frameworks supported like Svelte Vue and more.

To create a project using Vite you first go into the folder where you host all your projects, in my case it’s a dev folder in my user’s home folder.

Then run npm create vite@latest

Untitled

Choose a name for the project. That will also be the project’s folder name. In this case “test”:

Untitled

Now you can choose a framework. Pick “React”.

Untitled

Pick JavaScript or TypeScript, whatever you prefer. You can optionally use SWC.

Untitled

Done!

Untitled

Now go in the newly created project folder:cd test and run

npm install

to install the dependencies, followed by

npm run dev

to start the application:

Untitled

The application should be running at http://localhost:5173 (the port might be different if it’s already used)

Now you’re ready to work on this application!

Here’s the application folder opened in VS Code.

As you can see, Vite created a basic application and you can now open src/App.jsx to start working on it.

Untitled

The beauty of a tool like this is that now you can add files and Vite will automatically recognize them, without the need of restarting npm run dev like we had to do with our Node.js projects.

And when you save a component, it’s automatically updated in your browser.

It makes development very fast and fun!

Happy
Happy
100 %
Sad
Sad
0 %
Excited
Excited
0 %
Sleepy
Sleepy
0 %
Angry
Angry
0 %
Surprise
Surprise
0 %