When I need to create a React app without the need for a backend or multiple pages, my preferred tool is Next.js. However, for smaller projects or experiments, I find Vite to be a great alternative. Vite is a modern tool that provides a fast development server and is not limited to just React. It can be used with other frameworks like Svelte and Vue as well.
To create a project using Vite, follow these steps:
- Navigate to the folder where you store your projects (e.g., a ‘dev’ folder in your user’s home directory).
- Run
npm create @vitejs/app
command.
- Choose a name for your project. This will also be the name of the project’s folder.
- Select the framework you want to use. In this case, choose “React”.
- Select whether you want to use JavaScript or TypeScript for your project. You can also optionally use SWC.
- The project is now created.
- Navigate into the newly created project folder by running
cd your-project-name
. - Install the project dependencies by running
npm install
. - Start the application with
npm run dev
.
- The application should now be running at http://localhost:5173 (the port may vary if it’s already in use).
You are now ready to start working on your Vite-powered React application! You can open the project folder in your preferred code editor, like VS Code, and start editing the src/App.jsx
file to make changes to your application.
One of the advantages of using Vite is that it automatically recognizes and updates the files you add or modify. You don’t need to restart the development server, making the development process fast and enjoyable.
Tags: Vite, React, JavaScript, TypeScript, SWC