Using Vite to create a new React app
When I need multiple different pages and create a React app that needs a backend, my go-to framework is Next.js.
It provides a lot of things built-in, it’s very popular, and its set of conventions avoids me a lot of analysis paralysis and decision making.
But sometimes I just want to create a React app, maybe for a demo or to start a project, and I don’t need all the other stuff that Next.js gives me.
I don’t want to worry, I just want to freely experiment with React.
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

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

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

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

Done!

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:

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.

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!
download all my books for free
- javascript handbook
- typescript handbook
- css handbook
- node.js handbook
- astro handbook
- html handbook
- next.js pages router handbook
- alpine.js handbook
- htmx handbook
- react handbook
- sql handbook
- git cheat sheet
- laravel handbook
- express handbook
- swift handbook
- go handbook
- php handbook
- python handbook
- cli handbook
- c handbook
subscribe to my newsletter to get them
Terms: by subscribing to the newsletter you agree the following terms and conditions and privacy policy. The aim of the newsletter is to keep you up to date about new tutorials, new book releases or courses organized by Flavio. If you wish to unsubscribe from the newsletter, you can click the unsubscribe link that's present at the bottom of each email, anytime. I will not communicate/spread/publish or otherwise give away your address. Your email address is the only personal information collected, and it's only collected for the primary purpose of keeping you informed through the newsletter. It's stored in a secure server based in the EU. You can contact Flavio by emailing [email protected]. These terms and conditions are governed by the laws in force in Italy and you unconditionally submit to the jurisdiction of the courts of Italy.